1
1
export default class Data {
2
2
constructor ( editor ) {
3
3
this . editor = editor ;
4
+ window . editor = editor ;
4
5
this . element = editor . dom . getParent ( editor . selection . getStart ( ) , 'a[href]' ) ;
5
-
6
6
const textarea = document . createElement ( 'textarea' ) ;
7
- textarea . innerHTML = editor . selection . getContent ( ) ;
7
+ textarea . innerHTML = this . editor . selection . getContent ( ) ;
8
8
9
9
this . initialData = {
10
- link_text : textarea . value ,
10
+ link_text : this . editor . selection . getContent ( ) ,
11
11
link_title : '' ,
12
12
classes : '' ,
13
13
new_window : false ,
14
- page : {
15
- page : '' ,
16
- url : '' ,
17
- anchor : '' ,
18
- parameters : ''
19
- } ,
20
- url : {
21
- url : ''
22
- } ,
23
- email : {
24
- to : '' ,
25
- subject : '' ,
26
- body : ''
27
- } ,
28
- phone : {
29
- phone : ''
30
- } ,
31
- file : {
32
- file : ''
33
- }
14
+ 'page_page' : '' ,
15
+ 'page_url' : '' ,
16
+ 'page_anchor' : '' ,
17
+ 'page_parameters' : '' ,
18
+ 'url_url' : '' ,
19
+ 'email_to' : '' ,
20
+ 'email_subject' : '' ,
21
+ 'email_body' : '' ,
22
+ 'phone_phone' : '' ,
23
+ 'file_file' : { value : '' , metadata : undefined }
34
24
} ;
35
25
36
- this . activeTab = 'page ' ;
26
+ this . activeTab = 'url ' ;
37
27
this . data = this . parseData ( ) ;
38
28
}
39
29
@@ -61,54 +51,34 @@ export default class Data {
61
51
this . editor . selection . select ( this . element ) ;
62
52
63
53
const data = {
64
- global : {
65
- link_text : '' ,
66
- link_title : '' ,
67
- classes : '' ,
68
- new_window : false
69
- } ,
70
- page : {
71
- ...( this . initialData . page || { } )
72
- } ,
73
- url : {
74
- ...( this . initialData . url || { } )
75
- } ,
76
- email : {
77
- ...( this . initialData . email || { } )
78
- } ,
79
- phone : {
80
- ...( this . initialData . phone || { } )
81
- } ,
82
- file : {
83
- ...( this . initialData . file || { } )
84
- }
54
+ link_text : this . editor . selection . getContent ( ) ,
55
+ link_title : '' ,
56
+ classes : '' ,
57
+ new_window : false ,
58
+ ...( this . initialData || { } )
59
+
85
60
} ;
86
61
87
- data . global . link_title = this . element . getAttribute ( 'title' ) ;
88
- data . global . classes = this . element . getAttribute ( 'class' ) ;
89
- data . global . new_window = ( this . element . getAttribute ( 'target' ) === '_blank' ) ;
90
- data . global . link_text = this . element . innerHTML ;
62
+ data . link_title = this . element . getAttribute ( 'title' ) ?? '' ;
63
+ data . classes = this . element . getAttribute ( 'class' ) ?? '' ;
64
+ data . new_window = ( this . element . getAttribute ( 'target' ) === '_blank' ) ;
65
+ data . link_text = this . element . innerHTML ;
91
66
92
67
const linkType = this . element . dataset . fredLinkType ;
93
- let url = this . element . getAttribute ( 'href' ) || '' ;
68
+ let url = this . element . getAttribute ( 'href' ) ?? '' ;
94
69
95
70
if ( linkType === 'page' ) {
96
- data . page . page = this . element . getAttribute ( 'data-fred-link-page' ) ;
97
- data . page . anchor = this . element . getAttribute ( 'data-fred-link-anchor' ) ;
98
- data . page . parameters = this . element . getAttribute ( 'data-fred-link-parameters' ) ;
71
+ data . page_page = this . element . getAttribute ( 'data-fred-link-page' ) ?? '' ;
72
+ data . page_anchor = this . element . getAttribute ( 'data-fred-link-anchor' ) ?? '' ;
73
+ data . page_parameters = this . element . getAttribute ( 'data-fred-link-parameters' ) ?? '' ;
99
74
100
- if ( data . page . page || data . page . anchor || data . page . parameters ) {
101
- data . page . url = url . replace ( ( '#' + data . page . anchor ) , '' ) ;
102
- data . page . url = data . page . url . replace ( ( '?' + data . page . parameters ) , '' ) ;
75
+ if ( data . page_page || data . page_anchor || data . page_parameters ) {
76
+ data . page_url = url . replace ( ( '#' + data . page_anchor ) , '' ) ;
77
+ data . page_url = data . page_url . replace ( ( '?' + data . page_parameters ) , '' ) ;
103
78
104
79
return {
105
80
tab : 'page' ,
106
- data : {
107
- ...( data . global ) ,
108
- page : {
109
- ...( data . page )
110
- }
111
- }
81
+ data,
112
82
} ;
113
83
}
114
84
}
@@ -118,73 +88,53 @@ export default class Data {
118
88
url = url . slice ( 7 ) ;
119
89
url = url . split ( '?' ) ;
120
90
121
- data . email . to = url [ 0 ] ;
91
+ data . email_to = url [ 0 ] ;
122
92
if ( url [ 1 ] ) {
123
93
const components = url [ 1 ] . split ( '&' ) ;
124
94
components . forEach ( component => {
125
95
component = component . split ( '=' ) ;
126
96
if ( component [ 0 ] === 'subject' ) {
127
- data . email . subject = decodeURI ( component [ 1 ] ) ;
97
+ data . email_subject = decodeURI ( component [ 1 ] ) ;
128
98
}
129
99
130
100
if ( component [ 0 ] === 'body' ) {
131
- data . email . body = decodeURI ( component [ 1 ] ) ;
101
+ data . email_body = decodeURI ( component [ 1 ] ) ;
132
102
}
133
103
} ) ;
134
104
}
135
105
136
106
return {
137
107
tab : 'email' ,
138
- data : {
139
- ...( data . global ) ,
140
- email : {
141
- ...( data . email )
142
- }
143
- }
108
+ data,
144
109
}
145
110
}
146
111
}
147
112
148
113
if ( linkType === 'phone' ) {
149
114
if ( url . slice ( 0 , 4 ) === 'tel:' ) {
150
- data . phone . phone = url . slice ( 4 ) ;
115
+ data . phone_phone = url . slice ( 4 ) ;
151
116
152
117
return {
153
118
tab : 'phone' ,
154
- data : {
155
- ...( data . global ) ,
156
- phone : {
157
- ...( data . phone )
158
- }
159
- }
119
+ data,
160
120
}
161
121
}
162
122
}
163
123
164
124
if ( linkType === 'file' ) {
165
- data . file . file = url ;
125
+ data . file_file = { value : url , metadata : undefined } ;
166
126
167
127
return {
168
128
tab : 'file' ,
169
- data : {
170
- ...( data . global ) ,
171
- file : {
172
- ...( data . file )
173
- }
174
- }
129
+ data,
175
130
}
176
131
}
177
132
178
- data . url . url = url ;
133
+ data . url_url = url ;
179
134
180
135
return {
181
136
tab : 'url' ,
182
- data : {
183
- ...( data . global ) ,
184
- url : {
185
- ...( data . url )
186
- }
187
- }
137
+ data,
188
138
} ;
189
139
}
190
140
}
0 commit comments