Check-in Number:
|
26 | |
Date: |
2007-Apr-12 15:13:25 (local)
2007-Apr-12 13:13:25 (UTC) |
User: | rse |
Branch: | |
Comment: |
add XS AJAX jQuery plugin to ToT SVN
|
Tickets: |
|
Inspections: |
|
Files: |
|
Added: jquery/jquery.xsajax.js
===================================================================
--- jquery/jquery.xsajax.js (rev 0)
+++ jquery/jquery.xsajax.js 2007-04-12 13:13:25 UTC (rev 26)
@@ -0,0 +1,92 @@
+/*
+** jquery.xsajax.js -- jQuery plugin for Cross-Site AJAX
+** Copyright (c) 2007 Ralf S. Engelschall <rse@engelschall.com>
+** Licensed under GPL <http://www.gnu.org/licenses/gpl.txt>
+**
+** $LastChangedDate$
+** $LastChangedRevision$
+*/
+
+(function($){
+ $.extend({
+ getScriptXS: function () {
+ /* determine arguments */
+ var arg = {
+ 'url': null,
+ 'gc': true,
+ 'cb': null,
+ 'cb_args': null
+ };
+ if (typeof arguments[0] == "string") {
+ /* simple usage */
+ arg.url = arguments[0];
+ if (typeof arguments[1] == "function")
+ arg.cb = arguments[1];
+ }
+ else if (typeof arguments[0] == "object") {
+ /* flexible usage */
+ for (var option in arguments[0])
+ if (typeof arg[option] != "undefined")
+ arg[option] = arguments[0][option];
+ }
+
+ /* generate <script> node */
+ var node =
+ $(document.createElement('script'))
+ .attr('type', 'text/javascript')
+ .attr('src', arg.url);
+
+ /* optionally apply on-load handler for
+ garbage collecting <script> node after loading
+ or calling a custom callback function */
+ if (arg.gc || arg.cb !== null) {
+ var callback = function () {
+ if (arg.cb !== null) {
+ var args = arg.cb_args;
+ if (args === null)
+ args = [];
+ else if (!( typeof args === "object"
+ && args instanceof Array ))
+ args = [ args ];
+ arg.cb.apply(this, args);
+ }
+ if (arg.gc)
+ $(this).remove();
+ };
+ if ($.browser.msie) {
+ /* MSIE doesn't support the "onload" event on
+ <script> nodes, but it at least supports an
+ "onreadystatechange" event instead. But notice:
+ according to the MSDN documentation we would have
+ to look for the state "complete", but in practice
+ for <script> the state transitions from "loading"
+ to "loaded". So, we check for both here... */
+ node.get(0).onreadystatechange = function () {
+ if ( this.readyState == "complete"
+ || this.readyState == "loaded" )
+ callback.call(this);
+ };
+ }
+ else if ($.browser.safari) {
+ /* Apple Safari requires polling */
+ $.safariTimer = setInterval(function () {
+ if ( node.get(0).readyState == "complete"
+ || node.get(0).readyState == "loaded" ) {
+ clearInterval($.safariTimer);
+ $.safariTimer = null;
+ callback.call(node.get(0));
+ }
+ }, 100);
+ }
+ else {
+ /* use regular "onload" event for all other browsers */
+ $(node).load(callback);
+ }
+ }
+
+ /* inject <script> node into <head> of document */
+ $('head', document).append(node);
+ }
+ });
+})(jQuery);
+
Property changes on: jquery/jquery.xsajax.js
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+LastChangedDate LastChangedRevision
\ No newline at end of property
Added: jquery/jquery.xsajax.test.html
===================================================================
--- jquery/jquery.xsajax.test.html (rev 0)
+++ jquery/jquery.xsajax.test.html 2007-04-12 13:13:25 UTC (rev 26)
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title>jQuery XS AJAX Plugin Demo</title>
+ <script type="text/javascript" src="http://jquery.com/src/jquery-latest.pack.js"></script>
+ <script type="text/javascript" src="jquery.xsajax.js"></script>
+ </head>
+ <body>
+ <h1>jQuery XS AJAX Plugin Demo</h1>
+ output of script #1: <span id="output1">(none)</span><br/>
+ output of script #2: <span id="output2">(none)</span>
+ <p/>
+ <div id="logbook"></div>
+ <script type="text/javascript">
+ $(document).ready(function () {
+ $('div#logbook').append("1. start sequence<br/>");
+ $.getScriptXS({ url: "jquery.getscriptx.test1.js", cb: function(i) {
+ $('div#logbook').append("3. loaded script "+i+"<br/>");
+ }, cb_args: "1" });
+ $.getScriptXS({ url: "jquery.getscriptx.test2.js", cb: function(i) {
+ $('div#logbook').append("4. loaded script "+i+"<br/>");
+ }, cb_args: "2" });
+ $('div#logbook').append("2. end sequence<br/>");
+ });
+ </script>
+ </body>
+</html>
Added: jquery/jquery.xsajax.test1.js
===================================================================
--- jquery/jquery.xsajax.test1.js (rev 0)
+++ jquery/jquery.xsajax.test1.js 2007-04-12 13:13:25 UTC (rev 26)
@@ -0,0 +1,8 @@
+
+/* just produce some distinguishable output */
+$('span#output1').html("script #1 loaded");
+var i = 7;
+setInterval(function () {
+ $('span#output1').html("i=" + i++);
+}, 1000);
+
Added: jquery/jquery.xsajax.test2.js
===================================================================
--- jquery/jquery.xsajax.test2.js (rev 0)
+++ jquery/jquery.xsajax.test2.js 2007-04-12 13:13:25 UTC (rev 26)
@@ -0,0 +1,8 @@
+
+/* just produce some distinguishable output */
+$('span#output2').html("script #2 loaded");
+var j = 42;
+setInterval(function () {
+ $('span#output2').html("j=" + j++);
+}, 1000);
+