Skip to content

Commit dfa1ec2

Browse files
author
Aline Lee
authored
Merge pull request #44 from elo7/fix-find
Updates dependencies and adds compatibility with shadow DOM
2 parents 6442e34 + 345a12e commit dfa1ec2

5 files changed

Lines changed: 42 additions & 11 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "doc-amd",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"homepage": "https://github.com/elo7/doc-amd",
55
"description": "A small DOM manipulation library",
66
"main": "doc.js",

doc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ define('doc', ['event'], function(event) {
2020

2121
var search = function(namespace, selector) {
2222
var selector = selector.replace(/^\s+|\s+$/g, '');
23-
if (matcher.isTag(selector)) {
23+
if (matcher.isTag(selector) && namespace.getElementsByTagName) {
2424
return convertHtmlCollectionToArray(namespace.getElementsByTagName(selector));
2525
} else if(matcher.isId(selector)) {
2626
selector = selector.replace('#', '');
27+
if (namespace.getElementById) {
28+
return namespace.getElementById(selector);
29+
}
2730
return document.getElementById(selector);
2831
} else if (matcher.isClass(selector) && namespace.getElementsByClassName) {
2932
selector = selector.replace('.', '');

doc.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elo7-doc-amd",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"license": "BSD-3-Clause",
55
"description": "Elo7 doc amd",
66
"keywords": [
@@ -19,16 +19,16 @@
1919
},
2020
"author": "Elo7",
2121
"dependencies": {
22-
"define-async": "1.1.1",
22+
"define-async": "1.2.0",
2323
"elo7-events-amd": "1.1.3"
2424
},
2525
"devDependencies": {
26-
"bower": "1.4.1",
27-
"http-server": "0.7.4",
28-
"mocha": "2.0.1",
26+
"bower": "1.8.2",
27+
"http-server": "0.10.0",
28+
"mocha": "4.0.1",
2929
"mocha-phantomjs": "4.1.0",
30-
"phantomjs-prebuilt": "2.1.14",
31-
"proclaim": "2.0.0",
32-
"uglify-js": "3.0.28"
30+
"phantomjs-prebuilt": "2.1.15",
31+
"proclaim": "3.4.6",
32+
"uglify-js": "3.1.3"
3333
}
3434
}

test/docTest.js.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<div id='first-broadcast-listener'></div>
7878
<div id='second-broadcast-listener'></div>
7979
<div id='third-broadcast-listener'></div>
80+
<div id='shadow-root-test'></div>
8081
</div>
8182

8283
<div id="mocha"></div>
@@ -632,6 +633,33 @@
632633
}, 10);
633634
fireEvent($('#debounce-button').first(), 'click');
634635
});
636+
describe('with shadow DOM', function() {
637+
before(function() {
638+
if (!HTMLElement.prototype.createShadowRoot) {
639+
this.skip();
640+
}
641+
});
642+
it("should find elements inside shadow root by tag name", function() {
643+
var $root = $($('#shadow-root-test').first().createShadowRoot()),
644+
div = document.createElement('div');
645+
$root.append(div);
646+
assert.equal($root.find('div').first(), div);
647+
});
648+
it("should find elements inside shadow root by id", function() {
649+
var $root = $($('#shadow-root-test').first().createShadowRoot()),
650+
div = document.createElement('div');
651+
div.id = 'mocha';
652+
$root.append(div);
653+
assert.equal($root.find('#mocha').first(), div);
654+
});
655+
it("should find elements inside shadow root by class name", function() {
656+
var $root = $($('#shadow-root-test').first().createShadowRoot()),
657+
div = document.createElement('div');
658+
div.className = 'search-class-test';
659+
$root.append(div);
660+
assert.equal($root.find('.search-class-test').first(), div);
661+
});
662+
});
635663
});
636664
});
637665
</script>

0 commit comments

Comments
 (0)