/**
* windowName transport plugin 0.8.0-rc1 for jQuery
*
* Thanks to Kris Zyp
* for the original idea and some code
*
* Licensed under GPLv3: http://www.gnu.org/licenses/gpl-3.0.txt
* @author Marko Mrdjenovic
*
**/
(function () {
var $ = window.jQuery,
origAjax = $.ajax,
frameCounter = 0;
$.extend({
ajax: function (s) {
var remote = /^(?:\w+:)?\/\/([^\/?#]+)/,
data = '', status = '', requestDone = false,
xhr = null, type = null, ival = setTimeout(function () {}, 0),
onreadystatechange = null, success = null, complete = null,
localdom = remote.exec(s.url);
if (s.type === 'POST' && localdom && localdom[1] !== location.host) { // when posting to a remote location use window.name transport
xhr = function () {
var url = '',
frameName = '',
frame = '',
defaultName = 'jQuery.windowName.transport.frame',
u = null;
function cleanup() {
try {
delete window[frameName + '-callback'];
} catch (er) {
window[frameName + '-callback'] = function () {};
}
setTimeout(function () {
$(frame).remove();
}, 100);
}
function setData() {
try {
var data = frame.contentWindow.name;
if (typeof data === 'string') {
if (data === defaultName) {
u.status = 501;
u.statusText = 'Not Implemented';
} else {
u.status = 200;
u.statusText = 'OK';
u.responseText = data;
}
u.readyState = 4; // we are done now
u.onreadystatechange();
cleanup();
}
} catch (er) {}
}
u = {
abort: function () {
cleanup();
},
getAllResponseHeaders: function () {
return '';
},
getResponseHeader: function (key) {
return '';
},
open: function (m, u) {
url = u;
this.readyState = 1;
this.onreadystatechange();
},
send: function (data) {
// prepare frame
frameCounter += 1;
frameName = "jQuery.ajax.windowName." + ('' + Math.random()).substr(2, 8);
var form = document.createElement('form'),
ival = setTimeout(function () {}, 1);
frame = document.createElement($.browser.msie? '