X-Git-Url: https://svn.cri.ensmp.fr/git/Plinn.git/blobdiff_plain/3e0a2c257d49fb162da9c70d2f70194036235166..ac347cee296ffa604d899122742f9a5cdfd3b9dc:/skins/ajax_scripts/sarissa.js diff --git a/skins/ajax_scripts/sarissa.js b/skins/ajax_scripts/sarissa.js index ccac8ed..880b23b 100644 --- a/skins/ajax_scripts/sarissa.js +++ b/skins/ajax_scripts/sarissa.js @@ -5,7 +5,8 @@ * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs. * The library supports Gecko based browsers like Mozilla and Firefox, * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and Opera - * @author: Copyright 2004-2007 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net + * @version 0.9.9.6 + * @author: Copyright 2004-2008 Emmanouil Batsis, mailto: mbatsis at users full stop sourceforge full stop net * ==================================================================== * Licence * ==================================================================== @@ -33,14 +34,18 @@ * @static */ function Sarissa(){} -Sarissa.VERSION = "0.9.9.3"; +Sarissa.VERSION = "0.9.9.6"; Sarissa.PARSED_OK = "Document contains no parsing errors"; Sarissa.PARSED_EMPTY = "Document is empty"; Sarissa.PARSED_UNKNOWN_ERROR = "Not well-formed or other error"; Sarissa.IS_ENABLED_TRANSFORM_NODE = false; Sarissa.REMOTE_CALL_FLAG = "gr.abiss.sarissa.REMOTE_CALL_FLAG"; /** @private */ -Sarissa._sarissa_iNsCounter = 0; +Sarissa._lastUniqueSuffix = 0; +/** @private */ +Sarissa._getUniqueSuffix = function(){ + return Sarissa._lastUniqueSuffix++; +}; /** @private */ Sarissa._SARISSA_IEPREFIX4XSLPARAM = ""; /** @private */ @@ -58,6 +63,8 @@ Sarissa._SARISSA_IS_SAFARI_OLD = Sarissa._SARISSA_IS_SAFARI && (parseInt((naviga /** @private */ Sarissa._SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf("msie") > -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1; /** @private */ +Sarissa._SARISSA_IS_IE9 = Sarissa._SARISSA_IS_IE && navigator.userAgent.toLowerCase().indexOf("msie 9") > -1; +/** @private */ Sarissa._SARISSA_IS_OPERA = navigator.userAgent.toLowerCase().indexOf("opera") != -1; if(!window.Node || !Node.ELEMENT_NODE){ 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}; @@ -139,9 +146,22 @@ if(Sarissa._SARISSA_IS_IE){ // see non-IE version Sarissa.getDomDocument = function(sUri, sName){ if(!_SARISSA_DOM_PROGID){ - _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]); + try{ + _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID(["Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"]); + }catch(e){ + _SARISSA_DOM_PROGID = "noActiveX"; + } } - var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID); + + // Not sure how far IE can carry this but try to do something useful when ActiveX is disabled + var oDoc = _SARISSA_DOM_PROGID == "noActiveX" ? document.createElement("xml") : new ActiveXObject(_SARISSA_DOM_PROGID); + // set validation off, make sure older IEs dont choke (no time or IEs to test ;-) + try{ + oDoc.validateOnParse = false; + oDoc.resolveExternals = "false"; + oDoc.setProperty("ProhibitDTD", false); + }catch(e){} + // if a root tag name was provided, we need to load it in the DOM object if (sName){ // create an artifical namespace prefix @@ -152,7 +172,7 @@ if(Sarissa._SARISSA_IS_IE){ prefix = sName.substring(0, sName.indexOf(":")); sName = sName.substring(sName.indexOf(":")+1); }else{ - prefix = "a" + (Sarissa._sarissa_iNsCounter++); + prefix = "a" + Sarissa._getUniqueSuffix(); } } // use namespaces if a namespace URI exists @@ -203,7 +223,7 @@ if(Sarissa._SARISSA_IS_IE){ /** * Imports the given XSLT DOM and compiles it to a reusable transform * Note: If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those - * @argument xslDoc The XSLT DOMDocument to import + * @param {DOMDocument} xslDoc The XSLT DOMDocument to import */ XSLTProcessor.prototype.importStylesheet = function(xslDoc){ if(!_SARISSA_THREADEDDOM_PROGID){ @@ -217,9 +237,10 @@ if(Sarissa._SARISSA_IS_IE){ try{ converted.resolveExternals = true; converted.setProperty("AllowDocumentFunction", true); + converted.setProperty("AllowXsltScript", true); } catch(e){ - // Ignore. "AllowDocumentFunction" is only supported in MSXML 3.0 SP4 and later. + // Ignore. "AllowDocumentFunction" and "AllowXsltScript" is only supported in MSXML 3.0 SP4+ and 3.0 SP8+ respectively. } if(xslDoc.url && xslDoc.selectSingleNode("//xsl:*[local-name() = 'import' or local-name() = 'include']") != null){ converted.async = false; @@ -245,8 +266,8 @@ if(Sarissa._SARISSA_IS_IE){ /** * Transform the given XML DOM and return the transformation result as a new DOM document - * @argument sourceDoc The XML DOMDocument to transform - * @return The transformation result as a DOM Document + * @param {DOMDocument} sourceDoc The XML DOMDocument to transform + * @return {DOMDocument} The transformation result as a DOM Document */ XSLTProcessor.prototype.transformToDocument = function(sourceDoc){ // fix for bug 1549749 @@ -275,9 +296,9 @@ if(Sarissa._SARISSA_IS_IE){ /** * Transform the given XML DOM and return the transformation result as a new DOM fragment. * Note: The xsl:output method must match the nature of the owner document (XML/HTML). - * @argument sourceDoc The XML DOMDocument to transform - * @argument ownerDoc The owner of the result fragment - * @return The transformation result as a DOM Document + * @param {DOMDocument} sourceDoc The XML DOMDocument to transform + * @param {DOMDocument} ownerDoc The owner of the result fragment + * @return {DOMDocument} The transformation result as a DOM Document */ XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) { this.processor.input = sourceDoc; @@ -310,10 +331,12 @@ if(Sarissa._SARISSA_IS_IE){ }; /** - * Set global XSLT parameter of the imported stylesheet - * @argument nsURI The parameter namespace URI - * @argument name The parameter base name - * @argument value The new parameter value + * Set global XSLT parameter of the imported stylesheet. This method should + * only be used after the importStylesheet method for the + * context XSLTProcessor instance. + * @param {String} nsURI The parameter namespace URI + * @param {String} name The parameter base name + * @param {String} value The new parameter value */ XSLTProcessor.prototype.setParameter = function(nsURI, name, value){ // make value a zero length string if null to allow clearing @@ -334,9 +357,9 @@ if(Sarissa._SARISSA_IS_IE){ /** * Gets a parameter if previously set by setParameter. Returns null * otherwise - * @argument name The parameter base name - * @argument value The new parameter value - * @return The parameter value if reviously set by setParameter, null otherwise + * @param {String} name The parameter base name + * @param {String} value The new parameter value + * @return {String} The parameter value if reviously set by setParameter, null otherwise */ XSLTProcessor.prototype.getParameter = function(nsURI, name){ nsURI = "" + (nsURI || ""); @@ -384,9 +407,9 @@ if(Sarissa._SARISSA_IS_IE){ * Internal use.
* @memberOf Sarissa * @private - * @argument oDoc the DOM Document object to fire the + * @param oDoc the DOM Document object to fire the * readystatechange event - * @argument iReadyState the number to change the readystate property to + * @param iReadyState the number to change the readystate property to */ Sarissa.__setReadyState__ = function(oDoc, iReadyState){ oDoc.readyState = iReadyState; @@ -426,9 +449,9 @@ if(Sarissa._SARISSA_IS_IE){ /** *Factory method to obtain a new DOM Document object
* @memberOf Sarissa - * @argument sUri the namespace of the root node (if any) - * @argument sUri the local name of the root node (if any) - * @returns a new DOM Document + * @param {String} sUri the namespace of the root node (if any) + * @param {String} sUri the local name of the root node (if any) + * @returns {DOMDOcument} a new DOM Document */ Sarissa.getDomDocument = function(sUri, sName){ var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null); @@ -450,18 +473,18 @@ if(Sarissa._SARISSA_IS_IE){ //========================================== // Common stuff //========================================== -if(!window.DOMParser){ +if(!window.DOMParser || Sarissa._SARISSA_IS_IE9){ if(Sarissa._SARISSA_IS_SAFARI){ - /* + /** * DOMParser is a utility class, used to construct DOMDocuments from XML strings * @constructor */ DOMParser = function() { }; /** * Construct a new DOM Document from the given XMLstring - * @param sXml the given XML string - * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). - * @return a new DOM Document from the given XML string + * @param {String} sXml the given XML string + * @param {String} contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). + * @return {DOMDocument} a new DOM Document from the given XML string */ DOMParser.prototype.parseFromString = function(sXml, contentType){ var xmlhttp = new XMLHttpRequest(); @@ -473,6 +496,10 @@ if(!window.DOMParser){ DOMParser = function() { }; DOMParser.prototype.parseFromString = function(sXml, contentType){ var doc = Sarissa.getDomDocument(); + try{ + doc.validateOnParse = false; + doc.setProperty("ProhibitDTD", false); + }catch(e){} doc.loadXML(sXml); return doc; }; @@ -484,8 +511,8 @@ if((typeof(document.importNode) == "undefined") && Sarissa._SARISSA_IS_IE){ /** * Implementation of importNode for the context window document in IE. * IfoNode
is a TextNode, bChildren
is ignored.
- * @param oNode the Node to import
- * @param bChildren whether to include the children of oNode
+ * @param {DOMNode} oNode the Node to import
+ * @param {boolean} bChildren whether to include the children of oNode
* @returns the imported node for further use
*/
document.importNode = function(oNode, bChildren){
@@ -523,13 +550,13 @@ if(!Sarissa.getParseErrorText){
* element if you want to render it.
* Many thanks to Christian Stocker for the initial patch.
* @memberOf Sarissa - * @argument oDoc The target DOM document - * @returns The parsing error description of the target Document in + * @param {DOMDocument} oDoc The target DOM document + * @returns {String} The parsing error description of the target Document in * human readable form (preformated text) */ Sarissa.getParseErrorText = function (oDoc){ var parseErrorText = Sarissa.PARSED_OK; - if(!oDoc.documentElement){ + if((!oDoc) || (!oDoc.documentElement)){ parseErrorText = Sarissa.PARSED_EMPTY; } else if(oDoc.documentElement.tagName == "parsererror"){ parseErrorText = oDoc.documentElement.firstChild.data; @@ -545,13 +572,18 @@ if(!Sarissa.getParseErrorText){ } /** * Get a string with the concatenated values of all string nodes under the given node - * @memberOf Sarissa - * @argument oNode the given DOM node - * @argument deep whether to recursively scan the children nodes of the given node for text as well. Default isfalse
+ * @param {DOMNode} oNode the given DOM node
+ * @param {boolean} deep whether to recursively scan the children nodes of the given node for text as well. Default is false
+ * @memberOf Sarissa
*/
Sarissa.getText = function(oNode, deep){
var s = "";
var nodes = oNode.childNodes;
+ // opera fix, finds no child text node for attributes so we use .value
+ if (oNode.nodeType == Node.ATTRIBUTE_NODE && nodes.length == 0) {
+ return oNode.value;
+ }
+ // END opera fix
for(var i=0; i < nodes.length; i++){
var node = nodes[i];
var nodeType = node.nodeType;
@@ -571,17 +603,29 @@ if(!window.XMLSerializer && Sarissa.getDomDocument && Sarissa.getDomDocument("",
XMLSerializer = function(){};
/**
* Serialize the given DOM Node to an XML string
- * @param oNode the DOM Node to serialize
+ * @param {DOMNode} oNode the DOM Node to serialize
*/
XMLSerializer.prototype.serializeToString = function(oNode) {
return oNode.xml;
};
+} else if (Sarissa._SARISSA_IS_IE9 && window.XMLSerializer) {
+ // We save old object for any futur use with IE Document (not xml)
+ IE9XMLSerializer= XMLSerializer;
+ XMLSerializer = function(){ this._oldSerializer=new IE9XMLSerializer() };
+ XMLSerializer.prototype.serializeToString = function(oNode) {
+ if (typeof(oNode)=='object' && 'xml' in oNode) {
+ return oNode.xml;
+ } else {
+ return this._oldSerializer.serializeToString(oNode);
+ }
+ };
}
/**
* Strips tags from the given markup string. If the given string is
* undefined
, null
or empty, it is returned as is.
* @memberOf Sarissa
+ * @param {String} s the string to strip the tags from
*/
Sarissa.stripTags = function (s) {
return s?s.replace(/<[^>]+>/g,""):s;
@@ -589,7 +633,7 @@ Sarissa.stripTags = function (s) {
/**
* Deletes all child nodes of the given node
* @memberOf Sarissa - * @argument oNode the Node to empty + * @param {DOMNode} oNode the Node to empty */ Sarissa.clearChildNodes = function(oNode) { // need to check for firstChild due to opera 8 bug with hasChildNodes @@ -602,9 +646,9 @@ Sarissa.clearChildNodes = function(oNode) { *Note: The second object's original content is deleted before * the copy operation, unless you supply a true third parameter
* @memberOf Sarissa - * @argument nodeFrom the Node to copy the childNodes from - * @argument nodeTo the Node to copy the childNodes to - * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false + * @param {DOMNode} nodeFrom the Node to copy the childNodes from + * @param {DOMNode} nodeTo the Node to copy the childNodes to + * @param {boolean} bPreserveExisting whether to preserve the original content of nodeTo, default is false */ Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { if(Sarissa._SARISSA_IS_SAFARI && nodeTo.nodeType == Node.DOCUMENT_NODE){ // SAFARI_OLD ?? @@ -636,9 +680,9 @@ Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { *Note: The second object's original content is deleted before * the move operation, unless you supply a true third parameter
* @memberOf Sarissa - * @argument nodeFrom the Node to copy the childNodes from - * @argument nodeTo the Node to copy the childNodes to - * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is + * @param {DOMNode} nodeFrom the Node to copy the childNodes from + * @param {DOMNode} nodeTo the Node to copy the childNodes to + * @param {boolean} bPreserveExisting whether to preserve the original content of nodeTo, default is */ Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { if((!nodeFrom) || (!nodeTo)){ @@ -674,22 +718,30 @@ Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) { * as the XML element name. Array elements are rendered asarray-item
elements,
* using their index/key as the value of the key
attribute.
* @memberOf Sarissa
- * @argument anyObject the object to serialize
- * @argument objectName a name for that object
- * @return the XML serialization of the given object as a string
+ * @param {Object} anyObject the object to serialize
+ * @param {String} objectName a name for that object, to be used as the root element name
+ * @param {String} indentSpace Optional, the indentation space to use, default is an empty
+ * string. A single space character is added in any recursive call.
+ * @param {noolean} skipEscape Optional, whether to skip escaping characters that map to the
+ * five predefined XML entities. Default is false
.
+ * @return {String} the XML serialization of the given object as a string
*/
-Sarissa.xmlize = function(anyObject, objectName, indentSpace){
+Sarissa.xmlize = function(anyObject, objectName, indentSpace, skipEscape){
indentSpace = indentSpace?indentSpace:'';
var s = indentSpace + '<' + objectName + '>';
var isLeaf = false;
if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String || anyObject instanceof Boolean || anyObject instanceof Date){
- s += Sarissa.escape(""+anyObject);
+ s += (skipEscape ? Sarissa.escape(anyObject) : anyObject);
isLeaf = true;
}else{
s += "\n";
var isArrayItem = anyObject instanceof Array;
for(var name in anyObject){
- s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " ");
+ // do not xmlize functions
+ if (anyObject[name] instanceof Function){
+ continue;
+ }
+ s += Sarissa.xmlize(anyObject[name], (isArrayItem?"array-item key=\""+name+"\"":name), indentSpace + " ");
}
s += indentSpace;
}
@@ -699,7 +751,7 @@ Sarissa.xmlize = function(anyObject, objectName, indentSpace){
/**
* Escape the given string chacters that correspond to the five predefined XML entities
* @memberOf Sarissa
- * @param sXml the string to escape
+ * @param {String} sXml the string to escape
*/
Sarissa.escape = function(sXml){
return sXml.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'");
@@ -709,7 +761,7 @@ Sarissa.escape = function(sXml){
* Unescape the given string. This turns the occurences of the predefined XML
* entities to become the characters they represent correspond to the five predefined XML entities
* @memberOf Sarissa
- * @param sXml the string to unescape
+ * @param {String}sXml the string to unescape
*/
Sarissa.unescape = function(sXml){
return sXml.replace(/'/g,"'").replace(/"/g,"\"").replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&");
@@ -728,13 +780,13 @@ Sarissa.updateCursor = function(oTargetElement, sValue) {
* You can also pass a callback function to be executed when the update is finished. The function will be called as
* functionName(oNode, oTargetElement);
* @memberOf Sarissa
- * @param sFromUrl the URL to make the request to
- * @param oTargetElement the element to update
- * @param xsltproc (optional) the transformer to use on the returned
+ * @param {String} sFromUrl the URL to make the request to
+ * @param {DOMElement} oTargetElement the element to update
+ * @param {XSLTProcessor} xsltproc (optional) the transformer to use on the returned
* content before updating the target element with it
- * @param callback (optional) a Function object to execute once the update is finished successfuly, called as callback(sFromUrl, oTargetElement)
.
+ * @param {Function} callback (optional) a Function object to execute once the update is finished successfuly, called as callback(sFromUrl, oTargetElement)
.
* In case an exception is thrown during execution, the callback is called as called as callback(sFromUrl, oTargetElement, oException)
- * @param skipCache (optional) whether to skip any cache
+ * @param {boolean} skipCache (optional) whether to skip any cache
*/
Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc, callback, skipCache) {
try{
@@ -747,7 +799,9 @@ Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc, call
var oDomDoc = xmlhttp.responseXML;
if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement, xsltproc);
- callback(sFromUrl, oTargetElement);
+ if(callback){
+ callback(sFromUrl, oTargetElement);
+ }
}
else{
throw Sarissa.getParseErrorText(oDomDoc);
@@ -786,9 +840,9 @@ Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc, call
* You can also pass a callback function to be executed when the update is finished. The function will be called as
* functionName(oNode, oTargetElement);
* @memberOf Sarissa
- * @param oNode the URL to make the request to
- * @param oTargetElement the element to update
- * @param xsltproc (optional) the transformer to use on the given
+ * @param {DOMNode} oNode the URL to make the request to
+ * @param {DOMElement} oTargetElement the element to update
+ * @param {XSLTProcessor} xsltproc (optional) the transformer to use on the given
* DOM node before updating the target element with it
*/
Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
@@ -813,12 +867,12 @@ Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
}
else {
// ok that was not smart; it was paranoid. Keep up the good work by trying to use DOM instead of innerHTML
- if(oNode.nodeType == Node.DOCUMENT_NODE || oNode.ownerDocument.documentElement == oNode) {
- oTargetElement.innerHTML = new XMLSerializer().serializeToString(oNode);
- }
- else{
+ try{
oTargetElement.appendChild(oTargetElement.ownerDocument.importNode(oNode, true));
}
+ catch(e){
+ oTargetElement.innerHTML = new XMLSerializer().serializeToString(oNode);
+ }
}
}
}
@@ -834,6 +888,7 @@ Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
/**
* Creates an HTTP URL query string from the given HTML form data
* @memberOf Sarissa
+ * @param {HTMLFormElement} oForm the form to construct the query string from
*/
Sarissa.formToQueryString = function(oForm){
var qs = "";
@@ -893,11 +948,11 @@ Sarissa.formToQueryString = function(oForm){
* simply by assigning another value to Sarissa.REMOTE_CALL_FLAG. If JavaScript is not supported
* the form will be submitted normally.
* @memberOf Sarissa
- * @param oForm the form submition to emulate
- * @param oTargetElement the element to update
- * @param xsltproc (optional) the transformer to use on the returned
+ * @param {HTMLFormElement} oForm the form submition to emulate
+ * @param {DOMElement} oTargetElement the element to update
+ * @param {XSLTProcessor} xsltproc (optional) the transformer to use on the returned
* content before updating the target element with it
- * @param callback (optional) a Function object to execute once the update is finished successfuly, called as callback(oNode, oTargetElement)
.
+ * @param {Function} callback (optional) a Function object to execute once the update is finished successfuly, called as callback(oNode, oTargetElement)
.
* In case an exception occurs during excecution and a callback function was provided, the exception is cought and the callback is called as
* callback(oForm, oTargetElement, exception)
*/
@@ -923,7 +978,9 @@ Sarissa.updateContentFromForm = function(oForm, oTargetElement, xsltproc, callba
var oDomDoc = xmlhttp.responseXML;
if(oDomDoc && Sarissa.getParseErrorText(oDomDoc) == Sarissa.PARSED_OK){
Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement, xsltproc);
- callback(oForm, oTargetElement);
+ if(callback){
+ callback(oForm, oTargetElement);
+ }
}
else{
throw Sarissa.getParseErrorText(oDomDoc);
@@ -953,4 +1010,79 @@ Sarissa.updateContentFromForm = function(oForm, oTargetElement, xsltproc, callba
return false;
};
+/**
+ * Get the name of a function created like:
+ * function functionName(){}+ * If a name is not found, attach the function to + * the window object with a new name and return that + * @param {Function} oFunc the function object + */ +Sarissa.getFunctionName = function(oFunc){ + if(!oFunc || (typeof oFunc != 'function' )){ + throw "The value of parameter 'oFunc' must be a function"; + } + if(oFunc.name) { + return oFunc.name; + } + // try to parse the function name from the defintion + var sFunc = oFunc.toString(); + alert("sFunc: "+sFunc); + var name = sFunc.substring(sFunc.indexOf('function') + 8 , sFunc.indexOf('(')); + if(!name || name.length == 0 || name == " "){ + // attach to window object under a new name + name = "SarissaAnonymous" + Sarissa._getUniqueSuffix(); + window[name] = oFunc; + } + return name; +}; + +/** + * + */ +Sarissa.setRemoteJsonCallback = function(url, callback, callbackParam) { + if(!callbackParam){ + callbackParam = "callback"; + } + var callbackFunctionName = Sarissa.getFunctionName(callback); + //alert("callbackFunctionName: '" + callbackFunctionName+"', length: "+callbackFunctionName.length); + var id = "sarissa_json_script_id_" + Sarissa._getUniqueSuffix(); + var oHead = document.getElementsByTagName("head")[0]; + var scriptTag = document.createElement('script'); + scriptTag.type = 'text/javascript'; + scriptTag.id = id; + scriptTag.onload = function(){ + // cleanUp + // document.removeChild(scriptTag); + }; + if(url.indexOf("?") != -1){ + url += ("&" + callbackParam + "=" + callbackFunctionName); + } + else{ + url += ("?" + callbackParam + "=" + callbackFunctionName); + } + scriptTag.src = url; + oHead.appendChild(scriptTag); + return id; +}; + // EOF + +/*\ +|*| +|*| :: XMLHttpRequest.prototype.sendAsBinary() Polifyll :: +|*| +|*| https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#sendAsBinary() +|*| +\*/ + +if (!XMLHttpRequest.prototype.sendAsBinary) { + XMLHttpRequest.prototype.sendAsBinary = function (sData) { + var nBytes = sData.length, ui8Data = new Uint8Array(nBytes); + for (var nIdx = 0; nIdx < nBytes; nIdx++) { + ui8Data[nIdx] = sData.charCodeAt(nIdx) & 0xff; + } + /* send as ArrayBufferView...: */ + this.send(ui8Data); + /* ...or as ArrayBuffer (legacy)...: this.send(ui8Data.buffer); */ + }; +}