[763] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for internet |
---|
| 3 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
| 6 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
| 7 | * |
---|
| 8 | * For further information visit: |
---|
| 9 | * http://www.fckeditor.net/ |
---|
| 10 | * |
---|
| 11 | * "Support Open Source software. What about a donation today?" |
---|
| 12 | * |
---|
| 13 | * File Name: fckxml.js |
---|
| 14 | * Defines the FCKXml object that is used for XML data calls |
---|
| 15 | * and XML processing. |
---|
| 16 | * This script is shared by almost all pages that compose the |
---|
| 17 | * File Browser frameset. |
---|
| 18 | * |
---|
| 19 | * File Authors: |
---|
| 20 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | var FCKXml = function() |
---|
| 24 | {} |
---|
| 25 | |
---|
| 26 | FCKXml.prototype.GetHttpRequest = function() |
---|
| 27 | { |
---|
| 28 | // Gecko / IE7 |
---|
| 29 | if ( typeof(XMLHttpRequest) != 'undefined' ) |
---|
| 30 | return new XMLHttpRequest() ; |
---|
| 31 | |
---|
| 32 | // IE6 |
---|
| 33 | try { return new ActiveXObject("Msxml2.XMLHTTP") ; } |
---|
| 34 | catch(e) {} |
---|
| 35 | |
---|
| 36 | // IE5 |
---|
| 37 | try { return new ActiveXObject("Microsoft.XMLHTTP") ; } |
---|
| 38 | catch(e) {} |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | FCKXml.prototype.LoadUrl = function( urlToCall, asyncFunctionPointer ) |
---|
| 42 | { |
---|
| 43 | var oFCKXml = this ; |
---|
| 44 | |
---|
| 45 | var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ; |
---|
| 46 | |
---|
| 47 | var oXmlHttp = this.GetHttpRequest() ; |
---|
| 48 | |
---|
| 49 | oXmlHttp.open( "GET", urlToCall, bAsync ) ; |
---|
| 50 | |
---|
| 51 | if ( bAsync ) |
---|
| 52 | { |
---|
| 53 | oXmlHttp.onreadystatechange = function() |
---|
| 54 | { |
---|
| 55 | if ( oXmlHttp.readyState == 4 ) |
---|
| 56 | { |
---|
| 57 | oFCKXml.DOMDocument = oXmlHttp.responseXML ; |
---|
| 58 | if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) |
---|
| 59 | asyncFunctionPointer( oFCKXml ) ; |
---|
| 60 | else |
---|
| 61 | alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | oXmlHttp.send( null ) ; |
---|
| 67 | |
---|
| 68 | if ( ! bAsync ) |
---|
| 69 | { |
---|
| 70 | if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ) |
---|
| 71 | this.DOMDocument = oXmlHttp.responseXML ; |
---|
| 72 | else |
---|
| 73 | { |
---|
| 74 | alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | FCKXml.prototype.SelectNodes = function( xpath ) |
---|
| 80 | { |
---|
| 81 | if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE |
---|
| 82 | return this.DOMDocument.selectNodes( xpath ) ; |
---|
| 83 | else // Gecko |
---|
| 84 | { |
---|
| 85 | var aNodeArray = new Array(); |
---|
| 86 | |
---|
| 87 | var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, |
---|
| 88 | this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), XPathResult.ORDERED_NODE_ITERATOR_TYPE, null) ; |
---|
| 89 | if ( xPathResult ) |
---|
| 90 | { |
---|
| 91 | var oNode = xPathResult.iterateNext() ; |
---|
| 92 | while( oNode ) |
---|
| 93 | { |
---|
| 94 | aNodeArray[aNodeArray.length] = oNode ; |
---|
| 95 | oNode = xPathResult.iterateNext(); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | return aNodeArray ; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | FCKXml.prototype.SelectSingleNode = function( xpath ) |
---|
| 103 | { |
---|
| 104 | if ( navigator.userAgent.indexOf('MSIE') >= 0 ) // IE |
---|
| 105 | return this.DOMDocument.selectSingleNode( xpath ) ; |
---|
| 106 | else // Gecko |
---|
| 107 | { |
---|
| 108 | var xPathResult = this.DOMDocument.evaluate( xpath, this.DOMDocument, |
---|
| 109 | this.DOMDocument.createNSResolver(this.DOMDocument.documentElement), 9, null); |
---|
| 110 | |
---|
| 111 | if ( xPathResult && xPathResult.singleNodeValue ) |
---|
| 112 | return xPathResult.singleNodeValue ; |
---|
| 113 | else |
---|
| 114 | return null ; |
---|
| 115 | } |
---|
| 116 | } |
---|