-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.polymer-1.0.js
73 lines (65 loc) · 1.87 KB
/
jquery.polymer-1.0.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
// browser has native support for shadow root
jQuery.nativeShadowDOM = function () {
return !!document.body.createShadowRoot;
};
// filters
jQuery.extend(
jQuery.expr[":"],
{
shadow: function (elem) {
return elem.shadowRoot;
}
}
);
// methods
// override default jquery find method
// first copy as shallowFind
// jQuery.fn.shallowFind = jQuery.fn.find;
window.getWindow = function (elem) {
return window;
};
// new methods
jQuery.fn.extend({
offset: function (options) {
if (arguments.length) {
return options === undefined ?
this :
this.each(function (i) {
jQuery.offset.setOffset(this, options, i);
});
}
var docElem, win, elem = this[0], box = {top: 0, left: 0},
doc = elem && elem.ownerDocument;
if (!doc) {
return box;
}
docElem = doc.documentElement;
// Support: BlackBerry 5, iOS 3 (original iPhone)
// If we don't have gBCR, just use 0,0 rather than error
if (typeof elem.getBoundingClientRect !== undefined) {
box = elem.getBoundingClientRect();
}
win = getWindow(doc);
return {
top: box.top + win.pageYOffset - docElem.clientTop,
left: box.left + win.pageXOffset - docElem.clientLeft
};
},
hasShadowRoot: function () {
return !!this[0].shadowRoot;
},
getShadowRoot: function () {
return $(this[0].shadowRoot);
},
shadow: function(){
return this.getShadowRoot();
},
getOwnerShadowRoot: function () {
var templateInstance = this[0].templateInstance;
var shadow;
if (templateInstance) {
shadow = templateInstance.model.shadowRoot;
}
return $(shadow);
}
});