-
Notifications
You must be signed in to change notification settings - Fork 0
/
dom.js
44 lines (39 loc) · 1.2 KB
/
dom.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
40
41
42
43
44
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["mu-create/regexp"], factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory(require("mu-create/regexp"));
} else {
root["mu-jquery-widget/dom"] = factory(root["mu-create/regexp"]);
}
})(this, function (regexp) {
var toString = Object.prototype.toString;
var re_on = /^one?$/;
function copy(o) {
return Object.keys(o).reduce(function (result, key) {
if (!result.hasOwnProperty(key)) {
result[key] = o[key];
}
return result;
}, this);
}
return regexp(/^(one?|attr|prop)\/(.+?)(?:\((.*)\))?$/, function (result, data, method, type, args) {
var dom = toString.call(data.value) === "[object Object]"
? data.value
: re_on.test(method)
? { "handler": data.value }
: { "value": data.value };
dom = copy.call(dom, re_on.test(method)
? {
"method": method,
"events": type,
"selector": args
}
: {
"method": method,
"name": type
});
(result.dom = result.dom || []).push(dom);
return false;
});
});