-
Notifications
You must be signed in to change notification settings - Fork 101
/
bliss._.js
73 lines (59 loc) · 1.66 KB
/
bliss._.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
(function($) {
"use strict";
if (!Bliss || Bliss.shy) {
return;
}
var _ = Bliss.property;
// Methods requiring Bliss Full
$.add({
// Clone elements, with events and data
clone: function () {
console.warn("$.clone() is deprecated and will be removed in a future version of Bliss.");
var clone = this.cloneNode(true);
var descendants = $.$("*", clone).concat(clone);
$.$("*", this).concat(this).forEach(function(element, i, arr) {
$.events(descendants[i], element);
descendants[i]._.data = $.extend({}, element._.data);
});
return clone;
}
}, {array: false});
// Define the _ property on arrays and elements
Object.defineProperty(Node.prototype, _, {
// Written for IE compatibility (see #49)
get: function getter () {
Object.defineProperty(Node.prototype, _, {
get: undefined
});
Object.defineProperty(this, _, {
value: new $.Element(this)
});
Object.defineProperty(Node.prototype, _, {
get: getter
});
return this[_];
},
configurable: true
});
Object.defineProperty(Array.prototype, _, {
get: function () {
Object.defineProperty(this, _, {
value: new $.Array(this)
});
return this[_];
},
configurable: true
});
// Hijack addEventListener and removeEventListener to store callbacks
if (self.EventTarget && "addEventListener" in EventTarget.prototype) {
EventTarget.prototype.addEventListener = function(type, callback, options) {
return $.bind(this, type, callback, options);
};
EventTarget.prototype.removeEventListener = function(type, callback, options) {
return $.unbind(this, type, callback, options);
};
}
// Set $ and $$ convenience methods, if not taken
self.$ = self.$ || $;
self.$$ = self.$$ || $.$;
})(Bliss);