mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #2718 from Polymer/add-polymer-dom-wrap
Add Polymer.DomApi.wrap
This commit is contained in:
commit
c07a746936
@ -29,23 +29,17 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
var nativeCloneNode = Element.prototype.cloneNode;
|
||||
var nativeImportNode = Document.prototype.importNode;
|
||||
|
||||
// ensure nodes are wrapped if SD polyfill is present
|
||||
var needsToWrap = Settings.hasShadow && !Settings.nativeShadow;
|
||||
var wrap = window.wrap ? window.wrap : function(node) { return node; };
|
||||
|
||||
var DomApi = function(node) {
|
||||
this.node = node;
|
||||
this.node = needsToWrap ? wrap(node) : node;
|
||||
if (this.patch) {
|
||||
this.patch();
|
||||
}
|
||||
};
|
||||
|
||||
// ensure nodes are wrapped if SD polyfill is present
|
||||
if (window.wrap && Settings.useShadow && !Settings.useNativeShadow) {
|
||||
DomApi = function(node) {
|
||||
this.node = wrap(node);
|
||||
if (this.patch) {
|
||||
this.patch();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
DomApi.prototype = {
|
||||
|
||||
flush: function() {
|
||||
@ -66,7 +60,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
var n = node;
|
||||
// wrap document for SD polyfill
|
||||
var wrappedDocument = wrap(document);
|
||||
var wrappedDocument = Polymer.DomApi.wrap(document);
|
||||
|
||||
// walk from node to `this` or `document`
|
||||
while (n && n !== wrappedDocument && n !== this.node) {
|
||||
@ -977,7 +971,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
hasInsertionPoint: hasInsertionPoint,
|
||||
ctor: DomApi,
|
||||
factory: factory,
|
||||
hasDomApi: hasDomApi
|
||||
hasDomApi: hasDomApi,
|
||||
wrap: wrap
|
||||
};
|
||||
|
||||
})();
|
||||
|
@ -199,7 +199,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
handleNative: function(ev) {
|
||||
var handled;
|
||||
var type = ev.type;
|
||||
var node = wrap(ev.currentTarget);
|
||||
var node = Polymer.DomApi.wrap(ev.currentTarget);
|
||||
var gobj = node[GESTURE_KEY];
|
||||
if (!gobj) {
|
||||
return;
|
||||
@ -296,7 +296,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
// automate the event listeners for the native events
|
||||
add: function(node, evType, handler) {
|
||||
// SD polyfill: handle case where `node` is unwrapped, like `document`
|
||||
node = wrap(node);
|
||||
node = Polymer.DomApi.wrap(node);
|
||||
var recognizer = this.gestures[evType];
|
||||
var deps = recognizer.deps;
|
||||
var name = recognizer.name;
|
||||
@ -329,7 +329,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
// automate event listener removal for native events
|
||||
remove: function(node, evType, handler) {
|
||||
// SD polyfill: handle case where `node` is unwrapped, like `document`
|
||||
node = wrap(node);
|
||||
node = Polymer.DomApi.wrap(node);
|
||||
var recognizer = this.gestures[evType];
|
||||
var deps = recognizer.deps;
|
||||
var name = recognizer.name;
|
||||
|
@ -349,3 +349,11 @@
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id="x-wrapped">
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'x-wrapped'
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
|
@ -55,6 +55,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
<x-deep-contains></x-deep-contains>
|
||||
|
||||
<x-wrapped></x-wrapped>
|
||||
|
||||
<script src="polymer-dom.js"></script>
|
||||
|
||||
</body>
|
||||
|
@ -55,6 +55,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
|
||||
<x-deep-contains></x-deep-contains>
|
||||
|
||||
<x-wrapped></x-wrapped>
|
||||
|
||||
<script src="polymer-dom.js"></script>
|
||||
|
||||
</body>
|
||||
|
@ -936,4 +936,13 @@ suite('Polymer.dom non-distributed elements', function() {
|
||||
|
||||
document.body.removeChild(separate);
|
||||
});
|
||||
|
||||
test('Polymer.DomApi.wrap', function() {
|
||||
var wrap = window.wrap || function(node) { return node; };
|
||||
|
||||
var node = document.querySelector('x-wrapped');
|
||||
assert.equal(wrap(document), Polymer.DomApi.wrap(document), 'document should be wrapped');
|
||||
assert.equal(wrap(node), Polymer.DomApi.wrap(node), 'node should be wrapped');
|
||||
assert.equal(wrap(node), Polymer.dom(node).node, 'Polymer.dom should always wrap the input node');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user