Merge pull request #2637 from Polymer/deepcontains

Add `Polymer.dom.deepContains`
This commit is contained in:
Steve Orvell 2015-10-29 15:22:02 -07:00
commit f9d086b2f0
5 changed files with 1031 additions and 964 deletions

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,7 @@
Polymer({
is: 'x-test-no-distribute'
});
</script>
</script>
<dom-module id="x-distribute">
<template>
@ -328,4 +328,24 @@
}
});
</script>
</dom-module>
</dom-module>
<dom-module id="x-deep-contains">
<template>
<div id="shadowed"></div>
<content select="#light"></content>
</template>
<script>
Polymer({
is: 'x-deep-contains',
created: function() {
var e = document.createElement('div');
e.id = 'light';
Polymer.dom(this).appendChild(e);
e = document.createElement('div');
e.id = 'notdistributed';
Polymer.dom(this).appendChild(e);
}
});
</script>
</dom-module>

View File

@ -53,6 +53,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<span>2</span>
</div>
<x-deep-contains></x-deep-contains>
<script src="polymer-dom.js"></script>
</body>

View File

@ -53,6 +53,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<span>2</span>
</div>
<x-deep-contains></x-deep-contains>
<script src="polymer-dom.js"></script>
</body>

View File

@ -632,7 +632,7 @@ suite('Polymer.dom', function() {
} else {
testHeight();
}
});
});
@ -917,4 +917,23 @@ suite('Polymer.dom non-distributed elements', function() {
assert.equal(Polymer.dom(document.createElement('div')).getDestinationInsertionPoints().length, 0);
assert.equal(Polymer.dom(document).getDestinationInsertionPoints().length, 0);
});
test('Deep Contains', function() {
var el = document.querySelector('x-deep-contains');
var shadow = el.$.shadowed;
var light = Polymer.dom(el).querySelector('#light');
var notdistributed = Polymer.dom(el).children[1];
var disconnected = document.createElement('div');
var separate = document.createElement('div');
document.body.appendChild(separate);
assert.equal(Polymer.dom(el).deepContains(el), true, 'Element should deepContain itself');
assert.equal(Polymer.dom(el).deepContains(shadow), true, 'Shadowed Child element should be found');
assert.equal(Polymer.dom(el).deepContains(light), true, 'Light Child element should be found');
assert.equal(Polymer.dom(el).deepContains(notdistributed), true, 'Non-distributed child element should be found');
assert.equal(Polymer.dom(el).deepContains(disconnected), false, 'Disconnected element should not be found');
assert.equal(Polymer.dom(el).deepContains(separate), false, 'Unassociated, attached element should not be found');
document.body.removeChild(separate);
});
});