Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update shim due of last Microdata specification

+ Fix for old Opera implementation
* some refactoring and bugfixing
  • Loading branch information...
commit 0f6b610834e35ba817b935dc259ff67a35d92fe0 1 parent cb2111f
@termi authored
View
26 __COMPILE/microdata-js.js
@@ -1,13 +1,13 @@
-(function(n,e){"use strict";var h=!0,k=null;function m(a){for(var b=$$("[itemscope]",this),f=[],a=(a||"").trim().split(/\s+/),c,e=-1;c=b[++e];){var d=c.getAttribute("itemtype")||"",p=d.split(/\s+/),o,d=!(d&&!c.getAttribute("itemprop")&&(!("itemScope"in c)||c.itemScope));for(;!d&&(o=p.pop());)(d=~a.indexOf(o))&&f.push(c)}return f}function f(a,b){a._||(a._={});var c=a.getAttribute(b),f=a._._mcrdt_||(a._._mcrdt_={}),d=f[b];d?c!==k&&d+""!==c&&d.update(c):d=f[b]=new g(c,function(){a.setAttribute(b,this+"")});return d}var g=n.Utils.Dom.DOMStringCollection,
-j="INPUT,TEXTAREA,PROGRESS,METER,SELECT,OUTPUT".split(","),i="AUDIO,EMBED,IFRAME,IMG,SOURCE,TRACK,VIDEO".split(","),b=["A","AREA","LINK"],c={get:function(){var a=this.nodeName;return this.getAttribute("itemscope")!==k?this:this.getAttribute("itemprop")===k?k:~j.indexOf(a)?this.value:"META"===a?this.content:~i.indexOf(a)?this.src:~b.indexOf(a)?this.href:"OBJECT"===a?this.data:"TIME"===a&&this.getAttribute("datetime")?this.dateTime:"textContent"in this?this.textContent:this.innerText},set:function(a){var c=
-this.nodeName;if(this.getAttribute("itemprop")===k)throw a=Object.create(DOMException.prototype),a.code=DOMException.INVALID_ACCESS_ERR,a.message="INVALID_ACCESS_ERR: DOM Exception "+a.code,a;return this[~j.indexOf(c)?"value":"META"===c?"content":~i.indexOf(c)?"src":~b.indexOf(c)?"href":"OBJECT"===c?"data":"TIME"===c&&this.getAttribute("datetime")?"dateTime":"innerHTML"]=a}},d={get:function(){return f(this,"itemtype")},set:function(a){return this.setAttribute("itemtype",a+"")}};e.c=c;e.b=d;e.e=j;
-e.a=m;(!document.getItems?function(a){if(!a.PropertyNodeList){var b=a.PropertyNodeList=function(){this.length=0;this.values=[]};b.prototype._push=function(a,b){this[this.length++]=a;this.values.push(b)};b.prototype.namedItem=function(){};b.prototype.values=void 0;b.prototype.getValues=function(){for(var a=[],b=-1,c;c=this[++b];)a.push(c.itemValue);return this.values=a};b.prototype.toString=function(){return"[object PropertyNodeList]"}}if(!a.HTMLPropertiesCollection){var g=a.HTMLPropertiesCollection=
-function(){this.length=0;this.names=[]};g.prototype.d=function(){for(var a in this)this[a]instanceof b&&(this[a]=k,delete this[a]);this.length=0;this.names=[]};g.prototype._push=function(a,c,d){this[this.length++]=a;~this.names.indexOf(d)||this.names.push(d);(this[d]||(this[d]=new b))._push(a,c)};g.prototype.namedItem=function(a){return this[a]instanceof b?this[a]:new b};g.prototype.toString=function(){return"[object HTMLPropertiesCollection]"};g.prototype.item=b.prototype.item=function(a){isNaN(a)&&
-(a=0);return this[a]||k}}var j=a.HTMLElement&&a.HTMLElement.prototype||a.Element&&a.Element.prototype;j&&Object.defineProperties(j,{itemValue:c,itemProp:{get:function(){return f(this,"itemprop")},set:function(a){return this.setAttribute("itemprop",a)}},itemScope:{get:function(){return this.getAttribute("itemscope")!==k},set:function(a){a?this.setAttribute("itemscope",""):this.removeAttribute("itemscope");return a}},itemId:{get:function(){var a=(this.getAttribute("itemid")||"").trim();a&&!/\w+:(\/\/)?[\w][\w.\/]*/.test(a)&&
-(a=location.href.replace(/\/[^\/]*$/,"/"+escape(a)));return a},set:function(a){return this.setAttribute("itemid",a+"")}},itemType:d,itemRef:{get:function(){return f(this,"itemref")},set:function(a){return this.setAttribute("itemref",a+"")}},properties:{get:function(){this._||(this._={});var b=this._._mcrdt_||(this._._mcrdt_={}),c=b.f;if(c)if(a.microdata_liveProperties)c.d();else return c;else c=b.f=new g;for(var d=[],b=[],f=[],e,j=-1,i;i=this.childNodes[++j];)1===i.nodeType&&d.push(i);this.getAttribute("itemref")&&
-(f=this.getAttribute("itemref").trim().split(/\s+/),f.forEach(function(a){(a=document.getElementById(a))&&d.push(a)}));d=d.filter(function(a,b){var c=k,e=a,g=[];if(d.indexOf(a)!==b&&-1!==d.indexOf(a,b))return!1;if(a.id&&-1!==f.indexOf(a.id))return h;for(;(e=e.parentNode)!==k&&1===e.nodeType;)if(g.push(e),e.getAttribute("itemscope")!==k){c=e;break}return c!==k?-1!==d.indexOf(c)?!1:!g.some(function(a){var b=-1,e=k;if(-1!==(b=d.indexOf(a))){for(a=d[b];(a=a.parentNode)!==k&&1===a.nodeType;)if(a.getAttribute("itemscope")!==
-k){e=a;break}if(e===c)return h}return!1}):h});for(d.sort(function(a,b){return 3-(b.compareDocumentPosition(a)&6)});e=d.pop();)if(e.getAttribute("itemprop")&&b.push(e),e.getAttribute("itemscope")===k)for(j=e.childNodes.length;i=e.childNodes[--j];)1===i.nodeType&&d.push(i);b.forEach(function(a){j=-1;for(e=a.itemProp;i=e[++j];)c._push(a,a.itemValue,i)});return c}}});try{var i=document.createElement("EMBED");i.itemProp="t";i.itemValue+="1"}catch(n){}document.getItems=m;e(a)}:e)(n)})(window,function l(e){function m(b){var c,
-d=-1,a;if(void 0!==b.length){for(c={items:[]};a=b[++d];)a.getAttribute("itemscope")!==k&&c.items.push(m(a));return c}if(b.getAttribute("itemscope")!==k){c={};if(d=b.getAttribute("itemid"))c.id=d;if(d=b.getAttribute("itemtype"))c.type=d;c.properties=b.properties.toJSON()}return c}if(!e.__prot_fix__isfixed){var f,g=document.createElement("input");g.itemProp="";g.itemScope=h;g.itemType="t";"string"==typeof g.itemType&&(Object.defineProperty(e.Node.prototype,"itemType",l.b),HTMLDocument.prototype.getItems=
-l.a);if(f=e.PropertyNodeList){var j=e.PropertyNodeList;if(!(f=j.prototype).toJSON)f.toJSON=function(){for(var b=[],c=this.h(),d=-1,a;(a=c[++d])!=k;)a instanceof Element&&(a=m(a)),b.push(a);return b};g.itemProp="t";g.value="1";g.value!=g.itemValue&&(l.e.forEach(function(b){b="TEXTAREA"==b?"TextArea":b.charAt(0).toUpperCase()+b.substring(1).toLowerCase();b=e["HTML"+b+"Element"];(b=b.prototype)&&Object.defineProperty(b,"itemValue",l.c)}),f.getValues=function(){for(var b=[],c=-1,d;d=this[++c];)b.push(d.itemValue);
-return b});"values"in f||f.__defineGetter__("values",f.getValues);f=e.HTMLPropertiesCollection;if(!(f=f.prototype).toJSON)f.toJSON=function(){for(var b={},c=this.names,d=-1,a;a=c[++d];)this[a]instanceof j&&(b[a]=this[a].toJSON());return b};l.i=h}else{var i=HTMLDocument.prototype.getItems;HTMLDocument.prototype.getItems=function(){var b=document.createElement("div");b.innerHTML="<p itemprop='t'>1</p>";b.itemScope=h;b.properties.t[0].innerHTML="2";l(this.defaultView||e);return(this.getItems=i).apply(document,
-arguments)}}if(!l.g){if((f=e.DocumentFragment)&&(f=f.prototype))f.getItems||(f.getItems=document.getItems);l.g=h}}});
+(function(o,f){"use strict";var g=!0,j=null;function n(a){for(var c=this.querySelectorAll("[itemscope]"),e=[],a=(a||"").trim().split(/\s+/),d,k=-1;d=c[++k];){var b=d.getAttribute("itemtype")||"",q=b.split(/\s+/),p,b=!(b&&!d.getAttribute("itemprop")&&(!("itemScope"in d)||d.itemScope));for(;!b&&(p=q.pop());)(b=~a.indexOf(p))&&e.push(d)}return e}function d(a,c){a._||(a._={});var e=a.getAttribute(c),d=a._._mcrdt_||(a._._mcrdt_={}),b=d[c];b?e!==j&&b+""!==e&&b.update(e):b=d[c]=new i(e,function(){a.setAttribute(c,this+"")});return b}
+var i=o.Utils.Dom.DOMStringCollection,b="INPUT,TEXTAREA,PROGRESS,METER,SELECT,OUTPUT".split(","),h="AUDIO,EMBED,IFRAME,IMG,SOURCE,TRACK,VIDEO".split(","),m=["A","AREA","LINK"],e={get:function(){var a=this.nodeName;return this.getAttribute("itemscope")!==j?this:this.getAttribute("itemprop")===j?j:~b.indexOf(a)?this.value:"META"===a?this.content:~h.indexOf(a)?this.src:~m.indexOf(a)?this.href:"OBJECT"===a?this.data:"TIME"===a&&this.getAttribute("datetime")?this.dateTime:"textContent"in this?this.textContent:
+this.innerText},set:function(a){var c=this.nodeName;if(this.getAttribute("itemprop")===j)throw a=Object.create(DOMException.prototype),a.code=DOMException.INVALID_ACCESS_ERR,a.message="INVALID_ACCESS_ERR: DOM Exception "+a.code,a;return this[~b.indexOf(c)?"value":"META"===c?"content":~h.indexOf(c)?"src":~m.indexOf(c)?"href":"OBJECT"===c?"data":"TIME"===c&&this.getAttribute("datetime")?"dateTime":"innerHTML"]=a}},k={get:function(){return d(this,"itemtype")},set:function(a){return this.setAttribute("itemtype",
+a+"")}};f.c=e;f.b=k;f.e=b;f.a=n;(!document.getItems?function(a){if(!a.PropertyNodeList){var c=a.PropertyNodeList=function(){this.length=0;this.values=[]};c.prototype._push=function(a,c){this[this.length++]=a;this.values.push(c)};c.prototype.namedItem=function(){};c.prototype.values=void 0;c.prototype.getValues=function(){for(var a=[],c=-1,e;e=this[++c];)a.push(e.itemValue);return this.values=a};c.prototype.toString=function(){return"[object PropertyNodeList]"}}if(!a.HTMLPropertiesCollection){var b=
+a.HTMLPropertiesCollection=function(){this.length=0;this.names=[]};b.prototype.d=function(){for(var a in this)this[a]instanceof c&&(this[a]=j,delete this[a]);this.length=0;this.names=[]};b.prototype._push=function(a,e,b){this[this.length++]=a;~this.names.indexOf(b)||this.names.push(b);(this[b]||(this[b]=new c))._push(a,e)};b.prototype.namedItem=function(a){return this[a]instanceof c?this[a]:new c};b.prototype.toString=function(){return"[object HTMLPropertiesCollection]"};b.prototype.item=c.prototype.item=
+function(a){isNaN(a)&&(a=0);return this[a]||j}}var i=a.HTMLElement&&a.HTMLElement.prototype||a.Element&&a.Element.prototype;i&&Object.defineProperties(i,{itemValue:e,itemProp:{get:function(){return d(this,"itemprop")},set:function(a){return this.setAttribute("itemprop",a)}},itemScope:{get:function(){return this.getAttribute("itemscope")!==j},set:function(a){a?this.setAttribute("itemscope",""):this.removeAttribute("itemscope");return a}},itemId:{get:function(){var a=(this.getAttribute("itemid")||"").trim();
+a&&!/\w+:(\/\/)?[\w][\w.\/]*/.test(a)&&(a=location.href.replace(/\/[^\/]*$/,"/"+escape(a)));return a},set:function(a){return this.setAttribute("itemid",a+"")}},itemType:k,itemRef:{get:function(){return d(this,"itemref")},set:function(a){return this.setAttribute("itemref",a+"")}},properties:{get:function(){this._||(this._={});var c=this._._mcrdt_||(this._._mcrdt_={}),e=c.f;if(e)if(a.microdata_liveProperties)e.d();else return e;else e=c.f=new b;for(var d=[],c=[],k=[],f,i=-1,h;h=this.childNodes[++i];)1===
+h.nodeType&&d.push(h);this.getAttribute("itemref")&&(k=this.getAttribute("itemref").trim().split(/\s+/),k.forEach(function(a){(a=document.getElementById(a))&&d.push(a)}));d=d.filter(function(a,c){var e=j,b=a,f=[];if(d.indexOf(a)!==c&&d.indexOf(a,c)!==-1)return false;if(a.id&&k.indexOf(a.id)!==-1)return g;for(;(b=b.parentNode)!==j&&b.nodeType===1;){f.push(b);if(b.getAttribute("itemscope")!==j){e=b;break}}return e!==j?d.indexOf(e)!==-1?false:!f.some(function(a){var c=-1,b=j;if((c=d.indexOf(a))!==-1){for(a=
+d[c];(a=a.parentNode)!==j&&a.nodeType===1;)if(a.getAttribute("itemscope")!==j){b=a;break}if(b===e)return g}return false}):g});for(d.sort(function(a,c){return 3-(c.compareDocumentPosition(a)&6)});f=d.pop();)if(f.getAttribute("itemprop")&&c.push(f),f.getAttribute("itemscope")===j)for(i=f.childNodes.length;h=f.childNodes[--i];)1===h.nodeType&&d.push(h);c.forEach(function(a){i=-1;for(f=a.itemProp;h=f[++i];)e._push(a,a.itemValue,h)});return e}}});try{var h=document.createElement("EMBED");h.itemProp="t";
+h.itemValue+="1"}catch(m){}document.getItems=n;f(a)}:f)(o)})(window,function l(f){function n(e){var b,a=-1,c;if(void 0!==e.length){for(b={items:[]};c=e[++a];)c.getAttribute("itemscope")!==j&&b.items.push(n(c));return b}if(e.getAttribute("itemscope")!==j){b={};if(a=e.getAttribute("itemid"))b.id=a;if(a=e.getAttribute("itemtype"))b.type=a;b.properties=e.properties.toJSON()}return b}if(!l.h){var d,i=document.createElement("div"),b=HTMLDocument.prototype;b.getItems!=l.a&&(i.itemScope=g,i.itemType="t",
+"string"==typeof i.itemType&&(Object.defineProperty(f.Node.prototype,"itemType",l.b),b.getItems=l.a));if(d=f.PropertyNodeList){var h=f.PropertyNodeList;if(!(d=h.prototype).toJSON)d.toJSON=function(){for(var b=[],d=this.i(),a=-1,c;(c=d[++a])!=j;){c instanceof Element&&(c=n(c));b.push(c)}return b};b=document.createElement("input");b.itemProp="t";b.itemScope=!1;b.value="1";b.value!=b.itemValue&&(l.e.forEach(function(b){b=b=="TEXTAREA"?"TextArea":b.charAt(0).toUpperCase()+b.substring(1).toLowerCase();
+b=f["HTML"+b+"Element"];(b=b.prototype)&&Object.defineProperty(b,"itemValue",l.c)}),d.getValues=function(){for(var b=[],d=-1,a;a=this[++d];)b.push(a.itemValue);return b});"values"in d||d.__defineGetter__("values",d.getValues);d=f.HTMLPropertiesCollection;if(!(d=d.prototype).toJSON)d.toJSON=function(){for(var b={},d=this.names,a=-1,c;c=d[++a];)this[c]instanceof h&&(b[c]=this[c].toJSON());return b};l.h=g}else if(!b.getItems.orig){var m=b.getItems;b.getItems=function(){i.innerHTML="<p itemprop='t'>t</p>";
+i.properties.t[0].innerHTML="t";l(this.defaultView||f);return(this.getItems=m).apply(document,arguments)};b.getItems.orig=m}}if(!l.g){if((d=f.DocumentFragment)&&(d=d.prototype))d.getItems||(d.getItems=document.getItems);l.g=g}});
View
18 __COMPILE/microdata-js.noextras.js
@@ -1,9 +1,9 @@
-(function(m){"use strict";var f=null;function q(a){for(var b=$$("[itemscope]",this),c=[],a=(a||"").trim().split(/\s+/),d,h=-1;d=b[++h];){var i=d.getAttribute("itemtype")||"",g=i.split(/\s+/),n,i=!(i&&!d.getAttribute("itemprop")&&(!("itemScope"in d)||d.itemScope));for(;!i&&(n=g.pop());)(i=~a.indexOf(n))&&c.push(d)}return c}function l(a,b){a._||(a._={});var c=a.getAttribute(b),d=a._._mcrdt_||(a._._mcrdt_={}),h=d[b];h?c!==f&&h+""!==c&&h.update(c):h=d[b]=new r(c,function(){a.setAttribute(b,this+"")});return h}var r=m.Utils.Dom.DOMStringCollection,
-o="AUDIO,EMBED,IFRAME,IMG,SOURCE,TRACK,VIDEO".split(","),p=["A","AREA","LINK"],s={get:function(){var a=this.nodeName;return this.getAttribute("itemscope")!==f?this:this.getAttribute("itemprop")===f?f:"META"===a?this.content:~o.indexOf(a)?this.src:~p.indexOf(a)?this.href:"OBJECT"===a?this.data:"TIME"===a&&this.getAttribute("datetime")?this.dateTime:"textContent"in this?this.textContent:this.innerText},set:function(a){var b=this.nodeName;if(this.getAttribute("itemprop")===f)throw a=Object.create(DOMException.prototype),
-a.code=DOMException.INVALID_ACCESS_ERR,a.message="INVALID_ACCESS_ERR: DOM Exception "+a.code,a;return this["META"===b?"content":~o.indexOf(b)?"src":~p.indexOf(b)?"href":"OBJECT"===b?"data":"TIME"===b&&this.getAttribute("datetime")?"dateTime":"innerHTML"]=a}},t={get:function(){return l(this,"itemtype")},set:function(a){return this.setAttribute("itemtype",a+"")}};(!document.getItems?function(a){if(!a.PropertyNodeList){var b=a.PropertyNodeList=function(){this.length=0;this.values=[]};b.prototype._push=
-function(g,a){this[this.length++]=g;this.values.push(a)};b.prototype.namedItem=function(){};b.prototype.values=void 0;b.prototype.getValues=function(){for(var g=[],a=-1,b;b=this[++a];)g.push(b.itemValue);return this.values=g};b.prototype.toString=function(){return"[object PropertyNodeList]"}}if(!a.HTMLPropertiesCollection){var c=a.HTMLPropertiesCollection=function(){this.length=0;this.names=[]};c.prototype.a=function(){for(var g in this)this[g]instanceof b&&(this[g]=f,delete this[g]);this.length=
-0;this.names=[]};c.prototype._push=function(g,a,e){this[this.length++]=g;~this.names.indexOf(e)||this.names.push(e);(this[e]||(this[e]=new b))._push(g,a)};c.prototype.namedItem=function(a){return this[a]instanceof b?this[a]:new b};c.prototype.toString=function(){return"[object HTMLPropertiesCollection]"};c.prototype.item=b.prototype.item=function(a){isNaN(a)&&(a=0);return this[a]||f}}var d=a.HTMLElement&&a.HTMLElement.prototype||a.Element&&a.Element.prototype;d&&Object.defineProperties(d,{itemValue:s,
-itemProp:{get:function(){return l(this,"itemprop")},set:function(a){return this.setAttribute("itemprop",a)}},itemScope:{get:function(){return this.getAttribute("itemscope")!==f},set:function(a){a?this.setAttribute("itemscope",""):this.removeAttribute("itemscope");return a}},itemId:{get:function(){var a=(this.getAttribute("itemid")||"").trim();a&&!/\w+:(\/\/)?[\w][\w.\/]*/.test(a)&&(a=location.href.replace(/\/[^\/]*$/,"/"+escape(a)));return a},set:function(a){return this.setAttribute("itemid",a+"")}},
-itemType:t,itemRef:{get:function(){return l(this,"itemref")},set:function(a){return this.setAttribute("itemref",a+"")}},properties:{get:function(){this._||(this._={});var b=this._._mcrdt_||(this._._mcrdt_={}),d=b.b;if(d)if(a.microdata_liveProperties)d.a();else return d;else d=b.b=new c;for(var e=[],b=[],h=[],j,i=-1,k;k=this.childNodes[++i];)1===k.nodeType&&e.push(k);this.getAttribute("itemref")&&(h=this.getAttribute("itemref").trim().split(/\s+/),h.forEach(function(a){(a=document.getElementById(a))&&
-e.push(a)}));e=e.filter(function(a,b){var d=f,c=a,g=[];if(e.indexOf(a)!==b&&-1!==e.indexOf(a,b))return!1;if(a.id&&-1!==h.indexOf(a.id))return!0;for(;(c=c.parentNode)!==f&&1===c.nodeType;)if(g.push(c),c.getAttribute("itemscope")!==f){d=c;break}return d!==f?-1!==e.indexOf(d)?!1:!g.some(function(a){var b=-1,c=f;if(-1!==(b=e.indexOf(a))){for(a=e[b];(a=a.parentNode)!==f&&1===a.nodeType;)if(a.getAttribute("itemscope")!==f){c=a;break}if(c===d)return!0}return!1}):!0});for(e.sort(function(a,b){return 3-(b.compareDocumentPosition(a)&
-6)});j=e.pop();)if(j.getAttribute("itemprop")&&b.push(j),j.getAttribute("itemscope")===f)for(i=j.childNodes.length;k=j.childNodes[--i];)1===k.nodeType&&e.push(k);b.forEach(function(a){i=-1;for(j=a.itemProp;k=j[++i];)d._push(a,a.itemValue,k)});return d}}});try{var h=document.createElement("EMBED");h.itemProp="t";h.itemValue+="1"}catch(i){}document.getItems=q}:!1)(m)})(window,!1);
+(function(m){"use strict";var f=null;function q(a){for(var b=this.querySelectorAll("[itemscope]"),c=[],a=(a||"").trim().split(/\s+/),d,h=-1;d=b[++h];){var i=d.getAttribute("itemtype")||"",g=i.split(/\s+/),n,i=!(i&&!d.getAttribute("itemprop")&&(!("itemScope"in d)||d.itemScope));for(;!i&&(n=g.pop());)(i=~a.indexOf(n))&&c.push(d)}return c}function l(a,b){a._||(a._={});var c=a.getAttribute(b),d=a._._mcrdt_||(a._._mcrdt_={}),h=d[b];h?c!==f&&h+""!==c&&h.update(c):h=d[b]=new r(c,function(){a.setAttribute(b,this+"")});return h}
+var r=m.Utils.Dom.DOMStringCollection,o="AUDIO,EMBED,IFRAME,IMG,SOURCE,TRACK,VIDEO".split(","),p=["A","AREA","LINK"],s={get:function(){var a=this.nodeName;return this.getAttribute("itemscope")!==f?this:this.getAttribute("itemprop")===f?f:"META"===a?this.content:~o.indexOf(a)?this.src:~p.indexOf(a)?this.href:"OBJECT"===a?this.data:"TIME"===a&&this.getAttribute("datetime")?this.dateTime:"textContent"in this?this.textContent:this.innerText},set:function(a){var b=this.nodeName;if(this.getAttribute("itemprop")===
+f)throw a=Object.create(DOMException.prototype),a.code=DOMException.INVALID_ACCESS_ERR,a.message="INVALID_ACCESS_ERR: DOM Exception "+a.code,a;return this["META"===b?"content":~o.indexOf(b)?"src":~p.indexOf(b)?"href":"OBJECT"===b?"data":"TIME"===b&&this.getAttribute("datetime")?"dateTime":"innerHTML"]=a}},t={get:function(){return l(this,"itemtype")},set:function(a){return this.setAttribute("itemtype",a+"")}};(!document.getItems?function(a){if(!a.PropertyNodeList){var b=a.PropertyNodeList=function(){this.length=
+0;this.values=[]};b.prototype._push=function(g,a){this[this.length++]=g;this.values.push(a)};b.prototype.namedItem=function(){};b.prototype.values=void 0;b.prototype.getValues=function(){for(var g=[],a=-1,b;b=this[++a];)g.push(b.itemValue);return this.values=g};b.prototype.toString=function(){return"[object PropertyNodeList]"}}if(!a.HTMLPropertiesCollection){var c=a.HTMLPropertiesCollection=function(){this.length=0;this.names=[]};c.prototype.a=function(){for(var g in this)this[g]instanceof b&&(this[g]=
+f,delete this[g]);this.length=0;this.names=[]};c.prototype._push=function(g,a,e){this[this.length++]=g;~this.names.indexOf(e)||this.names.push(e);(this[e]||(this[e]=new b))._push(g,a)};c.prototype.namedItem=function(a){return this[a]instanceof b?this[a]:new b};c.prototype.toString=function(){return"[object HTMLPropertiesCollection]"};c.prototype.item=b.prototype.item=function(a){isNaN(a)&&(a=0);return this[a]||f}}var d=a.HTMLElement&&a.HTMLElement.prototype||a.Element&&a.Element.prototype;d&&Object.defineProperties(d,
+{itemValue:s,itemProp:{get:function(){return l(this,"itemprop")},set:function(a){return this.setAttribute("itemprop",a)}},itemScope:{get:function(){return this.getAttribute("itemscope")!==f},set:function(a){a?this.setAttribute("itemscope",""):this.removeAttribute("itemscope");return a}},itemId:{get:function(){var a=(this.getAttribute("itemid")||"").trim();a&&!/\w+:(\/\/)?[\w][\w.\/]*/.test(a)&&(a=location.href.replace(/\/[^\/]*$/,"/"+escape(a)));return a},set:function(a){return this.setAttribute("itemid",
+a+"")}},itemType:t,itemRef:{get:function(){return l(this,"itemref")},set:function(a){return this.setAttribute("itemref",a+"")}},properties:{get:function(){this._||(this._={});var b=this._._mcrdt_||(this._._mcrdt_={}),d=b.b;if(d)if(a.microdata_liveProperties)d.a();else return d;else d=b.b=new c;for(var e=[],b=[],h=[],j,i=-1,k;k=this.childNodes[++i];)1===k.nodeType&&e.push(k);this.getAttribute("itemref")&&(h=this.getAttribute("itemref").trim().split(/\s+/),h.forEach(function(a){(a=document.getElementById(a))&&
+e.push(a)}));e=e.filter(function(a,b){var d=f,c=a,g=[];if(e.indexOf(a)!==b&&e.indexOf(a,b)!==-1)return false;if(a.id&&h.indexOf(a.id)!==-1)return true;for(;(c=c.parentNode)!==f&&c.nodeType===1;){g.push(c);if(c.getAttribute("itemscope")!==f){d=c;break}}return d!==f?e.indexOf(d)!==-1?false:!g.some(function(a){var b=-1,c=f;if((b=e.indexOf(a))!==-1){for(a=e[b];(a=a.parentNode)!==f&&a.nodeType===1;)if(a.getAttribute("itemscope")!==f){c=a;break}if(c===d)return true}return false}):true});for(e.sort(function(a,
+b){return 3-(b.compareDocumentPosition(a)&6)});j=e.pop();)if(j.getAttribute("itemprop")&&b.push(j),j.getAttribute("itemscope")===f)for(i=j.childNodes.length;k=j.childNodes[--i];)1===k.nodeType&&e.push(k);b.forEach(function(a){i=-1;for(j=a.itemProp;k=j[++i];)d._push(a,a.itemValue,k)});return d}}});try{var h=document.createElement("EMBED");h.itemProp="t";h.itemValue+="1"}catch(i){}document.getItems=q}:!1)(m)})(window,!1);
View
230 __SRC/microdata-js.js
@@ -16,7 +16,7 @@
* 2. https://github.com/Treesaver/treesaver/blob/2180bb01e3cdb87811d1bd26bc81af020c1392bd/src/lib/microdata.js
* 3. http://www.w3.org/TR/html5/microdata.html
*
- * @version 4
+ * @version 5
*
* @required:
* 1. Utils.Dom.DOMStringCollection (DOMSettableTokenList like object)
@@ -108,7 +108,7 @@ var _formElements = ['INPUT', 'TEXTAREA', 'PROGRESS', 'METER', 'SELECT', 'OUTPUT
__getItems__ = function(itemTypes) {
var items =
//Не работает в ie6!!! (browser.msie && browser.msie < 8) ? $$(".__ielt8_css_class_itemscope__", this) ://Only for IE < 8 for increase performance //requared microdata-js.ielt8.htc
- $$("[itemscope]", this),
+ this.querySelectorAll("[itemscope]"),
matches = [],
_itemTypes = (itemTypes || "").trim().split(/\s+/),
node,
@@ -172,18 +172,6 @@ if(INCLUDE_EXTRAS) {
thisObj["values"].push(prop_value)
}
/**
- * @param {string} p_name property name
- * @return {PropertyNodeList}
- */
- PropertyNodeList.prototype["namedItem"] = function(p_name) {
- //TODO:: Still don't know what code here
- }
- /**
- * @type {undefined}
- * For compliance with real PropertyNodeList.prototype
- */
- PropertyNodeList.prototype["values"] = void 0;
- /**
* @return {Array}
*/
PropertyNodeList.prototype["getValues"] = function() {
@@ -192,7 +180,7 @@ if(INCLUDE_EXTRAS) {
while(el = this[++k])
_value.push(el["itemValue"]);
- return this["values"] = _value;//Update `values`
+ return _value;//Update `values`
}
/**
* @return {string}
@@ -286,10 +274,7 @@ if(INCLUDE_EXTRAS) {
// ------- Extending Element.prototype ---------- //
// For IE < 8 support use microdata-js.ielt8.js and microdata-js.ielt8.htc
-
- // Definition IF < 8 support
- var _HTMLElement_prototype = (global["HTMLElement"] && global["HTMLElement"].prototype || /*ie8*/global["Element"] && global["Element"].prototype);
- if(_HTMLElement_prototype)Object.defineProperties(_HTMLElement_prototype, {
+ Object.defineProperties(global["Node"].prototype, {
"itemValue" : __itemValueProperty,
"itemProp" : {
"get" : function() {
@@ -306,8 +291,6 @@ if(INCLUDE_EXTRAS) {
"set" : function(val) {
val ? this.setAttribute("itemscope", "") : this.removeAttribute("itemscope");
- //val === true && MicrodataJS.fixItemElement(this);
-
return val;
}
},
@@ -463,14 +446,6 @@ if(INCLUDE_EXTRAS) {
}
});
- //[BUG] Prevent bug in Google Chrome:: setter do not fire on first created EMBED element
- try {
- var EMBED = document.createElement("EMBED");
- EMBED["itemProp"] = "t";
- EMBED["itemValue"] = EMBED["itemValue"] + "1";
- }
- catch(e) {}
-
/**
* Gets all of the elements that have an itemType
* @param {string} itemTypes - whitespace-separated string of types to match
@@ -493,9 +468,7 @@ if(INCLUDE_EXTRAS) {
* @param {Window} global
*/
INCLUDE_EXTRAS && function fixPrototypes(global) {
- //if(fixPrototypes.isfixed)return;
- if(global["__prot_fix__isfixed"])return;
-
+
/* too difficult
//Adding toJSON function
if(!fixPrototypes.new_getItems) {
@@ -544,113 +517,118 @@ if(INCLUDE_EXTRAS) {
return result;
}
- var _a,
- test_input = document.createElement("input");
-
- //Fix old Opera Microdata.itemtype implimentation
- test_input["itemProp"] = "";
- test_input["itemScope"] = true;
- test_input["itemType"] = "t";
- if(typeof test_input["itemType"] == "string") {
- Object.defineProperty(global["Node"].prototype, "itemType", fixPrototypes.__itemTypeProperty);
- HTMLDocument.prototype["getItems"] = fixPrototypes.__getItems__;
- }
-
- if(!(_a = global["PropertyNodeList"])) {
- //Strange behavior in Opera 12 - HTMLPropertiesCollection and PropertyNodeList constructors available only when it realy need - when <el>.property and <el>.property[<prop_name>]
- // http://jsfiddle.net/EVmfh/
+ if(!fixPrototypes.isfixed) {
+ var _a,
+ test_div = document.createElement("div"),
+ HTMLDocument_prototype = HTMLDocument.prototype;
- var orig = HTMLDocument.prototype["getItems"];
- /**
- * @this {(HTMLDocument|DocumentFragment)}
- */
- HTMLDocument.prototype["getItems"] = function() {
- var test_div = document.createElement("div");
- test_div.innerHTML = "<p itemprop='t'>1</p>";
+ //[BUGFIX] Prevent bug in Google Chrome:: setter do not fire on first created EMBED element
+ try {
+ var EMBED = document.createElement("EMBED");
+ EMBED["itemProp"] = "t";
+ EMBED["itemValue"] = EMBED["itemValue"] + "1";
+ }
+ catch(e) {}
+
+ //[BUGFIX] Fix old Opera Microdata.itemtype implimentation
+ if(HTMLDocument_prototype["getItems"] != fixPrototypes.__getItems__) {
test_div["itemScope"] = true;
- test_div["properties"]["t"][0].innerHTML = "2";
-
- //DEBUG::
- //console.log((this.defaultView || global).location.href)
-
- //If 'this' is not DocumentFragment, and 'this' is a docuemnt in iFrame defaultView would be exsist
- fixPrototypes(this.defaultView || global);//Extend prototype's
-
- return (this["getItems"] = orig).apply(document, arguments)
+ test_div["itemType"] = "t";
+ if(typeof test_div["itemType"] == "string") {
+ Object.defineProperty(global["Node"].prototype, "itemType", fixPrototypes.__itemTypeProperty);
+ HTMLDocument_prototype["getItems"] = fixPrototypes.__getItems__;//replace wrong implimentation
+ }
}
- }
- else {
- var _PropertyNodeList = global["PropertyNodeList"];
- if(!(_a = _PropertyNodeList.prototype).toJSON)_a.toJSON =
- /**
- * @this {PropertyNodeList}
- * @return {Object} json
- */
- function() {
- var thisObj = this,
- result = [],
- values = thisObj.getValues(),
- i = -1,
- cur;
-
- while((cur = values[++i]) != null) {
- if(cur instanceof Element) {
- cur = itemToJSON(cur);//if cur is not Microdata element return undefined
+
+ if(!(_a = global["PropertyNodeList"])) {
+ //Strange behavior in Opera 12 - HTMLPropertiesCollection and PropertyNodeList constructors available only when it realy need - when <el>.property and <el>.property[<prop_name>]
+ // http://jsfiddle.net/EVmfh/
+ if(!HTMLDocument_prototype["getItems"]["orig"]) {//prevent refix
+ var orig = HTMLDocument_prototype["getItems"];
+ /**
+ * @this {(HTMLDocument|DocumentFragment)}
+ */
+ HTMLDocument_prototype["getItems"] = function() {
+ test_div.innerHTML = "<p itemprop='t'>t</p>";
+ test_div["properties"]["t"][0].innerHTML = "t";
+
+ //DEBUG::
+ //console.log((this.defaultView || global).location.href)
+
+ //If 'this' is not DocumentFragment, and 'this' is a docuemnt in iFrame defaultView would be exsist
+ fixPrototypes(this.defaultView || global);//Extend prototype's
+
+ return (this["getItems"] = orig).apply(document, arguments)
}
- result.push(cur);
+ HTMLDocument_prototype["getItems"]["orig"] = orig;
}
-
- return result;
}
-
- //Fix `itemValue` with FORM elements
- test_input["itemProp"] = "t";
- test_input.value = "1";
- if(test_input.value != test_input["itemValue"]) {
- fixPrototypes._formElements.forEach(function(_tagName) {
- if(_tagName == "TEXTAREA")_tagName = "TextArea";
- else _tagName = _tagName.charAt(0).toUpperCase() + _tagName.substring(1).toLowerCase();//INPUT -> Input
- var _proto = global["HTML" + _tagName + "Element"];
- if(_proto = _proto.prototype)
- Object.defineProperty(_proto, "itemValue", fixPrototypes.__itemValueProperty);
- })
- //_a === global["PropertyNodeList"].prototype
- _a["getValues"] = function() {//New `getValues` function worked for "Form Elements"
- var result = [], k = -1, el;
+ else {
+ var _PropertyNodeList = global["PropertyNodeList"];
+ if(!(_a = _PropertyNodeList.prototype).toJSON)_a.toJSON =
+ /**
+ * @this {PropertyNodeList}
+ * @return {Object} json
+ */
+ function() {
+ var thisObj = this,
+ result = [],
+ values = thisObj.getValues(),
+ i = -1,
+ cur;
- while(el = this[++k])
- result.push(el["itemValue"]);
+ while((cur = values[++i]) != null) {
+ if(cur instanceof Element) {
+ cur = itemToJSON(cur);//if cur is not Microdata element return undefined
+ }
+ result.push(cur);
+ }
return result;
}
- //TODO:: fix PropertyNodeList.values & PropertyNodeList.getValues()
- }
-
- //Check implementation of "values" property in PropertyNodeList in browser that support Microdata
- //Тут http://www.w3.org/TR/html5/microdata.html#using-the-microdata-dom-api (search: values)
- //TODO:: Check for compliance with FINALE Microdata specification.
- if(!("values" in _a)) {//_a === global["PropertyNodeList"]
- _a.__defineGetter__("values", //_a === global["PropertyNodeList"].prototype
- _a["getValues"]
- );
- }
-
- _a = global["HTMLPropertiesCollection"];
- if(!(_a = _a.prototype).toJSON)_a.toJSON = function() {
- var thisObj = this,
- result = {},
- names = thisObj["names"],
- i = -1,
- cur;
- while(cur = names[++i])
- if(thisObj[cur] instanceof _PropertyNodeList)
- result[cur] = thisObj[cur].toJSON();
+ //Fix `itemValue` with FORM elements
+ var test_input = document.createElement("input");
+ test_input["itemProp"] = "t";
+ test_input["itemScope"] = false;
+ test_input.value = "1";
+ if(test_input.value != test_input["itemValue"]) {
+ fixPrototypes._formElements.forEach(function(_tagName) {
+ if(_tagName == "TEXTAREA")_tagName = "TextArea";
+ else _tagName = _tagName.charAt(0).toUpperCase() + _tagName.substring(1).toLowerCase();//INPUT -> Input
+ var _proto = global["HTML" + _tagName + "Element"];
+ if(_proto = _proto.prototype)
+ Object.defineProperty(_proto, "itemValue", fixPrototypes.__itemValueProperty);
+ })
+ //_a === global["PropertyNodeList"].prototype
+ _a["getValues"] = function() {//New `getValues` function worked for "Form Elements"
+ var result = [], k = -1, el;
+
+ while(el = this[++k])
+ result.push(el["itemValue"]);
+
+ return result;
+ }
+ //TODO:: fix PropertyNodeList.values & PropertyNodeList.getValues()
+ }
+
+ _a = global["HTMLPropertiesCollection"];
+ if(!(_a = _a.prototype).toJSON)_a.toJSON = function() {
+ var thisObj = this,
+ result = {},
+ names = thisObj["names"],
+ i = -1,
+ cur;
+
+ while(cur = names[++i])
+ if(thisObj[cur] instanceof _PropertyNodeList)
+ result[cur] = thisObj[cur].toJSON();
+
+ return result;
+ }
- return result;
+ fixPrototypes.isfixed = true;
}
-
- fixPrototypes.isfixed = true;
}
if(!fixPrototypes.fixedDocumentFragment) {
Please sign in to comment.
Something went wrong with that request. Please try again.