-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
39 lines (31 loc) · 956 Bytes
/
form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// forms
(function (root, factory) {
if (typeof module === 'object' && module.exports) {
module.exports = factory( require('./live-dom') );
} else if (typeof define === 'function' && define.amd && typeof require === 'function') {
require(['$live'], function ($live) {
return factory($live);
});
} else {
factory(root.$live);
}
})(this, function ($live) {
var formRunning = null,
formHandlers = {};
$live.form = function (formName, handler) {
formHandlers[formName] = handler;
if( formRunning === null ) {
formRunning = false;
$live('form[name]', function () {
if( formHandlers[this.name] ) {
formHandlers[this.name].apply(this, arguments);
}
}, function () {
formRunning = true;
});
} else if( formRunning ) {
[].forEach.call(document.querySelectorAll('form[name="' + formName + '"]'), handler);
}
};
return $live.form;
});