diff options
author | Thomas BrĂ¼derli | 2007-08-28 14:18:50 +0000 |
---|---|---|
committer | Thomas BrĂ¼derli | 2007-08-28 14:18:50 +0000 |
commit | 549a1b6dc0e96bfd5ddebe752d031bd5ed883a92 (patch) | |
tree | c316104c5a432dbe7f707fafa689395e682e7b33 /itjs/loader.js | |
parent | ae17c5f249a6f8f810bd583ca022d6052d95400e (diff) | |
download | itools-549a1b6dc0e96bfd5ddebe752d031bd5ed883a92.tar.gz itools-549a1b6dc0e96bfd5ddebe752d031bd5ed883a92.tar.bz2 itools-549a1b6dc0e96bfd5ddebe752d031bd5ed883a92.zip |
Use <script> tags to enable data loading from foreign hosts
Diffstat (limited to 'itjs/loader.js')
-rw-r--r-- | itjs/loader.js | 41 |
1 files changed, 29 insertions, 12 deletions
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; + |