diff --git a/bower.json b/bower.json index 86d5960..f601dc0 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "doc-amd", - "version": "1.3.0", + "version": "1.3.1", "homepage": "https://github.com/elo7/doc-amd", "description": "A small DOM manipulation library", "main": "doc.js", diff --git a/doc.js b/doc.js index 281dd5f..b3043d7 100644 --- a/doc.js +++ b/doc.js @@ -20,10 +20,13 @@ define('doc', ['event'], function(event) { var search = function(namespace, selector) { var selector = selector.replace(/^\s+|\s+$/g, ''); - if (matcher.isTag(selector)) { + if (matcher.isTag(selector) && namespace.getElementsByTagName) { return convertHtmlCollectionToArray(namespace.getElementsByTagName(selector)); } else if(matcher.isId(selector)) { selector = selector.replace('#', ''); + if (namespace.getElementById) { + return namespace.getElementById(selector); + } return document.getElementById(selector); } else if (matcher.isClass(selector) && namespace.getElementsByClassName) { selector = selector.replace('.', ''); diff --git a/doc.min.js b/doc.min.js index 5af5d92..c852d5e 100644 --- a/doc.min.js +++ b/doc.min.js @@ -1 +1 @@ -define("doc",["event"],function(t){function e(t){return t?u("string"==typeof t?r(document,t):t):t}var n={isTag:function(t){return t.match(/^\w+$/)},isClass:function(t){return t.match(/^\.[\w-]+$/)},isId:function(t){return t.match(/^#[\w-]+$/)},isTagWithClass:function(t){return t.match(/[\w+\.\w+]+/)}},i=function(t){return!!(t&&t.call&&t.apply)},r=function(t,e){var e=e.replace(/^\s+|\s+$/g,"");return n.isTag(e)?o(t.getElementsByTagName(e)):n.isId(e)?(e=e.replace("#",""),document.getElementById(e)):n.isClass(e)&&t.getElementsByClassName?(e=e.replace(".",""),o(t.getElementsByClassName(e))):o(t.querySelectorAll(e))},o=function(t){try{return Array.prototype.slice.call(namespace.getElementsByTagName(selector))}catch(r){for(var e=[],n=t.length,i=0;i0},isEmpty:function(){return!this.isPresent()},on:function(e,n,i){return this.each(function(r){t.addEvent(r,e,n,i)}),t.boundEvents=t.boundEvents||{},t.boundEvents[e]=t.boundEvents[e]||[],boundElements=t.boundEvents[e],this.each(function(t){-1===boundElements.indexOf(t)&&boundElements.push(t)}),this},throttle:function(t,e,n,i){n=n||1e3;var r=0;return this.on(t,function(t){var i=+new Date;r+n<=i&&(e.apply(this,arguments),r=+new Date),t.preventDefault()},i)},debounce:function(t,e,n,i){n=n||1e3;var r=0;return this.on(t,function(t){clearTimeout(r),r=setTimeout(e.bind(this),n),t.preventDefault()},i)},off:function(e,n){return this.each(function(i){t.removeEvent(i,e,n)}),t.boundEvents=t.boundEvents||{},t.boundEvents[e]=t.boundEvents[e]||[],boundElements=t.boundEvents[e],elementIndex=-1,this.each(function(t){-1!==(elementIndex=boundElements.indexOf(t))&&boundElements.splice(elementIndex,1)}),this},trigger:function(t,e){this.each(function(n){s(n,t,e)})},selectedText:function(){var t=this.els[0],e=this.attr("type"),n=!!e&&e.match("(text|search|password|tel|url)");return document.activeElement!==t?void 0:n&&void 0!==t.selectionStart&&t.selectionEnd>0?t.value.substring(t.selectionStart,t.selectionEnd):window.getSelection?window.getSelection().toString():document.getSelection?document.getSelection().toString():document.selection?document.selection.createRange().text?document.selection.createRange().text:document.selection.createRange().htmlText:void 0},focus:function(){return this.els[0].focus(),this},scrollIntoView:function(t){var t="boolean"==typeof t?t:t||!0;return this.els[0].scrollIntoView(t),this},insertBefore:function(t){"string"==typeof t&&(t=u(r(document,t))),t.each(function(t){if(!t.parentNode)throw Error("Trying to insert element before element without parent");t.insertAdjacentHTML("beforebegin",this.els[0].outerHTML)}.bind(this))},insertAfter:function(t){"string"==typeof t&&(t=u(r(document,t))),t.each(function(t){if(!t.parentNode)throw Error("Trying to insert element after element without parent");t.insertAdjacentHTML("afterend",this.els[0].outerHTML)}.bind(this))}}};return e.broadcast=function(e,n){for(var i=t.boundEvents[e]||[],r=0;r0},isEmpty:function(){return!this.isPresent()},on:function(e,n,i){return this.each(function(r){t.addEvent(r,e,n,i)}),t.boundEvents=t.boundEvents||{},t.boundEvents[e]=t.boundEvents[e]||[],boundElements=t.boundEvents[e],this.each(function(t){-1===boundElements.indexOf(t)&&boundElements.push(t)}),this},throttle:function(t,e,n,i){n=n||1e3;var r=0;return this.on(t,function(t){var i=+new Date;r+n<=i&&(e.apply(this,arguments),r=+new Date),t.preventDefault()},i)},debounce:function(t,e,n,i){n=n||1e3;var r=0;return this.on(t,function(t){clearTimeout(r),r=setTimeout(e.bind(this),n),t.preventDefault()},i)},off:function(e,n){return this.each(function(i){t.removeEvent(i,e,n)}),t.boundEvents=t.boundEvents||{},t.boundEvents[e]=t.boundEvents[e]||[],boundElements=t.boundEvents[e],elementIndex=-1,this.each(function(t){-1!==(elementIndex=boundElements.indexOf(t))&&boundElements.splice(elementIndex,1)}),this},trigger:function(t,e){this.each(function(n){s(n,t,e)})},selectedText:function(){var t=this.els[0],e=this.attr("type"),n=!!e&&e.match("(text|search|password|tel|url)");return document.activeElement!==t?void 0:n&&void 0!==t.selectionStart&&t.selectionEnd>0?t.value.substring(t.selectionStart,t.selectionEnd):window.getSelection?window.getSelection().toString():document.getSelection?document.getSelection().toString():document.selection?document.selection.createRange().text?document.selection.createRange().text:document.selection.createRange().htmlText:void 0},focus:function(){return this.els[0].focus(),this},scrollIntoView:function(t){var t="boolean"==typeof t?t:t||!0;return this.els[0].scrollIntoView(t),this},insertBefore:function(t){"string"==typeof t&&(t=u(r(document,t))),t.each(function(t){if(!t.parentNode)throw Error("Trying to insert element before element without parent");t.insertAdjacentHTML("beforebegin",this.els[0].outerHTML)}.bind(this))},insertAfter:function(t){"string"==typeof t&&(t=u(r(document,t))),t.each(function(t){if(!t.parentNode)throw Error("Trying to insert element after element without parent");t.insertAdjacentHTML("afterend",this.els[0].outerHTML)}.bind(this))}}};return e.broadcast=function(e,n){for(var i=t.boundEvents[e]||[],r=0;r
+
@@ -632,6 +633,33 @@ }, 10); fireEvent($('#debounce-button').first(), 'click'); }); + describe('with shadow DOM', function() { + before(function() { + if (!HTMLElement.prototype.createShadowRoot) { + this.skip(); + } + }); + it("should find elements inside shadow root by tag name", function() { + var $root = $($('#shadow-root-test').first().createShadowRoot()), + div = document.createElement('div'); + $root.append(div); + assert.equal($root.find('div').first(), div); + }); + it("should find elements inside shadow root by id", function() { + var $root = $($('#shadow-root-test').first().createShadowRoot()), + div = document.createElement('div'); + div.id = 'mocha'; + $root.append(div); + assert.equal($root.find('#mocha').first(), div); + }); + it("should find elements inside shadow root by class name", function() { + var $root = $($('#shadow-root-test').first().createShadowRoot()), + div = document.createElement('div'); + div.className = 'search-class-test'; + $root.append(div); + assert.equal($root.find('.search-class-test').first(), div); + }); + }); }); });