This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
282 additions
and
86 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
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
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,70 @@ | ||
// Copyright 2013 The Toolkitchen 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) { | ||
'use strict'; | ||
|
||
function findOne(node, selector) { | ||
var m, el = node.firstElementChild; | ||
while (el) { | ||
if (el.matches(selector)) | ||
return el; | ||
m = findOne(el, selector); | ||
if (m) | ||
return m; | ||
el = el.nextElementSibling; | ||
} | ||
return null; | ||
} | ||
|
||
function findAll(node, selector, results) { | ||
var el = node.firstElementChild; | ||
while (el) { | ||
if (el.matches(selector)) | ||
results[results.length++] = el; | ||
findAll(el, selector, results); | ||
el = el.nextElementSibling; | ||
} | ||
return results; | ||
} | ||
|
||
// find and findAll will only match Simple Selectors, | ||
// Structural Pseudo Classes are not guarenteed to be correct | ||
// http://www.w3.org/TR/css3-selectors/#simple-selectors | ||
|
||
var SelectorsInterface = { | ||
querySelector: function(selector) { | ||
return findOne(this, selector); | ||
}, | ||
querySelectorAll: function(selector) { | ||
return findAll(this, selector, new NodeList()) | ||
} | ||
}; | ||
|
||
var GetElementsByInterface = { | ||
getElementsByTagName: function(tagName) { | ||
// TODO(arv): Check tagName? | ||
return this.querySelectorAll(tagName); | ||
}, | ||
getElementsByClassName: function(className) { | ||
// TODO(arv): Check className? | ||
return this.querySelectorAll('.' + className); | ||
}, | ||
getElementsByTagNameNS: function(ns, tagName) { | ||
// TODO(arv): Check tagName? | ||
var result = new NodeList; | ||
var els = this.getElementsByTagName(tagName); | ||
for (var i = 0, j = 0; i < els.length; i++) { | ||
if (els[i].namespace === ns) | ||
result[j++] = els[i]; | ||
} | ||
result.length = j; | ||
return result; | ||
} | ||
}; | ||
|
||
scope.GetElementsByInterface = GetElementsByInterface; | ||
scope.SelectorsInterface = SelectorsInterface; | ||
|
||
})(this.ShadowDOMPolyfill); |
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
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
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
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
Oops, something went wrong.