-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlQuery.min.js
More file actions
2 lines (2 loc) · 3.08 KB
/
xmlQuery.min.js
File metadata and controls
2 lines (2 loc) · 3.08 KB
1
2
/*! xmlQuery.js 1.0.0beta 2013-04-10 */
(function(t){var e=function(t,n){return new e.fn.init(t,n)};e.fn=e.prototype={constructor:e,sort:[].sort,splice:[].splice,push:[].push,length:0,size:function(){return this.length},pushStack:function(t){var n=e.merge(this.constructor(),t);return n.prevObject=this,n.context=this.context,n},init:function(t,n){var r,i,o,s=[];if(null===t||void 0===t)return this;if(n)for(o=e(n),t=o.find(t),r=0,i=t.length;i>r;r++)s.push(t[r]);return void 0!==t.length&&"string"==typeof t?this.append(t):"xmlQuery"===t.type?t:(void 0===t.length||t.type?s.push(t.documentElement||t):t.length>0&&(s=s.concat(t)),this.append(s))}},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(t){var n,r,i,o,s,h=this;if(null!==(o=t))for(i in o)if(o.hasOwnProperty(i)){if(n=h[i],r=o[i],h===r)continue;r&&"object"==typeof r?(s=n,h[i]=e.extend(r)):void 0!==r&&(h[i]=r)}return h},e.extend({error:function(t){throw Error(t)},serializeXML:function(n){var r;try{t.XMLSerializer||(t.XMLSerializer=function(){},t.XMLSerializer.prototype.serializeToString=function(t){return t.xml||""}),r=(new XMLSerializer).serializeToString(n)}catch(i){r=void 0}return r||e.error("Invalid XML Object"),r},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{t.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=void 0}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||e.error("Invalid XML: "+n),r},merge:function(t,e){var n,r=e.length,i=t.length;if("number"==typeof r)for(n=0;r>n;n++)t[i++]=e[n];else for(;void 0!==e[n];)t[i++]=e[n++];return t.length=i,t}}),e.fn.extend({type:"xmlQuery",attr:function(t,e){var n;if(void 0===e)return this[0].getAttribute(t)||void 0;for(n=0;this.length>n;n++)null!==e&&void 0!==e&&this[n].setAttribute(t,e);return this},find:function(t){var e,n,r,i=[];for(e=0;this.length>e;e++)for(r=this[e].getElementsByTagName(t),n=0;r.length>n;n++)i.push(r[n]);return this.pushStack(i)},append:function(t){var n,r,i,o=[];if(t.length&&"string"==typeof t){for(t=e.parseXML("<root>"+t+"</root>").documentElement.childNodes,n=0,i=t.length;i>n;n++)o.push((t[n].documentElement||t[n]).cloneNode(!0));t=o}if("number"==typeof t.length&&1===this.length){for(n=0,i=t.length;i>n;n++)this.append(t[n]);return this}if(0===this.length)for(void 0===t.length&&"object"==typeof t&&(t=[t]),n=0,i=t.length;i>n;n++)this.push(t[n]);else for(n=0,i=this.length;i>n;n++)this[n].importNode?r=this[n].importNode(t):this[n].appendChild((t.documentElement||t).cloneNode(!0));return this},serialize:function(){var t;return t=this.length>1?e("<root></root>").append(this)[0]:this[0],e.serializeXML(t).replace(/ ?xmlns="[^\"]*" ?/g," ")},toString:function(){return this.serialize()},first:function(){return this.length>0?e(this[0]):this},last:function(){return this.length>0?e(this[this.length-1]):this},eq:function(t){return e(this[t])},size:function(){return this.length},clone:function(t){var e,n,r=this.constructor();for(t=void 0===t?!0:t,e=0,n=this.length;n>e;e++)r.append(this[e].cloneNode(t));return r}}),t.xmlQuery=t.$X=e})(window);