1/* 2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 3 * Copyright (C) 2003-2009 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 28var FCKXml = function() 29{} 30 31FCKXml.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 48FCKXml.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 // For IE 10 58 try { oXmlHttp.responseType = 'msxml-document'; } catch(e){} 59 if ( bAsync ) 60 { 61 oXmlHttp.onreadystatechange = function() 62 { 63 if ( oXmlHttp.readyState == 4 ) 64 { 65 var oXml ; 66 try 67 { 68 // this is the same test for an FF2 bug as in fckxml_gecko.js 69 // but we've moved the responseXML assignment into the try{} 70 // so we don't even have to check the return status codes. 71 var test = oXmlHttp.responseXML.firstChild ; 72 oXml = oXmlHttp.responseXML ; 73 } 74 catch ( e ) 75 { 76 try 77 { 78 oXml = (new DOMParser()).parseFromString( oXmlHttp.responseText, 'text/xml' ) ; 79 } 80 catch ( e ) {} 81 } 82 83 if ( !oXml || !oXml.firstChild || oXml.firstChild.nodeName == 'parsererror' ) 84 { 85 alert( 'The server didn\'t send back a proper XML response. Please contact your system administrator.\n\n' + 86 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')\n\n' + 87 'Requested URL:\n' + urlToCall + '\n\n' + 88 'Response text:\n' + oXmlHttp.responseText ) ; 89 return ; 90 } 91 92 oFCKXml.DOMDocument = oXml ; 93 asyncFunctionPointer( oFCKXml ) ; 94 } 95 } 96 } 97 98 oXmlHttp.send( null ) ; 99 100 if ( ! bAsync ) 101 { 102 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) { 103 this.DOMDocument = oXmlHttp.responseXML ; 104 } 105 else 106 { 107 alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; 108 } 109 } 110 111} 112 113FCKXml.prototype.SelectNodes = function( xpath ) 114{ 115 if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE 116 return this.DOMDocument.selectNodes( xpath ) ; 117 else // Gecko 118 { 119 var aNodeArray = new Array(); 120 121 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 122 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ; 123 if ( xPathResult ) 124 { 125 var oNode = xPathResult.iterateNext() ; 126 while( oNode ) 127 { 128 aNodeArray[aNodeArray.length] = oNode ; 129 oNode = xPathResult.iterateNext(); 130 } 131 } 132 return aNodeArray ; 133 } 134} 135 136FCKXml.prototype.SelectSingleNode = function( xpath ) 137{ 138 if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE 139 return this.DOMDocument.selectSingleNode( xpath ) ; 140 else // Gecko 141 { 142 var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, 143 this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null); 144 145 if ( xPathResult && xPathResult.singleNodeValue ) 146 return xPathResult.singleNodeValue ; 147 else 148 return null ; 149 } 150} 151 if(window.document.documentMode && window.document.documentMode > 8) { 152 document.writeln( '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />'); 153 154 } 155 156