Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Oct 13, 2015
1 parent 54911a7 commit 0ede79a
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/lib/dom-api-classlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

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) {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/dom-api-event.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
var DomApi = Polymer.DomApi.ctor;
var Settings = Polymer.Settings;


/**
* DomApi.Event allows maniuplation of events compatible with
* the scoping concepts in Shadow DOM and compatible with both Shady DOM
* and Shadow DOM. The general usage is
* `Polymer.dom(event).property`. The `path` property returns `event.path`
* matching Shadow DOM. The `rootTarget` property returns the first node
* in the `path` and is the original event target. The `localTarget` property
* matches event.target under Shadow DOM and is the scoped event target.
*/
DomApi.Event = function(event) {
this.event = event;
};
Expand Down
9 changes: 8 additions & 1 deletion src/lib/dom-api-flush.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@
-->
<script>

// add Polymer.dom flush api...
/**
* `Polymer.dom.flush()` causes any asynchronously queued actions to be
* flushed synchronously. It should be used sparingly as calling it frequently
* can negatively impact performance since work is often deferred for
* efficiency. Calling `Polymer.dom.flush()` is useful, for example, when
* an element has to measure itself and is unsure about the state of its
* internal or compoased DOM.
*/
Polymer.Base.extend(Polymer.dom, {

_flushGuard: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
var DomApi = Polymer.DomApi.ctor;
var Settings = Polymer.Settings;

DomApi.MutationContent = function(domApi) {
DomApi.Mutation.call(this, domApi);
/**
* DomApi.ObserveDistributedNodes 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.ObserveDistributedNodes = function(domApi) {
DomApi.ObserveNodes.call(this, domApi);
};

DomApi.MutationContent.prototype = Object.create(DomApi.Mutation.prototype);
DomApi.ObserveDistributedNodes.prototype =
Object.create(DomApi.ObserveNodes.prototype);

Polymer.Base.extend(DomApi.MutationContent.prototype, {
Polymer.Base.extend(DomApi.ObserveDistributedNodes.prototype, {

// NOTE: ShadyDOM distribute provokes notification of these observers
// so no setup is required.
Expand All @@ -41,7 +49,7 @@

if (Settings.useShadow) {

Polymer.Base.extend(DomApi.MutationContent.prototype, {
Polymer.Base.extend(DomApi.ObserveDistributedNodes.prototype, {

// NOTE: Under ShadowDOM we must observe the host element for
// changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
var Settings = Polymer.Settings;
var hasDomApi = Polymer.DomApi.hasDomApi;

DomApi.Mutation = function(domApi) {
/**
* DomApi.ObserveNodes tracks changes to an element's effective child nodes,
* the same list returned from `Polymer.dom(node).getEffectiveChildNodes()`.
* It is not meant to be used directly; it is used by
* `Polymer.dom(node).observeNodes(callback)` to observe changes.
*/
DomApi.ObserveNodes = function(domApi) {
this.domApi = domApi;
this.node = this.domApi.node;
this._listeners = [];
};

DomApi.Mutation.prototype = {
DomApi.ObserveNodes.prototype = {

addListener: function(callback) {
if (!this._isSetup) {
Expand Down Expand Up @@ -167,12 +173,13 @@

if (Settings.useShadow) {

var baseSetup = DomApi.Mutation.prototype._setup;
var baseCleanup = DomApi.Mutation.prototype._cleanup;
var baseSetup = DomApi.ObserveNodes.prototype._setup;
var baseCleanup = DomApi.ObserveNodes.prototype._cleanup;

var beforeCallListeners = DomApi.Mutation.prototype._beforeCallListeners;
var beforeCallListeners = DomApi.ObserveNodes
.prototype._beforeCallListeners;

Polymer.Base.extend(DomApi.Mutation.prototype, {
Polymer.Base.extend(DomApi.ObserveNodes.prototype, {

_setup: function() {
if (!this._observer) {
Expand Down
40 changes: 35 additions & 5 deletions src/lib/dom-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
<link rel="import" href="dom-innerHTML.html">
<script>

/**
* DomApi is a dom manipulation library which is compatible with both
* Shady DOM and Shadow DOM. The general usage is
* `Polymer.dom(node).method(arguments)` where methods and arguments
* match native DOM where possible.
*/
Polymer.DomApi = (function() {
'use strict';

Expand Down Expand Up @@ -462,6 +468,11 @@
return list;
},

/*
Returns a list of effective childNoes within this element. These can be
dom child nodes or elements distributed to children that are insertion
points.
*/
getEffectiveChildNodes: function() {
var list = [];
var c$ = this.childNodes;
Expand Down Expand Up @@ -526,15 +537,34 @@
return n;
},

/**
* Notifies callers about changes to the element's effective child nodes,
* the same list as returned by `getEffectiveChildNodes`.
* @param {function} callback The supplied callback is called with an
* `info` argument which is an object that provides
* the `target` on which the changes occurred, a list of any nodes
* added in the `addedNodes` array, and nodes removed in the
* `removedNodes` array.
* @return {object} Returns a handle which is the argument to
* `unobserveNodes`.
*/
observeNodes: function(callback) {
if (!this.observer) {
this.observer = this.node.localName === CONTENT ?
new DomApi.MutationContent(this) :
new DomApi.Mutation(this);
if (callback) {
if (!this.observer) {
this.observer = this.node.localName === CONTENT ?
new DomApi.ObserveDistributedNodes(this) :
new DomApi.ObserveNodes(this);
}
return this.observer.addListener(callback);
}
return this.observer.addListener(callback);
},

/**
* Stops observing changes to the element's effective child nodes.
* @param {object} handle The handle for the callback that should
* no longer receive notifications. This handle is returned from
* `observeNodes`.
*/
unobserveNodes: function(handle) {
if (this.observer) {
this.observer.removeListener(handle);
Expand Down
7 changes: 2 additions & 5 deletions src/mini/shady.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
<link rel="import" href="../lib/dom-api-flush.html">
<link rel="import" href="../lib/dom-api-event.html">
<link rel="import" href="../lib/dom-api-classlist.html">
<link rel="import" href="../lib/dom-api-mutation.html">
<link rel="import" href="../lib/dom-api-mutation-content.html">
<link rel="import" href="../lib/dom-api-observe-nodes.html">
<link rel="import" href="../lib/dom-api-observe-distributed-nodes.html">
<script>

(function() {
/**
Implements a pared down version of ShadowDOM's scoping, which is easy to
polyfill across browsers.
*/

var hasDomApi = Polymer.DomApi.hasDomApi;

Polymer.Base._addFeature({
Expand Down

0 comments on commit 0ede79a

Please sign in to comment.