Skip to content

Commit 5550abd

Browse files
committed
upd
1 parent 755fcce commit 5550abd

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Diff for: src/pat/inject/inject.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,29 @@ export default Base.extend({
6565
// XXX: This is used in only one project for linked
6666
// fullcalendars, it's sanity is wonky and we should
6767
// 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) {
6969
log.debug(
7070
"Skipping as next href is anchor, which already exists",
7171
cfgs[0].nextHref
7272
);
7373
// 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+
);
7778
}
7879
}
7980
if (cfgs[0].pushMarker) {
8081
$("body").on("push", (event, data) => {
8182
log.debug("received push message: " + data);
8283
if (data == cfgs[0].pushMarker) {
8384
log.debug("re-injecting " + data);
84-
this.onTrigger({ currentTarget: $el[0] });
85+
this.onTrigger({ currentTarget: this.el });
8586
}
8687
});
8788
}
8889
if (cfgs[0].idleTrigger) {
89-
this._initIdleTrigger($el, cfgs[0].idleTrigger);
90+
this._initIdleTrigger(this.$el, cfgs[0].idleTrigger);
9091
} else {
9192
switch (cfgs[0].trigger) {
9293
case "default":
@@ -96,27 +97,28 @@ export default Base.extend({
9697
}
9798
});
9899
// 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))
101103
.on("click.pat-inject", "[type=submit]", ajax.onClickSubmit)
102104
.on(
103105
"click.pat-inject",
104106
"[type=submit][formaction], [type=image][formaction]",
105107
this.onFormActionSubmit.bind(this)
106108
);
107-
} else if ($el.is(".pat-subform")) {
109+
} else if (this.el.matches(".pat-subform")) {
108110
log.debug("Initializing subform with injection");
109111
} else {
110-
$el.on("click.pat-inject", this.onTrigger.bind(this));
112+
this.$el.on("click.pat-inject", this.onTrigger.bind(this));
111113
}
112114
break;
113115
case "autoload":
114116
if (!cfgs[0].delay) {
115-
this.onTrigger({ currentTarget: $el[0] });
117+
this.onTrigger({ currentTarget: this.el });
116118
} else {
117119
// generate UID
118120
const uid = Math.random().toString(36);
119-
$el.attr("data-pat-inject-uid", uid);
121+
this.el.setAttribute("data-pat-inject-uid", uid);
120122

121123
// function to trigger the autoload and mark as triggered
122124
const delayed_trigger = (uid_) => {
@@ -127,7 +129,7 @@ export default Base.extend({
127129
if (still_there.length == 0) return false;
128130

129131
$el.data("pat-inject-autoloaded", true);
130-
this.onTrigger({ currentTarget: $el[0] });
132+
this.onTrigger({ currentTarget: this.el });
131133
return true;
132134
};
133135
window.setTimeout(
@@ -137,21 +139,20 @@ export default Base.extend({
137139
}
138140
break;
139141
case "autoload-visible":
140-
this._initAutoloadVisible($el, cfgs);
142+
this._initAutoloadVisible(this.$el, cfgs);
141143
break;
142144
case "idle":
143-
this._initIdleTrigger($el, cfgs[0].delay);
145+
this._initIdleTrigger(this.$el, cfgs[0].delay);
144146
break;
145147
}
146148
}
147149

148-
log.debug("initialised:", $el);
149-
return $el;
150+
log.debug("initialised:", this.el);
151+
return this.$el;
150152
},
151153

152154
destroy($el) {
153155
$el.off(".pat-inject");
154-
$el.data("pat-inject", null);
155156
return $el;
156157
},
157158

@@ -160,16 +161,15 @@ export default Base.extend({
160161
* link has been clicked.
161162
*/
162163
const $el = $(e.currentTarget);
163-
const cfgs = $el.data("pat-inject");
164164
if ($el.is("form")) {
165165
// 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) {
167167
cfg.params = $.param($sub.serializeArray());
168168
}
169169
}
170170
e.preventDefault && e.preventDefault();
171171
$el.trigger("patterns-inject-triggered");
172-
this.execute(cfgs, $el);
172+
this.execute(this.cfgs, $el);
173173
},
174174

175175
onFormActionSubmit(e) {
@@ -185,7 +185,7 @@ export default Base.extend({
185185
const cfgs = this.extractConfig($cfg_node, opts);
186186

187187
// 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) {
189189
cfg.params = $.param($sub.serializeArray());
190190
}
191191

@@ -201,7 +201,7 @@ export default Base.extend({
201201
const cfgs = this.extractConfig($sub[0]);
202202

203203
// 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) {
205205
cfg.params = $.param($sub.serializeArray());
206206
}
207207

0 commit comments

Comments
 (0)