summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--itjs.class13
-rw-r--r--itjs/loader.js41
2 files changed, 39 insertions, 15 deletions
diff --git a/itjs.class b/itjs.class
index 86e9e86..22c5730 100644
--- a/itjs.class
+++ b/itjs.class
@@ -21,7 +21,7 @@ class itjs
*/
function send_headers()
{
- if (!preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']) && !$_REQUEST['itjs_call']) # text/plain breaks Opera 8.51/Linux and IFrame fallback
+ if (!preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']) && !$_REQUEST['itjs_iframe']) # text/plain breaks Opera 8.51/Linux and IFrame fallback
header('Content-Type: text/plain; charset=iso-8859-1'); # Berni reported some Firewalls to require this
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+10) . ' GMT'); # prevent broken data on IE reloads
@@ -37,8 +37,15 @@ function serialize($values)
{
if ($callback = it::replace(array('[^\w.]' => ""), $_REQUEST['itjs_call']))
{
- $header = "<script type='text/javascript'>$callback(";
- $footer = "," . intval($_REQUEST['itjs_callid']) . ")</script>";
+ $target = $_REQUEST['itjs_iframe'] ? "parent" : "window";
+ $header = "$target.it_loader && $target.$callback(";
+ $footer = "," . intval($_REQUEST['itjs_callid']) . ");";
+
+ if ($_REQUEST['itjs_iframe']) # iframe-based loading required by Opera 7
+ {
+ $header = '<script type="text/javascript">' . $header;
+ $footer .= "</script>";
+ }
}
return $header . itjs::encode($values) . $footer;
diff --git a/itjs/loader.js b/itjs/loader.js
index 2a29d8b..b5005ae 100644
--- a/itjs/loader.js
+++ b/itjs/loader.js
@@ -8,7 +8,7 @@ function it_loader(handler)
/* Clear cache etc. if completely new data */
this.loader = null;
this.handler = handler;
- this.name = "it_loader";
+ this.instance = it_loader.instances++;
this.callid = 0;
this.clear();
}
@@ -51,7 +51,7 @@ load: function(baseurl, pos, num, query_volatile, retry)
this.num = num;
this.query_volatile = query_volatile;
- if (this.loader)
+ if (this.loader && this.loader.stop)
this.stop();
while ((num > 0) && this.entry[pos])
@@ -70,7 +70,8 @@ load: function(baseurl, pos, num, query_volatile, retry)
try
{
- this.loader = new XMLHttpRequest();
+ if (!(baseurl.indexOf('http://') == 0 && baseurl.indexOf(window.location.hostname) < 0))
+ this.loader = new XMLHttpRequest();
}
catch (e)
{
@@ -110,23 +111,29 @@ load: function(baseurl, pos, num, query_volatile, retry)
}
else
{
-
- if (!this.iframe)
+ var req_url = baseurl + "&pos=" + pos + "&num=" + num + (query_volatile ? query_volatile : "") + (this.post_data ? '&' + this.post_data : "") + "&itjs_call=it_loader.__inst" + this.instance + ".dataReady&itjs_callid=" + ++this.callid;
+ if (window.opera && !window.XMLHttpRequest) // Opera 7 only works with iframes
{
- this.iframe = document.createElement("iframe");
- this.iframe.frameBorder = 0;
- this.iframe.style.width = this.iframe.style.height = 1;
- document.body.appendChild(this.iframe);
+ this.scrpt = document.createElement("iframe");
+ this.scrpt.style.width = this.scrpt.style.height = 1;
+ req_url += "&itjs_iframe=1";
}
+ else
+ this.scrpt = document.createElement("script");
+ it_loader['__inst'+this.instance] = this;
this.loader = { starttime: new Date().getTime(), retry: retry };
- var loaderinstance = this.name;
- window[loaderinstance] = this;
- this.iframe.src = baseurl + "&pos=" + pos + "&num=" + num + (query_volatile ? query_volatile : "") + '&itjs_call=parent.' + loaderinstance + '.dataReady&itjs_callid=' + ++this.callid;
+ try {
+ this.scrpt.src = req_url;
+ document.body.appendChild(this.scrpt);
+ }
+ catch (e) { return false; }
}
}
else
this.handler.render(this);
+
+ return true;
},
post: function(baseurl, data)
@@ -215,6 +222,12 @@ dataReady: function(data, callid)
if (!this.attr.eof && (this.end < this.pos + this.num))
this.load(this.baseurl, this.end, this.pos + this.num - this.end);
}
+
+ if (this.scrpt)
+ {
+ document.body.removeChild(this.scrpt);
+ this.scrpt = null;
+ }
},
stop: function()
@@ -229,3 +242,7 @@ stop: function()
}/* NO COMMA */
}
+
+// static properties
+it_loader.instances = 0;
+