-
Notifications
You must be signed in to change notification settings - Fork 1
/
domination-jQuery.js
executable file
·101 lines (94 loc) · 2.73 KB
/
domination-jQuery.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
(function(basis) {
var _safeAttributeSet = function(_e, attr, val) {
var lattr = attr.toLowerCase();
if (lattr === 'class') {
_e.addClass(val);
} else if ((lattr === 'style') && (typeof(val) === "object")){
_e.css(val);
} else if (lattr.substring(0, 7) === 'observe') {
_e.bind(attr.substring(7).toLowerCase(), val);
} else {
/* fix some stupid IE capitalization bugs */
if (lattr === "rowspan") {
attr = "rowSpan";
} else if (lattr === "colspan") {
attr = "colSpan";
} else if (lattr === "frameborder") {
attr = "frameBorder";
}
_e.attr(attr, val);
}
};
var createDOM = function(n, node_args) {
var attrs = {};
var nodeStart = 0;
if ((node_args !== null) && (node_args.length > 0) ) {
var first = node_args[0];
if (first
&& (typeof(first) == 'object')
&& !('jquery' in first) ) {
attrs = first;
nodeStart = 1;
}
}
var _e ;
if ((n === "input") && navigator.appName === 'Microsoft Internet Explorer' && attrs.name) {
_e = document.createElement('<input name="' + attrs.name + '"/>');
} else {
_e = document.createElement(n);
}
_e = $(_e);
if ((n === "a") && !attrs.href) {
_e.attr("href", "#");
_e.bind("click", function() { return false; });
}
for (var attr in attrs) {
_safeAttributeSet(_e, attr, attrs[attr]);
}
for (var i = nodeStart; i < node_args.length; ++i) {
if (typeof(node_args[i]) === 'function') {
_e.append(node_args[i]());
} else if ( (typeof(node_args[i]) === 'string') || (typeof(node_args[i]) === 'number')) {
_e.append(document.createTextNode(node_args[i]));
} else {
_e.append(node_args[i]);
}
}
return _e;
};
var _nodes = [ 'table', 'tbody','thead', 'tr', 'th', 'td', 'a', 'strong', 'div', 'img',
'br', 'b', 'span', 'li', 'ul', 'ol', 'iframe', 'form', 'h1',
'input', 'h2', 'h3', 'h4','h5','h6', 'p', 'br', 'select', 'option', 'optgroup',
'script', 'label', 'textarea', 'em', 'button', 'b', 'hr', 'fieldset', 'nobr',
'object', 'embed', 'param', 'style'];
var makeFunction = function(nodeName) {
return function() {
return createDOM(nodeName, arguments);
};
};
for (var i = 0; i < _nodes.length; i++) {
var node = _nodes[i].toUpperCase();
var nodeName = _nodes[i];
basis[node] = makeFunction(nodeName);
}
var makeRealArray = function(a) {
return Array.prototype.slice.call(a);
};
var bareLink = basis.A;
basis.A = function() {
var callback = null;
var args = makeRealArray(arguments);
if (typeof(args[0]) == "function") {
callback = args.shift();
}
var rv = bareLink.apply(this, args);
if (callback) {
rv.click(function(e) {
e.preventDefault();
callback();
return false;
});
}
return rv;
};
})(self);