Skip to content

Commit dd75472

Browse files
authored
Merge pull request #36 from jpeltoniemi/feature-attach
Moved wplf form initialization under window.wplf.attach
2 parents 18f41fc + 22fbbe6 commit dd75472

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

assets/scripts/wplf-form.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313

1414
window.wplf = {
1515
successCallbacks: [],
16-
errorCallbacks: []
17-
};
18-
19-
document.addEventListener("DOMContentLoaded", function(){
20-
[].forEach.call(document.querySelectorAll(".libre-form"), function(form){
16+
errorCallbacks: [],
17+
attach: function(form){
18+
// form is a selector
19+
if (typeof form == 'string')
20+
form = document.querySelectorAll(form);
21+
22+
// form is an array of elements or a node list
23+
if (form.constructor === Array || form.constructor === NodeList){
24+
[].forEach.call(form, function(form){
25+
window.wplf.attach(form);
26+
});
27+
return;
28+
}
2129

2230
form.addEventListener("submit", function(e){
2331

@@ -91,6 +99,10 @@ document.addEventListener("DOMContentLoaded", function(){
9199
e.preventDefault();
92100
});
93101

94-
});
102+
}
103+
}
104+
105+
document.addEventListener("DOMContentLoaded", function(){
106+
[].forEach.call(document.querySelectorAll(".libre-form"), wplf.attach);
95107
});
96108
})();

0 commit comments

Comments
 (0)