@@ -65,28 +65,29 @@ export default Base.extend({
65
65
// XXX: This is used in only one project for linked
66
66
// fullcalendars, it's sanity is wonky and we should
67
67
// probably solve it differently.
68
- if ( $ el. is ( "a" ) && $ ( cfgs [ 0 ] . nextHref ) . length > 0 ) {
68
+ if ( this . el . nodeName === "A" && $ ( cfgs [ 0 ] . nextHref ) . length > 0 ) {
69
69
log . debug (
70
70
"Skipping as next href is anchor, which already exists" ,
71
71
cfgs [ 0 ] . nextHref
72
72
) ;
73
73
// XXX: reconsider how the injection enters exhausted state
74
- return $el . attr ( {
75
- href : ( window . location . href . split ( "#" ) [ 0 ] || "" ) + cfgs [ 0 ] . nextHref ,
76
- } ) ;
74
+ return this . el . setAttribute (
75
+ "href" ,
76
+ ( window . location . href . split ( "#" ) [ 0 ] || "" ) + cfgs [ 0 ] . nextHref
77
+ ) ;
77
78
}
78
79
}
79
80
if ( cfgs [ 0 ] . pushMarker ) {
80
81
$ ( "body" ) . on ( "push" , ( event , data ) => {
81
82
log . debug ( "received push message: " + data ) ;
82
83
if ( data == cfgs [ 0 ] . pushMarker ) {
83
84
log . debug ( "re-injecting " + data ) ;
84
- this . onTrigger ( { currentTarget : $el [ 0 ] } ) ;
85
+ this . onTrigger ( { currentTarget : this . el } ) ;
85
86
}
86
87
} ) ;
87
88
}
88
89
if ( cfgs [ 0 ] . idleTrigger ) {
89
- this . _initIdleTrigger ( $el , cfgs [ 0 ] . idleTrigger ) ;
90
+ this . _initIdleTrigger ( this . $el , cfgs [ 0 ] . idleTrigger ) ;
90
91
} else {
91
92
switch ( cfgs [ 0 ] . trigger ) {
92
93
case "default" :
@@ -96,27 +97,28 @@ export default Base.extend({
96
97
}
97
98
} ) ;
98
99
// setup event handlers
99
- if ( $el . is ( "form" ) ) {
100
- $el . on ( "submit.pat-inject" , this . onTrigger . bind ( this ) )
100
+ if ( this . el . nodeName === "FORM" ) {
101
+ this . $el
102
+ . on ( "submit.pat-inject" , this . onTrigger . bind ( this ) )
101
103
. on ( "click.pat-inject" , "[type=submit]" , ajax . onClickSubmit )
102
104
. on (
103
105
"click.pat-inject" ,
104
106
"[type=submit][formaction], [type=image][formaction]" ,
105
107
this . onFormActionSubmit . bind ( this )
106
108
) ;
107
- } else if ( $ el. is ( ".pat-subform" ) ) {
109
+ } else if ( this . el . matches ( ".pat-subform" ) ) {
108
110
log . debug ( "Initializing subform with injection" ) ;
109
111
} else {
110
- $el . on ( "click.pat-inject" , this . onTrigger . bind ( this ) ) ;
112
+ this . $el . on ( "click.pat-inject" , this . onTrigger . bind ( this ) ) ;
111
113
}
112
114
break ;
113
115
case "autoload" :
114
116
if ( ! cfgs [ 0 ] . delay ) {
115
- this . onTrigger ( { currentTarget : $el [ 0 ] } ) ;
117
+ this . onTrigger ( { currentTarget : this . el } ) ;
116
118
} else {
117
119
// generate UID
118
120
const uid = Math . random ( ) . toString ( 36 ) ;
119
- $ el. attr ( "data-pat-inject-uid" , uid ) ;
121
+ this . el . setAttribute ( "data-pat-inject-uid" , uid ) ;
120
122
121
123
// function to trigger the autoload and mark as triggered
122
124
const delayed_trigger = ( uid_ ) => {
@@ -127,7 +129,7 @@ export default Base.extend({
127
129
if ( still_there . length == 0 ) return false ;
128
130
129
131
$el . data ( "pat-inject-autoloaded" , true ) ;
130
- this . onTrigger ( { currentTarget : $el [ 0 ] } ) ;
132
+ this . onTrigger ( { currentTarget : this . el } ) ;
131
133
return true ;
132
134
} ;
133
135
window . setTimeout (
@@ -137,21 +139,20 @@ export default Base.extend({
137
139
}
138
140
break ;
139
141
case "autoload-visible" :
140
- this . _initAutoloadVisible ( $el , cfgs ) ;
142
+ this . _initAutoloadVisible ( this . $el , cfgs ) ;
141
143
break ;
142
144
case "idle" :
143
- this . _initIdleTrigger ( $el , cfgs [ 0 ] . delay ) ;
145
+ this . _initIdleTrigger ( this . $el , cfgs [ 0 ] . delay ) ;
144
146
break ;
145
147
}
146
148
}
147
149
148
- log . debug ( "initialised:" , $ el) ;
149
- return $el ;
150
+ log . debug ( "initialised:" , this . el ) ;
151
+ return this . $el ;
150
152
} ,
151
153
152
154
destroy ( $el ) {
153
155
$el . off ( ".pat-inject" ) ;
154
- $el . data ( "pat-inject" , null ) ;
155
156
return $el ;
156
157
} ,
157
158
@@ -160,16 +161,15 @@ export default Base.extend({
160
161
* link has been clicked.
161
162
*/
162
163
const $el = $ ( e . currentTarget ) ;
163
- const cfgs = $el . data ( "pat-inject" ) ;
164
164
if ( $el . is ( "form" ) ) {
165
165
// store the params of the form in the config, to be used by history
166
- for ( cfg of cfgs ) {
166
+ for ( const cfg of this . cfgs ) {
167
167
cfg . params = $ . param ( $sub . serializeArray ( ) ) ;
168
168
}
169
169
}
170
170
e . preventDefault && e . preventDefault ( ) ;
171
171
$el . trigger ( "patterns-inject-triggered" ) ;
172
- this . execute ( cfgs , $el ) ;
172
+ this . execute ( this . cfgs , $el ) ;
173
173
} ,
174
174
175
175
onFormActionSubmit ( e ) {
@@ -185,7 +185,7 @@ export default Base.extend({
185
185
const cfgs = this . extractConfig ( $cfg_node , opts ) ;
186
186
187
187
// store the params of the form in the config, to be used by history
188
- for ( cfg of cfgs ) {
188
+ for ( const cfg of cfgs ) {
189
189
cfg . params = $ . param ( $sub . serializeArray ( ) ) ;
190
190
}
191
191
@@ -201,7 +201,7 @@ export default Base.extend({
201
201
const cfgs = this . extractConfig ( $sub [ 0 ] ) ;
202
202
203
203
// store the params of the subform in the config, to be used by history
204
- for ( cfg of cfgs ) {
204
+ for ( const cfg of cfgs ) {
205
205
cfg . params = $ . param ( $sub . serializeArray ( ) ) ;
206
206
}
207
207
0 commit comments