1 | var XMLTools = { |
---|
2 | "_defaultUrl" : im_path + 'controller.php?action=', |
---|
3 | "_debug" : false, |
---|
4 | "_http" : null, |
---|
5 | "mode" : 'X', |
---|
6 | "threads" : [], |
---|
7 | "http" : function() |
---|
8 | { |
---|
9 | try |
---|
10 | { |
---|
11 | this._http = new XMLHttpRequest(); |
---|
12 | } |
---|
13 | catch (e) |
---|
14 | { |
---|
15 | try |
---|
16 | { |
---|
17 | this._http = new ActiveXObject('Msxml2.XMLHTTP'); |
---|
18 | } |
---|
19 | catch (e1) |
---|
20 | { |
---|
21 | try |
---|
22 | { |
---|
23 | this._http = new ActiveXObject('Microsoft.XMLHTTP'); |
---|
24 | } |
---|
25 | catch (e2) |
---|
26 | { |
---|
27 | this._http = null; |
---|
28 | } |
---|
29 | } |
---|
30 | } |
---|
31 | }, |
---|
32 | "load" : function(pFile) |
---|
33 | { |
---|
34 | var data = null; |
---|
35 | if ( document.implementation.createDocument ) |
---|
36 | data = document.implementation.createDocument("", "", null); |
---|
37 | else |
---|
38 | data = new ActiveXObject("Msxml2.FreeThreadedDOMDocument"); |
---|
39 | |
---|
40 | data.async = false; |
---|
41 | data.load(pFile); |
---|
42 | return data; |
---|
43 | }, |
---|
44 | "request" : function(pId, pTarget, pMethod, pHandler, pData) |
---|
45 | { |
---|
46 | if ( typeof pHandler != 'function' ) |
---|
47 | return false; |
---|
48 | |
---|
49 | if ( this.threads[pId] ) |
---|
50 | return false; |
---|
51 | else |
---|
52 | this.threads[pId] = pHandler; |
---|
53 | |
---|
54 | var _pTarget = pId; |
---|
55 | |
---|
56 | var _this = this; |
---|
57 | this.http(); |
---|
58 | var _http = this._http; |
---|
59 | var _handler = function () |
---|
60 | { |
---|
61 | try |
---|
62 | { |
---|
63 | switch( _http.readyState ) |
---|
64 | { |
---|
65 | case 1 : |
---|
66 | break; |
---|
67 | case 2 : |
---|
68 | break; |
---|
69 | case 3 : |
---|
70 | break; |
---|
71 | case 4 : |
---|
72 | switch ( _http.status ) |
---|
73 | { |
---|
74 | case 200: |
---|
75 | var data = ( _this.mode == 'X' ) ? |
---|
76 | _http.responseXML : |
---|
77 | _http.responseText; |
---|
78 | |
---|
79 | pHandler(data, _pTarget); |
---|
80 | _this.threads[_pTarget] = false; |
---|
81 | delete _this.threads[_pTarget]; |
---|
82 | break; |
---|
83 | case 404: |
---|
84 | alert('Page Not Found!'); |
---|
85 | break; |
---|
86 | default: |
---|
87 | } |
---|
88 | break; |
---|
89 | default: |
---|
90 | } |
---|
91 | } |
---|
92 | catch(e) |
---|
93 | { |
---|
94 | if ( this._debug ) alert(e) |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | try |
---|
99 | { |
---|
100 | var target = pTarget; |
---|
101 | if ( pMethod == 'POST' ) |
---|
102 | { |
---|
103 | _http.open("POST", target, true); |
---|
104 | _http.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); |
---|
105 | _http.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate'); |
---|
106 | _http.setRequestHeader('Cache-Control', 'post-check=0, pre-check=0'); |
---|
107 | _http.setRequestHeader('Pragma', 'no-cache'); |
---|
108 | _http.onreadystatechange = _handler; |
---|
109 | _http.send(pData); |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | _http.open("GET", target, true); |
---|
114 | _http.onreadystatechange = _handler; |
---|
115 | _http.send(null); |
---|
116 | } |
---|
117 | } |
---|
118 | catch(e) |
---|
119 | {} |
---|
120 | return true; |
---|
121 | }, |
---|
122 | "transform" : function(pXML, pXSL) |
---|
123 | { |
---|
124 | var fragment = null; |
---|
125 | if ( window.XSLTProcessor ) |
---|
126 | { |
---|
127 | var xslProc = new XSLTProcessor(); |
---|
128 | xslProc.importStylesheet(pXSL); |
---|
129 | fragment = xslProc.transformToFragment(pXML, document); |
---|
130 | |
---|
131 | // para retornar valor igual ao ie. |
---|
132 | var aux = document.createElement("div"); |
---|
133 | aux.appendChild(fragment); |
---|
134 | fragment = aux.innerHTML; |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | var xslTemplate = new ActiveXObject("Msxml2.XSLTemplate"); |
---|
139 | xslTemplate.stylesheet = pXSL; |
---|
140 | |
---|
141 | var myXslProc = xslTemplate.createProcessor(); |
---|
142 | myXslProc.input = pXML; |
---|
143 | |
---|
144 | myXslProc.transform(); |
---|
145 | fragment = myXslProc.output; |
---|
146 | |
---|
147 | } |
---|
148 | return fragment; |
---|
149 | } |
---|
150 | } |
---|