1.1 --- a/examples/Common/Configurator/Resources/scripts/sarissa.js Tue Jun 14 14:51:32 2005 +0000
1.2 +++ b/examples/Common/Configurator/Resources/scripts/sarissa.js Thu Jul 14 00:31:36 2005 +0000
1.3 @@ -3,7 +3,7 @@
1.4 * About
1.5 * ====================================================================
1.6 * Sarissa cross browser XML library
1.7 - * @version 0.9.5.2
1.8 + * @version 0.9.6
1.9 * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
1.10 *
1.11 * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.
1.12 @@ -52,13 +52,6 @@
1.13 */
1.14 Sarissa.IS_ENABLED_XMLHTTP = false;
1.15 /**
1.16 - * <b>Deprecated, will be removed in 0.9.6</b>. Check for
1.17 - * <code>window.XSLTProcessor</code> instead to see if
1.18 - * XSLTProcessor is available.
1.19 - * @type boolean
1.20 - */
1.21 -Sarissa.IS_ENABLED_XSLTPROC = false;
1.22 -/**
1.23 * tells you whether selectNodes/selectSingleNode is available
1.24 * @type boolean
1.25 */
1.26 @@ -68,16 +61,14 @@
1.27 var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;
1.28 var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;
1.29 var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;
1.30 -/** <b>Deprecated, will be removed in 0.9.6</b>. @deprecated */
1.31 var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;
1.32 -/** <b>Deprecated, will be removed in 0.9.6</b>. @deprecated */
1.33 -var _SARISSA_IS_IE = document.all && window.ActiveXObject && (navigator.userAgent.toLowerCase().indexOf("msie") > -1);
1.34 -//==========================================
1.35 -// Implement Node constants if not available
1.36 -//==========================================
1.37 +var _SARISSA_IS_SAFARI = navigator.userAgent.toLowerCase().indexOf("applewebkit") != -1;
1.38 +var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1;
1.39 +
1.40 if(!window.Node || !window.Node.ELEMENT_NODE){
1.41 var Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5, ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12};
1.42 };
1.43 +
1.44 // IE initialization
1.45 if(_SARISSA_IS_IE){
1.46 // for XSLT parameter names, prefix needed by IE
1.47 @@ -91,7 +82,7 @@
1.48 * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object
1.49 * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled
1.50 */
1.51 - function pickRecentProgID(idList, enabledList){
1.52 + pickRecentProgID = function (idList, enabledList){
1.53 // found progID flag
1.54 var bFound = false;
1.55 for(var i=0; i < idList.length && !bFound; i++){
1.56 @@ -139,15 +130,6 @@
1.57 };
1.58 return oDoc;
1.59 };
1.60 - if(!window.XMLHttpRequest){
1.61 - /**
1.62 - * Emulate XMLHttpRequest
1.63 - * @constructor
1.64 - */
1.65 - function XMLHttpRequest(){
1.66 - return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.67 - };
1.68 - };
1.69 // see non-IE version
1.70 Sarissa.getParseErrorText = function (oDoc) {
1.71 var parseErrorText = Sarissa.PARSED_OK;
1.72 @@ -175,7 +157,7 @@
1.73 * Reuses the same XSLT stylesheet for multiple transforms
1.74 * @constructor
1.75 */
1.76 - function XSLTProcessor(){
1.77 + XSLTProcessor = function(){
1.78 this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);
1.79 this.processor = null;
1.80 };
1.81 @@ -323,25 +305,6 @@
1.82 };
1.83 return oDoc;
1.84 };
1.85 -
1.86 - if(window.DOMParser && !XMLDocument.loadXML){
1.87 - /**
1.88 - * <p>Parses the String given as parameter to build the document content
1.89 - * for the object, exactly like IE's loadXML()</p>
1.90 - * @argument strXML The XML String to load as the Document's childNodes
1.91 - * @returns the old Document structure serialized as an XML String
1.92 - */
1.93 - XMLDocument.prototype.loadXML = function(strXML){
1.94 - Sarissa.__setReadyState__(this, 1);
1.95 - var sOldXML = this.xml;
1.96 - var oDoc = (new DOMParser()).parseFromString(strXML, "text/xml");
1.97 - Sarissa.__setReadyState__(this, 2);
1.98 - Sarissa.copyChildNodes(oDoc, this);
1.99 - Sarissa.__setReadyState__(this, 3);
1.100 - Sarissa.__handleLoad__(this);
1.101 - return sOldXML;
1.102 - };
1.103 - };//if(window.DOMParser && !XMLDocument.loadXML)
1.104 };//if(window.XMLDocument)
1.105
1.106 /**
1.107 @@ -354,13 +317,15 @@
1.108 oDoc.parseError = -1;
1.109 Sarissa.__setReadyState__(oDoc, 4);
1.110 };
1.111 +
1.112 /**
1.113 * <p>Attached by an event handler to the load event. Internal use.</p>
1.114 * @private
1.115 */
1.116 - function _sarissa_XMLDocument_onload() {
1.117 + _sarissa_XMLDocument_onload = function(){
1.118 Sarissa.__handleLoad__(this);
1.119 };
1.120 +
1.121 /**
1.122 * <p>Sets the readyState property of the given DOM Document object.
1.123 * Internal use.</p>
1.124 @@ -390,35 +355,61 @@
1.125 //==========================================
1.126 // Common stuff
1.127 //==========================================
1.128 +if(!window.DOMParser){
1.129 + /**
1.130 + * DOMParser is a utility class, used to construct DOMDocuments from XML strings
1.131 + * @constructor
1.132 + */
1.133 + DOMParser = function() {
1.134 + };
1.135 + /**
1.136 + * Construct a new DOM Document from the given XMLstring
1.137 + * @param sXml the given XML string
1.138 + * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml).
1.139 + * @return a new DOM Document from the given XML string
1.140 + */
1.141 + DOMParser.prototype.parseFromString = function(sXml, contentType){
1.142 + var doc = Sarissa.getDomDocument();
1.143 + doc.loadXML(sXml);
1.144 + return doc;
1.145 + };
1.146 +
1.147 +};
1.148 +
1.149 if(window.XMLHttpRequest){
1.150 + Sarissa.IS_ENABLED_XMLHTTP = true;
1.151 +}
1.152 +else if(_SARISSA_IS_IE){
1.153 /**
1.154 - * <p><b>Deprecated, will be removed in 0.9.6</b>. Factory method to obtain a new XMLHTTP Request object</p>
1.155 - * @returns a new XMLHTTP Request object
1.156 - * @deprecated
1.157 - */
1.158 - Sarissa.getXmlHttpRequest = function() {
1.159 - return new XMLHttpRequest();
1.160 + * Emulate XMLHttpRequest
1.161 + * @constructor
1.162 + */
1.163 + XMLHttpRequest = function() {
1.164 + return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);
1.165 };
1.166 Sarissa.IS_ENABLED_XMLHTTP = true;
1.167 };
1.168 -if(!window.document.importNode){
1.169 - /**
1.170 - * Implements importNode for the current window document in IE using innerHTML.
1.171 - * Testing showed that DOM was multiple times slower than innerHTML for this,
1.172 - * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML)
1.173 - * please gimme a call.
1.174 - * @param oNode the Node to import
1.175 - * @param bChildren whether to include the children of oNode
1.176 - * @returns the imported node for further use
1.177 - */
1.178 - window.document.importNode = function(oNode, bChildren){
1.179 - var importNode = document.createElement("div");
1.180 - if(bChildren)
1.181 - importNode.innerHTML = Sarissa.serialize(oNode);
1.182 - else
1.183 - importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false));
1.184 - return importNode.firstChild;
1.185 - };
1.186 +
1.187 +if(!window.document.importNode && _SARISSA_IS_IE){
1.188 + try{
1.189 + /**
1.190 + * Implements importNode for the current window document in IE using innerHTML.
1.191 + * Testing showed that DOM was multiple times slower than innerHTML for this,
1.192 + * sorry folks. If you encounter trouble (who knows what IE does behind innerHTML)
1.193 + * please gimme a call.
1.194 + * @param oNode the Node to import
1.195 + * @param bChildren whether to include the children of oNode
1.196 + * @returns the imported node for further use
1.197 + */
1.198 + window.document.importNode = function(oNode, bChildren){
1.199 + var importNode = document.createElement("div");
1.200 + if(bChildren)
1.201 + importNode.innerHTML = Sarissa.serialize(oNode);
1.202 + else
1.203 + importNode.innerHTML = Sarissa.serialize(oNode.cloneNode(false));
1.204 + return importNode.firstChild;
1.205 + };
1.206 + }catch(e){};
1.207 };
1.208 if(!Sarissa.getParseErrorText){
1.209 /**
1.210 @@ -452,13 +443,14 @@
1.211 var nodes = oNode.childNodes;
1.212 for(var i=0; i < nodes.length; i++){
1.213 var node = nodes[i];
1.214 - if(node.nodeType == Node.TEXT_NODE){
1.215 + var nodeType = node.nodeType;
1.216 + if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){
1.217 s += node.data;
1.218 - }else if(deep == true
1.219 - && (node.nodeType == Node.ELEMENT_NODE
1.220 - || node.nodeType == Node.DOCUMENT_NODE
1.221 - || node.nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
1.222 -
1.223 + }
1.224 + else if(deep == true
1.225 + && (nodeType == Node.ELEMENT_NODE
1.226 + || nodeType == Node.DOCUMENT_NODE
1.227 + || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){
1.228 s += Sarissa.getText(node, true);
1.229 };
1.230 };
1.231 @@ -493,9 +485,7 @@
1.232 };
1.233 };
1.234 };
1.235 -if(window.XSLTProcessor){
1.236 - Sarissa.IS_ENABLED_XSLTPROC = true;
1.237 -};
1.238 +
1.239 /**
1.240 * strips tags from a markup string
1.241 */
1.242 @@ -512,17 +502,20 @@
1.243 };
1.244 };
1.245 /**
1.246 - * <p> Replaces the childNodes of the toDoc object with the childNodes of
1.247 - * the fromDoc object</p>
1.248 - * <p> <b>Note:</b> The second object's original content is deleted before the copy operation</p>
1.249 + * <p> Copies the childNodes of nodeFrom to nodeTo</p>
1.250 + * <p> <b>Note:</b> The second object's original content is deleted before
1.251 + * the copy operation, unless you supply a true third parameter</p>
1.252 * @argument nodeFrom the Node to copy the childNodes from
1.253 * @argument nodeTo the Node to copy the childNodes to
1.254 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
1.255 */
1.256 -Sarissa.copyChildNodes = function(nodeFrom, nodeTo) {
1.257 - Sarissa.clearChildNodes(nodeTo);
1.258 +Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.259 + if(!bPreserveExisting){
1.260 + Sarissa.clearChildNodes(nodeTo);
1.261 + };
1.262 var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.263 var nodes = nodeFrom.childNodes;
1.264 - if(typeof(ownerDoc.importNode) == "function"){
1.265 + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
1.266 for(var i=0;i < nodes.length;i++) {
1.267 nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.268 };
1.269 @@ -534,6 +527,40 @@
1.270 };
1.271 };
1.272
1.273 +/**
1.274 + * <p> Moves the childNodes of nodeFrom to nodeTo</p>
1.275 + * <p> <b>Note:</b> The second object's original content is deleted before
1.276 + * the move operation, unless you supply a true third parameter</p>
1.277 + * @argument nodeFrom the Node to copy the childNodes from
1.278 + * @argument nodeTo the Node to copy the childNodes to
1.279 + * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false
1.280 + */
1.281 +Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {
1.282 + if(!bPreserveExisting){
1.283 + Sarissa.clearChildNodes(nodeTo);
1.284 + };
1.285 +
1.286 + var nodes = nodeFrom.childNodes;
1.287 + // if within the same doc, just move, else copy and delete
1.288 + if(nodeFrom.ownerDocument == nodeTo.ownerDocument){
1.289 + nodeTo.appendChild(nodes[i]);
1.290 + }else{
1.291 + var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;
1.292 + if(ownerDoc.importNode && (!_SARISSA_IS_IE)) {
1.293 + for(var i=0;i < nodes.length;i++) {
1.294 + nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));
1.295 + };
1.296 + }
1.297 + else{
1.298 + for(var i=0;i < nodes.length;i++) {
1.299 + nodeTo.appendChild(nodes[i].cloneNode(true));
1.300 + };
1.301 + };
1.302 + Sarissa.clearChildNodes(nodeFrom);
1.303 + };
1.304 +
1.305 +};
1.306 +
1.307 /**
1.308 * <p>Serialize any object to an XML string. All properties are serialized using the property name
1.309 * as the XML element name. Array elements are rendered as <code>array-item</code> elements,