X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=js%2Fpz2.js;h=8ef4db8889a3db758a45188e4fba84383e72fdd0;hb=a293edf0d13509b00a61e25b159879fb97dffc17;hp=becef3391e4158a938108b849555f67410155a89;hpb=c24c7254b8a48abef8df4e195405f5e58b8aaf43;p=pazpar2-moved-to-github.git diff --git a/js/pz2.js b/js/pz2.js index becef33..8ef4db8 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -32,6 +32,7 @@ var pz2 = function ( paramArray ) throw new Error("Pz2.js: Array with parameters has to be supplied."); //supported pazpar2's protocol version + this.windowid = paramArray.windowid || window.name; this.suppProtoVer = '1'; if (typeof paramArray.pazpar2path != "undefined") this.pz2String = paramArray.pazpar2path; @@ -240,7 +241,7 @@ pz2.prototype = var request = new pzHttpRequest(this.pz2String, this.errorHandler); request.safeGet( - { "command": "ping", "session": this.sessionID, "windowid" : window.name }, + { "command": "ping", "session": this.sessionID, "windowid" : this.windowid }, function(data) { if ( data.getElementsByTagName("status")[0] .childNodes[0].nodeValue == "OK" ) { @@ -290,7 +291,7 @@ pz2.prototype = "command": "search", "query": this.currQuery, "session": this.sessionID, - "windowid" : window.name + "windowid" : this.windowid }; if( sort !== undefined ) { @@ -343,7 +344,7 @@ pz2.prototype = var context = this; var request = new pzHttpRequest(this.pz2String, this.errorHandler); request.safeGet( - { "command": "stat", "session": this.sessionID, "windowid" : window.name }, + { "command": "stat", "session": this.sessionID, "windowid" : this.windowid }, function(data) { if ( data.getElementsByTagName("stat") ) { var activeClients = @@ -401,7 +402,7 @@ pz2.prototype = "sort": this.currentSort, "block": 1, "type": this.showResponseType, - "windowid" : window.name + "windowid" : this.windowid }; if (query_state) requestParameters["query-state"] = query_state; @@ -490,7 +491,7 @@ pz2.prototype = "command": "record", "session": this.sessionID, "id": this.currRecID, - "windowid" : window.name + "windowid" : this.windowid }; this.currRecOffset = null; @@ -579,7 +580,7 @@ pz2.prototype = "command": "termlist", "session": this.sessionID, "name": this.termKeys, - "windowid" : window.name, + "windowid" : this.windowid, "version" : this.version }, @@ -672,7 +673,7 @@ pz2.prototype = "command": "bytarget", "session": this.sessionID, "block": 1, - "windowid" : window.name, + "windowid" : this.windowid, "version" : this.version }, function(data) { @@ -768,23 +769,26 @@ pz2.prototype = ** AJAX HELPER CLASS *********************************************************** ******************************************************************************** */ -var pzHttpRequest = function ( url, errorHandler ) { +var pzHttpRequest = function (url, errorHandler, cookieDomain) { this.maxUrlLength = 2048; this.request = null; this.url = url; this.errorHandler = errorHandler || null; this.async = true; this.requestHeaders = {}; - this.isXDomain = false; + this.isXDR = false; this.domainRegex = /https?:\/\/([^:/]+).*/; + this.cookieDomain = cookieDomain || null; var xhr = new XMLHttpRequest(); + var domain = this._getDomainFromUrl(url); if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari. - } else if (typeof XDomainRequest != "undefined") { - // XDomainRequest for IE. + } else if (domain && this._isCrossDomain(domain) && + typeof XDomainRequest != "undefined") { + // use XDR (IE7/8) when no other way xhr = new XDomainRequest(); - this.isXDomain = true; + this.isXDR = true; } else { // CORS not supported. } @@ -843,6 +847,7 @@ pzHttpRequest.prototype = _getDomainFromUrl: function (url) { + if (this.cookieDomain) return this.cookieDomain; //explicit cookie domain var m = this.domainRegex.exec(url); return (m && m.length > 1) ? m[1] : null; }, @@ -854,6 +859,7 @@ pzHttpRequest.prototype = _isCrossDomain: function (domain) { + if (this.cookieDomain) return true; //assume xdomain is cookie domain set return !this._strEndsWith(domain, document.domain); }, @@ -911,12 +917,12 @@ pzHttpRequest.prototype = } } this.request.open( type, url, this.async ); - if (!this.isXDomain) { + if (!this.isXDR) { //setting headers is only allowed with XHR for (var key in this.requestHeaders) this.request.setRequestHeader(key, this.requestHeaders[key]); } - if (this.isXDomain) { + if (this.isXDR) { this.request.onload = function () { //fake XHR props context.request.status = 200; @@ -953,7 +959,7 @@ pzHttpRequest.prototype = // pick up appplication errors first var errNode = null; // xdomainreq does not have responseXML - if (this.isXDomain) { + if (this.isXDR) { if (this.request.contentType.match(/\/xml/)){ var dom = new ActiveXObject('Microsoft.XMLDOM'); dom.async = false;