This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start on observer, not integrated yet.
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 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,57 @@ | ||
/* | ||
Copyright 2013 The Polymer Authors. All rights reserved. | ||
Use of this source code is governed by a BSD-style | ||
license that can be found in the LICENSE file. | ||
*/ | ||
|
||
(function(scope){ | ||
|
||
var IMPORT_LINK_TYPE = scope.IMPORT_LINK_TYPE; | ||
var importSelector = 'link[rel=' + IMPORT_LINK_TYPE + ']'; | ||
|
||
var importer = scope.importer; | ||
|
||
function handler(mutations) { | ||
for (var i=0, l=mutations.length, m; (i<l) && (m=mutations[i]); i++) { | ||
if (m.type === 'childList' && m.addedNodes.length) { | ||
addedNodes(m.addedNodes); | ||
} | ||
}); | ||
}; | ||
|
||
function addedNodes(nodes) { | ||
for (var i=0, l=nodes.length, n; (i<l) && (n=nodes[i]); i++) { | ||
if (shouldLoadNode(n)) { | ||
// TODO(sorvell): need to add this api. | ||
importer.addNode(node); | ||
} | ||
} | ||
} | ||
|
||
// TODO(sorvell): need x-platform matches | ||
function shouldLoadNode(node) { | ||
return node.matches(importer.preloadSelectors); | ||
} | ||
|
||
var observer = new MutationObserver(handler); | ||
|
||
function observe(root) { | ||
observer.observe(root, {childList: true, subtree: true}); | ||
} | ||
|
||
// ***** | ||
// TODO(sorvell): wip | ||
function canParse(node) { | ||
var doc = node.ownerDocument; | ||
return nextImportToParse(doc) === node; | ||
} | ||
|
||
function nextImportToParse(doc) { | ||
|
||
} | ||
|
||
|
||
// exports | ||
scope.observe = observe; | ||
|
||
})(HTMLImports); |