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;
this.stop();
if ( this.resetCallback )
- this.resetCallback();
+ this.resetCallback(this.windowid);
},
init: function (sessionId, serviceId)
context.keepAlive
);
if ( context.initCallback )
- context.initCallback();
+ context.initCallback(context.windowid);
}
else
context.throwError('Init failed. Malformed WS resonse.',
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
request.safeGet(
- { "command": "ping", "session": this.sessionID, "windowid" : window.name },
+ { "command": "ping", "session": this.sessionID, "windowid" : context.windowid },
function(data) {
if ( data.getElementsByTagName("status")[0]
.childNodes[0].nodeValue == "OK" ) {
"command": "search",
"query": this.currQuery,
"session": this.sessionID,
- "windowid" : window.name
+ "windowid" : this.windowid
};
if( sort !== undefined ) {
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" : context.windowid },
function(data) {
if ( data.getElementsByTagName("stat") ) {
var activeClients =
},
delay
);
- context.statCallback(stat);
+ context.statCallback(stat, context.windowid);
}
else
context.throwError('Stat failed. Malformed WS resonse.',
"sort": this.currentSort,
"block": 1,
"type": this.showResponseType,
- "windowid" : window.name
+ "windowid" : this.windowid
};
if (query_state)
requestParameters["query-state"] = query_state;
context.show();
},
delay);
- context.showCallback(show);
+ context.showCallback(show, context.windowid);
}
);
},
"command": "record",
"session": this.sessionID,
"id": this.currRecID,
- "windowid" : window.name
+ "windowid" : this.windowid
};
this.currRecOffset = null;
record = new Array();
record['xmlDoc'] = data;
record['offset'] = context.currRecOffset;
- callback(record, args);
+ callback(record, args, context.windowid);
//pz2 record
} else if ( recordNode =
data.getElementsByTagName("record")[0] ) {
},
delay
);
- callback(record, args);
+ callback(record, args, context.windowid);
}
else
context.throwError('Record failed. Malformed WS resonse.',
"command": "termlist",
"session": this.sessionID,
"name": this.termKeys,
- "windowid" : window.name,
+ "windowid" : this.windowid,
"version" : this.version
},
delay
);
- context.termlistCallback(termList);
+ context.termlistCallback(termList, context.windowid);
}
else
context.throwError('Termlist failed. Malformed WS resonse.',
"command": "bytarget",
"session": this.sessionID,
"block": 1,
- "windowid" : window.name,
+ "windowid" : this.windowid,
"version" : this.version
},
function(data) {
delay
);
- context.bytargetCallback(bytarget);
+ context.bytargetCallback(bytarget, context.windowid);
}
else
context.throwError('Bytarget failed. Malformed WS resonse.',
** 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.
}
_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;
},
_isCrossDomain: function (domain)
{
+ if (this.cookieDomain) return true; //assume xdomain is cookie domain set
return !this._strEndsWith(domain, document.domain);
},
}
}
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;
// 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;