-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2548 from Polymer/effective-children
Effective children
- Loading branch information
Showing
18 changed files
with
2,128 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- | ||
@license | ||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<script> | ||
|
||
(function() { | ||
'use strict'; | ||
|
||
var DomApi = Polymer.DomApi.ctor; | ||
|
||
/** | ||
* DomApi.classList allows maniuplation of `classList` compatible with | ||
* Polymer.dom. The general usage is | ||
* `Polymer.dom(node).classList.method(arguments)` where methods and arguments | ||
* match native DOM. | ||
*/ | ||
Object.defineProperty(DomApi.prototype, 'classList', { | ||
get: function() { | ||
if (!this._classList) { | ||
this._classList = new DomApi.ClassList(this); | ||
} | ||
return this._classList; | ||
}, | ||
configurable: true | ||
}); | ||
|
||
DomApi.ClassList = function(host) { | ||
this.domApi = host; | ||
this.node = host.node; | ||
} | ||
|
||
DomApi.ClassList.prototype = { | ||
add: function() { | ||
this.node.classList.add.apply(this.node.classList, arguments); | ||
this.domApi._distributeParent(); | ||
}, | ||
|
||
remove: function() { | ||
this.node.classList.remove.apply(this.node.classList, arguments); | ||
this.domApi._distributeParent(); | ||
}, | ||
|
||
toggle: function() { | ||
this.node.classList.toggle.apply(this.node.classList, arguments); | ||
this.domApi._distributeParent(); | ||
}, | ||
contains: function() { | ||
return this.node.classList.contains.apply(this.node.classList, | ||
arguments); | ||
} | ||
} | ||
|
||
})(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!-- | ||
@license | ||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<link rel="import" href="settings.html"> | ||
<script> | ||
(function() { | ||
'use strict'; | ||
|
||
var DomApi = Polymer.DomApi.ctor; | ||
var Settings = Polymer.Settings; | ||
|
||
/** | ||
* DomApi.DistributedNodesObserver notifies when the list returned by | ||
* a <content> element's `getDistributedNodes()` may have changed. | ||
* It is not meant to be used directly; it is used by | ||
* `Polymer.dom(node).observeNodes(callback)` to observe changes to | ||
* `<content>.getDistributedNodes()`. | ||
*/ | ||
DomApi.DistributedNodesObserver = function(domApi) { | ||
DomApi.EffectiveNodesObserver.call(this, domApi); | ||
}; | ||
|
||
DomApi.DistributedNodesObserver.prototype = | ||
Object.create(DomApi.EffectiveNodesObserver.prototype); | ||
|
||
Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { | ||
|
||
// NOTE: ShadyDOM distribute provokes notification of these observers | ||
// so no setup is required. | ||
_setup: function() {}, | ||
|
||
_cleanup: function() {}, | ||
|
||
// no need to update sub-elements since <content> does not nest | ||
// (but note that <slot> will) | ||
_beforeCallListeners: function() {}, | ||
|
||
_getEffectiveNodes: function() { | ||
return this.domApi.getDistributedNodes(); | ||
} | ||
|
||
}); | ||
|
||
if (Settings.useShadow) { | ||
|
||
Polymer.Base.extend(DomApi.DistributedNodesObserver.prototype, { | ||
|
||
// NOTE: Under ShadowDOM we must observe the host element for | ||
// changes. | ||
_setup: function() { | ||
if (!this._observer) { | ||
var root = this.domApi.getOwnerRoot(); | ||
var host = root && root.host; | ||
if (host) { | ||
this._observer = Polymer.dom(host).observeNodes( | ||
this._scheduleNotify.bind(this)); | ||
// NOTE: we identify this listener as needed for <content> | ||
// notification so that enableShadowAttributeTracking | ||
// can find these observers an ensure that we pass always | ||
// pass notifications down. | ||
this._observer._isContentListener = true; | ||
if (this._hasAttrSelect()) { | ||
Polymer.dom(host).observer.enableShadowAttributeTracking(); | ||
} | ||
} | ||
} | ||
}, | ||
|
||
_hasAttrSelect: function() { | ||
var select = this.node.getAttribute('select'); | ||
return select && select.match(/[[.]+/); | ||
}, | ||
|
||
_cleanup: function() { | ||
var root = this.domApi.getOwnerRoot(); | ||
var host = root && root.host; | ||
if (host) { | ||
Polymer.dom(host).unobserveNodes(this._observer); | ||
} | ||
this._observer = null; | ||
} | ||
|
||
}); | ||
|
||
} | ||
|
||
})(); | ||
|
||
</script> |
Oops, something went wrong.