Name: cockpit/lib/util.js
| 1: | $.fn.serializeXML = function () { |
| 2: | var out = ''; |
| 3: | if (typeof XMLSerializer == 'function') { |
| 4: | var xs = new XMLSerializer(); |
| 5: | this.each(function() { |
| 6: | out += xs.serializeToString(this); |
| 7: | }); |
| 8: | } else if (this[0] && this[0].xml != 'undefined') { |
| 9: | this.each(function() { |
| 10: | out += this.xml; |
| 11: | }); |
| 12: | } |
| 13: | return out; |
| 14: | }; |
| 15: | $.fn.serializePrettyXML = function () { |
| 16: | var out = ''; |
| 17: | if (typeof XMLSerializer == 'function') { |
| 18: | var xs = new XMLSerializer(); |
| 19: | this.each(function() { |
| 20: | out += XML(xs.serializeToString(this)).toXMLString(); |
| 21: | }); |
| 22: | } else if (this[0] && this[0].xml != 'undefined') { |
| 23: | this.each(function() { |
| 24: | out += this.xml; |
| 25: | }); |
| 26: | } |
| 27: | return out; |
| 28: | }; |
| 29: | |
| 30: | String.prototype.repeat = function(num) { |
| 31: | return new Array(num + 1).join(this); |
| 32: | }; |
| 33: | |
| 34: | String.prototype.unserialize = function() { |
| 35: | var data = this.split("&"); |
| 36: | var ret = new Array(); |
| 37: | $.each(data, function(){ |
| 38: | var properties = this.split("="); |
| 39: | ret.push([properties[0], properties[1]]); |
| 40: | }); |
| 41: | return ret; |
| 42: | }; |
| 43: | |
| 44: | String.prototype.parseXML = function() { |
| 45: | if (window.ActiveXObject && window.GetObject) { |
| 46: | var dom = new ActiveXObject('Microsoft.XMLDOM'); |
| 47: | dom.loadXML(this); |
| 48: | return dom; |
| 49: | } |
| 50: | if (window.DOMParser) |
| 51: | return new DOMParser().parseFromString(this,'text/xml'); |
| 52: | throw new Error('NoXMLparser available'); |
| 53: | } |
