Skip to content
Browse files

Fixed isDOMElement check for document.

Fixed demo.
  • Loading branch information...
1 parent cc4d44f commit 6bcede2c19e1f95d7c0e2b319ef8643cc6074b04 @alexlawrence committed Mar 11, 2012
Showing with 22 additions and 17 deletions.
  1. +3 −2 bin/declarative.js
  2. +7 −7 bin/declarative.min.js
  3. +1 −6 demo/demo.html
  4. +8 −0 spec/isDOMElement.spec.js
  5. +3 −2 src/isDOMElement.js
View
5 bin/declarative.js
@@ -64,10 +64,11 @@ var declarative = {};
(function(){
declarative.isDOMElement = function(element) {
- return element && element.nodeType === ELEMENT_NODE;
+ return element &&
+ (element.nodeType === ELEMENT_NODE || element.nodeType === DOCUMENT_NODE);
};
- var ELEMENT_NODE = 1;
+ var ELEMENT_NODE = 1, DOCUMENT_NODE = 9;
}());
(function() {
View
14 bin/declarative.min.js
@@ -8,10 +8,10 @@
*/
(function(a,b){typeof exports==="object"?module.exports=b():typeof define==="function"&&define.amd?define(b):a.declarative=b()})(this,function(){var a={};(function(){a.versionOfInternetExplorer=function(){var a=-1;navigator.appName=="Microsoft Internet Explorer"&&/MSIE ([0-9]{1,}[.0-9]{0,})/.exec(navigator.userAgent)!=null&&(a=parseFloat(RegExp.$1));return a}})();(function(){var b=a.array={};b.ensureArray=function(a){return b.isArray(a)?a:[a]};b.isArray=function(a){return Object.prototype.toString.call(a)===
-"[object Array]"};b.indexOf=function(a,h){for(var b=0,g=a.length;b<g;b++)if(a[b]==h)return b;return-1}})();(function(){a.isDOMElement=function(a){return a&&a.nodeType===b};var b=1})();(function(){var b=a.versionOfInternetExplorer()!=7;a.parseOptions=function(a){try{return f(a)}catch(d){throw Error("declarative.parseOptions: JSON parsing error");}};var n=RegExp(/'/g),h=RegExp(/(^|,)\s*(\w+)\s*:/g),f=b?function(a){a=a.replace(h,'$1"$2":');a=a.replace(n,'"');return JSON.parse("{"+a+"}")}:function(a){eval("var output = {"+
-a+"};");return output}})();(function(){var b=a.isDOMElement;a.getSpecifiedAttributes=function(a){if(!b(a))throw Error("declarative.getSpecifiedAttributes: invalid element (DOM element required)");for(var a=a.attributes,h,f={},g=0,d=a.length;g<d;g++)if(h=a[g],h.specified)f[h.nodeName]=h.nodeValue;return f}})();(function(){var b=a.array.isArray,n=a.array.ensureArray;a.mappings={};var h=a.mappingModes={attribute:"attribute",element:"element"};a.mappings.clear=function(){l={}};a.mappings.add=function(a){for(var a=
-n(a),b=0,e=a.length;b<e;b++){var i=a[b],c=i;c||g("add","invalid options");c.id||g("add","missing id");c.types||g("add","missing types");c.types&&!c.types.push&&g("add","invalid types");(!c.callback||typeof c.callback!=="function")&&g("add","invalid callback");c.mappingMode&&c.mappingMode!==h.attribute&&c.mappingMode!==h.element&&g("add","invalid mappingMode");var j;a:{j=c.id;var f=void 0;for(f in l)if(l.hasOwnProperty(f)&&f==j){j=true;break a}j=false}j&&g("add",'duplicate id "'+c.id+'"');c=i;c.prefix=
-c.prefix||"";c.mappingMode=c.mappingMode||h.attribute;c=i;c.prefix=c.prefix.toLowerCase();c.convertedTypes=[];j=0;for(f=c.types.length;j<f;j++){var p=d(c.types[j]);c.convertedTypes.push(c.prefix+p)}l[i.id]=i}};a.mappings.getAll=function(){var a=[],b;for(b in l)l.hasOwnProperty(b)&&a.push(l[b]);return a};a.mappings.get=function(a){if(!b(a))return f(a);for(var d=[],g=0,e=a.length;g<e;g++)d.push(f(a[g]));return d};var f=function(a){l[a]||g("get",'invalid id "'+a+'"');return l[a]},g=function(a,b){throw Error("declarative.mappings."+
-a+": "+b);},d=function(a){return a.replace(e,function(a,b){return"-"+b.toLowerCase()})},l={},e=RegExp(/([A-Z])/g)})();(function(){var b=a.array.ensureArray,n=a.isDOMElement,h=a.mappingModes;a.apply=function(g){var d=a.mappings.get(g),d=b(d);return{to:function(a){f(d,a)}}};a.applyAll=function(){var b=a.mappings.getAll();return{to:function(a){f(b,a)}}};var f=function(b,d){if(!n(d))throw Error("declarative.apply.to: invalid element (DOM object required)");var f;if(d.querySelectorAll){f=d;var e={};e[h.attribute]=
-[];e[h.element]=[];for(var k=0,m=b.length;k<m;k++){var o=b[k];e[o.mappingMode]=e[o.mappingMode].concat(o.convertedTypes)}(k=e[h.attribute].join("],["))&&(k="["+k+"]");e=e[h.element].join(",");f=f.querySelectorAll(k+(k&&e?",":"")+e)}else f=d.all?d.all:d.getElementsByTagName("*");for(var k=f.length,i,m=0,o=b.length,c=0,j=0;d;){for(m=0;m<o;m++){e=b[m];for(c=0,j=e.convertedTypes.length;c<j;c++){if(e.mappingMode===h.attribute&&(i=d.getAttributeNode&&d.getAttributeNode(e.convertedTypes[c]))&&i.specified)i=
-a.parseOptions(i.nodeValue),e.callback(d,e.types[c],i);e.mappingMode===h.element&&d.nodeName.toLowerCase()==e.convertedTypes[c]&&(i=a.getSpecifiedAttributes(d),e.callback(d,e.types[c],i))}}d=k&&f[--k]}}})();return a});
+"[object Array]"};b.indexOf=function(a,h){for(var b=0,g=a.length;b<g;b++)if(a[b]==h)return b;return-1}})();(function(){a.isDOMElement=function(a){return a&&(a.nodeType===b||a.nodeType===m)};var b=1,m=9})();(function(){var b=a.versionOfInternetExplorer()!=7;a.parseOptions=function(a){try{return f(a)}catch(d){throw Error("declarative.parseOptions: JSON parsing error");}};var m=RegExp(/'/g),h=RegExp(/(^|,)\s*(\w+)\s*:/g),f=b?function(a){a=a.replace(h,'$1"$2":');a=a.replace(m,'"');return JSON.parse("{"+
+a+"}")}:function(a){eval("var output = {"+a+"};");return output}})();(function(){var b=a.isDOMElement;a.getSpecifiedAttributes=function(a){if(!b(a))throw Error("declarative.getSpecifiedAttributes: invalid element (DOM element required)");for(var a=a.attributes,h,f={},g=0,d=a.length;g<d;g++)if(h=a[g],h.specified)f[h.nodeName]=h.nodeValue;return f}})();(function(){var b=a.array.isArray,m=a.array.ensureArray;a.mappings={};var h=a.mappingModes={attribute:"attribute",element:"element"};a.mappings.clear=
+function(){l={}};a.mappings.add=function(a){for(var a=m(a),b=0,e=a.length;b<e;b++){var i=a[b],c=i;c||g("add","invalid options");c.id||g("add","missing id");c.types||g("add","missing types");c.types&&!c.types.push&&g("add","invalid types");(!c.callback||typeof c.callback!=="function")&&g("add","invalid callback");c.mappingMode&&c.mappingMode!==h.attribute&&c.mappingMode!==h.element&&g("add","invalid mappingMode");var j;a:{j=c.id;var f=void 0;for(f in l)if(l.hasOwnProperty(f)&&f==j){j=true;break a}j=
+false}j&&g("add",'duplicate id "'+c.id+'"');c=i;c.prefix=c.prefix||"";c.mappingMode=c.mappingMode||h.attribute;c=i;c.prefix=c.prefix.toLowerCase();c.convertedTypes=[];j=0;for(f=c.types.length;j<f;j++){var p=d(c.types[j]);c.convertedTypes.push(c.prefix+p)}l[i.id]=i}};a.mappings.getAll=function(){var a=[],b;for(b in l)l.hasOwnProperty(b)&&a.push(l[b]);return a};a.mappings.get=function(a){if(!b(a))return f(a);for(var d=[],g=0,e=a.length;g<e;g++)d.push(f(a[g]));return d};var f=function(a){l[a]||g("get",
+'invalid id "'+a+'"');return l[a]},g=function(a,b){throw Error("declarative.mappings."+a+": "+b);},d=function(a){return a.replace(e,function(a,b){return"-"+b.toLowerCase()})},l={},e=RegExp(/([A-Z])/g)})();(function(){var b=a.array.ensureArray,m=a.isDOMElement,h=a.mappingModes;a.apply=function(g){var d=a.mappings.get(g),d=b(d);return{to:function(a){f(d,a)}}};a.applyAll=function(){var b=a.mappings.getAll();return{to:function(a){f(b,a)}}};var f=function(b,d){if(!m(d))throw Error("declarative.apply.to: invalid element (DOM object required)");
+var f;if(d.querySelectorAll){f=d;var e={};e[h.attribute]=[];e[h.element]=[];for(var k=0,n=b.length;k<n;k++){var o=b[k];e[o.mappingMode]=e[o.mappingMode].concat(o.convertedTypes)}(k=e[h.attribute].join("],["))&&(k="["+k+"]");e=e[h.element].join(",");f=f.querySelectorAll(k+(k&&e?",":"")+e)}else f=d.all?d.all:d.getElementsByTagName("*");for(var k=f.length,i,n=0,o=b.length,c=0,j=0;d;){for(n=0;n<o;n++){e=b[n];for(c=0,j=e.convertedTypes.length;c<j;c++){if(e.mappingMode===h.attribute&&(i=d.getAttributeNode&&
+d.getAttributeNode(e.convertedTypes[c]))&&i.specified)i=a.parseOptions(i.nodeValue),e.callback(d,e.types[c],i);e.mappingMode===h.element&&d.nodeName.toLowerCase()==e.convertedTypes[c]&&(i=a.getSpecifiedAttributes(d),e.callback(d,e.types[c],i))}}d=k&&f[--k]}}})();return a});
View
7 demo/demo.html
@@ -6,12 +6,7 @@
<script type="text/javascript" src="../vendor/jquery-1.7.js"></script>
- <script type="text/javascript" src="../src/declarative.js"></script>
- <script type="text/javascript" src="../src/versionOfInternetExplorer.js"></script>
- <script type="text/javascript" src="../src/array.js"></script>
- <script type="text/javascript" src="../src/parseOptions.js"></script>
- <script type="text/javascript" src="../src/mappings.js"></script>
- <script type="text/javascript" src="../src/apply.js"></script>
+ <script type="text/javascript" src="../bin/declarative.js"></script>
</head>
<body>
View
8 spec/isDOMElement.spec.js
@@ -46,4 +46,12 @@ describe('declarative.isDOMElement', function() {
});
+ it('should return true if given the document element', function() {
+
+ var result = testMethod(document);
+
+ expect(result).toBeTruthy();
+
+ });
+
});
View
5 src/isDOMElement.js
@@ -1,9 +1,10 @@
(function(){
declarative.isDOMElement = function(element) {
- return element && element.nodeType === ELEMENT_NODE;
+ return element &&
+ (element.nodeType === ELEMENT_NODE || element.nodeType === DOCUMENT_NODE);
};
- var ELEMENT_NODE = 1;
+ var ELEMENT_NODE = 1, DOCUMENT_NODE = 9;
}());

0 comments on commit 6bcede2

Please sign in to comment.
Something went wrong with that request. Please try again.