Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.
Name: ui/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: | var xsl = $.parseXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output omit-xml-declaration="yes" indent="yes"/><xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template></xsl:stylesheet>'); |
20: | var ex; |
21: | this.each(function() { |
22: | if (window.ActiveXObject) { |
23: | // code for IE |
24: | ex = this.transformNode(xsl); |
25: | } else if (document.implementation && document.implementation.createDocument) { |
26: | // code for Chrome, Firefox, Opera, etc. |
27: | xsltProcessor = new XSLTProcessor(); |
28: | xsltProcessor.importStylesheet(xsl); |
29: | ex = xsltProcessor.transformToFragment(this, document); |
30: | } |
31: | out += xs.serializeToString(ex); |
32: | console.log(out); |
33: | }); |
34: | } else if (this[0] && this[0].xml != 'undefined') { |
35: | this.each(function() { |
36: | out += this.xml; |
37: | }); |
38: | } |
39: | return out; |
40: | }; |
41: | |
42: | String.prototype.repeat = function(num) { |
43: | return new Array(num + 1).join(this); |
44: | }; |
45: | |
46: | String.prototype.unserialize = function() { |
47: | var data = this.split("&"); |
48: | var ret = new Array(); |
49: | $.each(data, function(){ |
50: | var properties = this.split("="); |
51: | ret.push([properties[0], properties[1]]); |
52: | }); |
53: | return ret; |
54: | }; |
55: | |
56: | $X = function(xmlstr) { |
57: | return $($.parseXML(xmlstr).documentElement); |
58: | }; |