| 1925 |
jp_milcent |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
|
|
|
3 |
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
|
|
|
4 |
*
|
|
|
5 |
* == BEGIN LICENSE ==
|
|
|
6 |
*
|
|
|
7 |
* Licensed under the terms of any of the following licenses at your
|
|
|
8 |
* choice:
|
|
|
9 |
*
|
|
|
10 |
* - GNU General Public License Version 2 or later (the "GPL")
|
|
|
11 |
* http://www.gnu.org/licenses/gpl.html
|
|
|
12 |
*
|
|
|
13 |
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
|
|
|
14 |
* http://www.gnu.org/licenses/lgpl.html
|
|
|
15 |
*
|
|
|
16 |
* - Mozilla Public License Version 1.1 or later (the "MPL")
|
|
|
17 |
* http://www.mozilla.org/MPL/MPL-1.1.html
|
|
|
18 |
*
|
|
|
19 |
* == END LICENSE ==
|
|
|
20 |
*
|
|
|
21 |
* Defines the FCKXml object that is used for XML data calls
|
|
|
22 |
* and XML processing.
|
|
|
23 |
*
|
|
|
24 |
* This script is shared by almost all pages that compose the
|
|
|
25 |
* File Browser frameset.
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
var FCKXml = function()
|
|
|
29 |
{}
|
|
|
30 |
|
|
|
31 |
FCKXml.prototype.GetHttpRequest = function()
|
|
|
32 |
{
|
|
|
33 |
// Gecko / IE7
|
|
|
34 |
try { return new XMLHttpRequest(); }
|
|
|
35 |
catch(e) {}
|
|
|
36 |
|
|
|
37 |
// IE6
|
|
|
38 |
try { return new ActiveXObject( 'Msxml2.XMLHTTP' ) ; }
|
|
|
39 |
catch(e) {}
|
|
|
40 |
|
|
|
41 |
// IE5
|
|
|
42 |
try { return new ActiveXObject( 'Microsoft.XMLHTTP' ) ; }
|
|
|
43 |
catch(e) {}
|
|
|
44 |
|
|
|
45 |
return null ;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer )
|
|
|
49 |
{
|
|
|
50 |
var oFCKXml = this ;
|
|
|
51 |
|
|
|
52 |
var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
|
|
|
53 |
|
|
|
54 |
var oXmlHttp = this.GetHttpRequest() ;
|
|
|
55 |
|
|
|
56 |
oXmlHttp.open( "GET", urlToCall, bAsync ) ;
|
|
|
57 |
|
|
|
58 |
if ( bAsync )
|
|
|
59 |
{
|
|
|
60 |
oXmlHttp.onreadystatechange = function()
|
|
|
61 |
{
|
|
|
62 |
if ( oXmlHttp.readyState == 4 )
|
|
|
63 |
{
|
|
|
64 |
var oXml ;
|
|
|
65 |
try
|
|
|
66 |
{
|
|
|
67 |
// this is the same test for an FF2 bug as in fckxml_gecko.js
|
|
|
68 |
// but we've moved the responseXML assignment into the try{}
|
|
|
69 |
// so we don't even have to check the return status codes.
|
|
|
70 |
var test = oXmlHttp.responseXML.firstChild ;
|
|
|
71 |
oXml = oXmlHttp.responseXML ;
|
|
|
72 |
}
|
|
|
73 |
catch ( e )
|
|
|
74 |
{
|
|
|
75 |
try
|
|
|
76 |
{
|
|
|
77 |
oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ;
|
|
|
78 |
}
|
|
|
79 |
catch ( e ) {}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' )
|
|
|
83 |
{
|
|
|
84 |
alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' +
|
|
|
85 |
'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' +
|
|
|
86 |
'Requested URL:\n' + urlToCall + '\n\n' +
|
|
|
87 |
'Response text:\n' + oXmlHttp.responseText ) ;
|
|
|
88 |
return ;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
oFCKXml.DOMDocument = oXml ;
|
|
|
92 |
asyncFunctionPointer( oFCKXml ) ;
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
oXmlHttp.send( null ) ;
|
|
|
98 |
|
|
|
99 |
if ( ! bAsync )
|
|
|
100 |
{
|
|
|
101 |
if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 )
|
|
|
102 |
this.DOMDocument = oXmlHttp.responseXML ;
|
|
|
103 |
else
|
|
|
104 |
{
|
|
|
105 |
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
FCKXml.prototype.SelectNodes = function( xpath )
|
|
|
111 |
{
|
|
|
112 |
if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE
|
|
|
113 |
return this.DOMDocument.selectNodes( xpath ) ;
|
|
|
114 |
else // Gecko
|
|
|
115 |
{
|
|
|
116 |
var aNodeArray = new Array();
|
|
|
117 |
|
|
|
118 |
var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
|
|
|
119 |
this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ;
|
|
|
120 |
if ( xPathResult )
|
|
|
121 |
{
|
|
|
122 |
var oNode = xPathResult.iterateNext() ;
|
|
|
123 |
while( oNode )
|
|
|
124 |
{
|
|
|
125 |
aNodeArray[aNodeArray.length] = oNode ;
|
|
|
126 |
oNode = xPathResult.iterateNext();
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
return aNodeArray ;
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
FCKXml.prototype.SelectSingleNode = function( xpath )
|
|
|
134 |
{
|
|
|
135 |
if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE
|
|
|
136 |
return this.DOMDocument.selectSingleNode( xpath ) ;
|
|
|
137 |
else // Gecko
|
|
|
138 |
{
|
|
|
139 |
var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument,
|
|
|
140 |
this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null);
|
|
|
141 |
|
|
|
142 |
if ( xPathResult && xPathResult.singleNodeValue )
|
|
|
143 |
return xPathResult.singleNodeValue ;
|
|
|
144 |
else
|
|
|
145 |
return null ;
|
|
|
146 |
}
|
|
|
147 |
}
|