/trunk/dependencies/sajax/Changes.txt |
---|
0,0 → 1,69 |
SAJAX CHANGELOG |
--------------- |
Sajax version 0.13 (August 26, 2009) |
* [php] Use php native json_encode for serilization of responce data. |
* [php] use of JSON.parse on client side for better speed and security. |
* [php] per function GET/POST |
* [php] Autoselect POST if request is to large data for GET |
* [php] Synchronous mode |
* [php] gratly improved error handeling on both client and server side |
* [php] Support for utf-8 and international charectors |
* [php] Better handeling of IE (no more warnings in IE7+) |
* [cf] Updated to match the PHP implementation. |
Sajax version 0.12 (January 30, 2006) |
* [php] Numerous improvements to serialization, support for varied PHP |
setups, addition of sajax_cancel(). |
* [asp] Removed due to serious bugs |
Sajax version 0.11 () Unreleased beta. |
Sajax version 0.10 (March 21, 2005) |
* [php] Support for POST instead of just GET. Set $sajax_request_type. |
Based on code from Folletto Malefico, to whom I owe thanks. |
POST mode should be used if you are sending long requests (more |
than 512 bytes) or if you are modifying data with the request. |
* [php] (untested) Support for GET/POST to pages other than $REQUEST_URI. |
Set $sajax_remote_uri to the desired URL to get this behavior. |
* [php] Small fixes to the Wall example, thanks to Leonardo Lorieri |
and Jesse Sightler. |
* [cf] Cold Fusion MX support (Thanks Eric Moritz) |
* [asp] ASP support (Thanks Jared Nuzzolillo) |
* [python] Improvements to the Python backend from Adam Collard |
Sajax version 0.9 (March 15, 2005) |
* [php] Major changes to the PHP backend: |
* [php] Renamed incl_sajax.php to Sajax.php to fit PEAR and other language |
naming conventions |
* [php] Functions and vars previously named rs_* are now sajax_* |
* [php] Function stubs all call one generalized sajax_do_call() dispatcher |
* [php] Added non-echoing version of sajax_echo_javascript() called |
sajax_get_javascript via the magic of output buffering |
* [php] Changed all examples to support new framework |
* [perl] Applied fix for URL encoding of space (Thanks Max Maischein) |
* [ruby] Added Ruby backend contributed by anonymous author |
* [io] Added Io (http://www.iolanguage.com/) backend by Sajax team @ MM |
Sajax version 0.8 (March 9, 2005) |
* [php] Bug in the long-open-tags changes. Thanks to Matthew M. Vince. |
* [lua] Backend port added. Thanks to Javier Guerra. |
Sajax version 0.7 (March 9, 2005) |
* [php] Major bug calling remote functions without args. |
Sajax version 0.6 (March 8, 2005) |
* Layout of archive changed; base folder changed; subfolders added for backends |
* [php] Used short open tags by default. Thanks to Matthew M. Vince. |
* [perl] Backend port added. Thanks to Nathan Schmidt, Jason Purdy and Nate |
Mueller. |
* [python] Backend port added. Thanks to Adam Collard. Please note that |
this port is licensed under the Creative Commons "By" License version |
2.0. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/Known issues.txt |
---|
0,0 → 1,13 |
iCab 3.0.5 will fail badly when using json_parse_state and receving large stings. |
IE 5.01 will fail nicly when using json_parse. |
Safari 1.2 will send malformed data when using json2.stringify and sending numberes as strings. |
Prototype 1.5.1 and later, 1.6.0.3 is the latest at this point, breaks firefox's JSON.stringify(), a workaround for this is to use the methode provided by Prototype instead, to this, include the folowing code just after you load prototype.js |
<script type="text/javascript"><!-- |
var JSON = JSON || {}; |
JSON.stringify = function(value) { return value.toJSON(); }; |
JSON.parse = JSON.parse || function(jsonsring) { return jsonsring.evalJSON(true); }; |
//--> |
</script> |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/Old browsers.txt |
---|
0,0 → 1,10 |
Mozila 0.6 - 0.9.2 might be posible to geat to work but may requre major rewrite as it does not support x.readyState or x.onreadystatechange and probably othere parts of XMLHttpRequest, an alternative would be using iframe's. Also JSON.stringify() seams to fail for it. |
IE 4 is also posible but it requres removing all try{} catch(e) {} from the code, only using 'Microsoft.XMLHTTP' for IE6, IE5.5, IE5 and IE4 and having less error handeling. and might break support for othere browsers and or functionality. In addition I think it would requre some special case of installed updates on the client end. If you do get it to work feel free to end us the code and we will include it in this file for the next version of Sajax. |
iCab 3.0 - 3.0.4 are untested, please report your results. |
Google Chrom is untested except for 2.0.172.39 |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/Readme.txt |
---|
0,0 → 1,27 |
WELCOME TO SAJAX |
---------------- |
Sajax is a cross-platform, cross-browser web scripting toolkit |
that makes it easy to expose functions in your code to JavaScript. |
For more information about Sajax, please see the homepage: |
http://sajax.info/ |
In this archive you will find a folder for each platform that is |
currently supported. Please see individual documentation in each |
folder for specific errata. |
As of 0.13 a JavaScript implementation of JSON.stringify() has |
become a requirement when sending data for browsers that does not |
have this nativly (IE8 or FF3.5). JSON2 from |
http://www.json.org/js.html has been included for this reason. |
It is highly recomented to also include a JSON.parse() |
implementation for better security for the client, especialy when |
handeling data from othere sites, json.parse.js is the |
implementation from JSON2, unfortunatly this breaks Safari 1.3.2 |
json_parse_state.js seams to be the most compatible but |
json_parse.js might also be worth checking out. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/Todo.txt |
---|
0,0 → 1,24 |
SAJAX TO DO LIST |
---------------- |
* Fix http://www.modernmethod.com/sajax/forum/viewtopic.php?p=308 |
* Make the whole darn thing an object |
* Add J2EE module |
* Apply Julien Grossiord's port non-80 patch. |
* Apply Steve Smith (ND)'s ColdFusion POST patch. |
* Better whitespace handling |
* Test if a function exists before allowing you to export it |
* Add Kae's IFRAME patch. |
* Add C# support. |
* Update othere backends to match php in 0.13. |
THINGS THAT WERE TO DO AND ARE NOW TO DONE |
------------------------------------------ |
* All-numeric array indices -> JS array, not object. |
* Encode/serialize array elements |
* Return false if the object could not be created. |
* Support for "options" such as post-to-an-ID and POST/GET submit. |
* Added sajax_set_remote_url or something along those lines instead of |
$REQUEST_URI |
* Support POST |
* Add CFML, ASP.Net |
* Fix Perl module (with the contributed code) |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/asp/Readme.txt |
---|
0,0 → 1,3 |
ASP support has been temporarily removed due to bugs. It will be back soon. |
- tlack |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/asp/example_multiply.asp |
---|
0,0 → 1,77 |
<%@ Language=JScript %> |
<!--#include file="sajax.asp"--> |
<% |
function multiply(x, y) { |
return x * y; |
} |
function add(x, y, z) { |
return x + y + z; |
} |
sajax = new Sajax(); |
// sajax.debug_mode = true; |
sajax.export_function("multiply","add"); |
sajax.handle_client_request(); |
%> |
<html> |
<head> |
<title>Multiplier</title> |
<script> |
<% |
sajax.show_javascript(); |
%> |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
// get the folder name |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_multiply(x, y, do_multiply_cb); |
} |
function do_add_cb(z) { |
document.getElementById("zza").value = z; |
} |
function do_add() { |
// get the folder name |
var x, y, z; |
x = "'"+document.getElementById("xa").value+"'"; |
y = "'"+document.getElementById("ya").value+"'"; |
z = "'"+document.getElementById("za").value+"'"; |
x_add(x, y, z, do_add_cb); |
} |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3"> |
* |
<input type="text" name="y" id="y" value="3" size="3"> |
= |
<input type="text" name="z" id="z" value="" size="3"> |
<input type="button" name="check" value="Calculate" |
onclick="do_multiply(); return false;"> |
<br> |
try adding some strings, eg: |
<input type="text" name="xa" id="xa" value="ex " size="3"> |
+ |
<input type="text" name="ya" id="ya" value="nihil, " size="3"> |
+ |
<input type="text" name="za" id="za" value="nihil fit" size="3"> |
= |
<input type="text" name="zza" id="zza" value="" size="15"> |
<input type="button" name="check" value="Calculate" |
onclick="do_add(); return false;"> |
</body> |
</html> |
/trunk/dependencies/sajax/asp/sajax.asp |
---|
0,0 → 1,186 |
<% |
function r(str) |
{ |
Response.write("<br>-"+str+"-<br>") |
} |
function Sajax(debug_mode) |
{ |
this.debug_mode = debug_mode||false; |
this.export_list = []; |
this.js_has_been_shown = false; |
this.handle_client_request = function() |
{ |
func_name = Request.QueryString("rs"); |
if(!func_name||String(func_name)=="undefined") return false |
//bust cache |
Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT") |
//always modified |
Response.AddHeader("Last-Modified", new Date().toGMTString().replace(/UTC/,"GMT")) |
//HTTP/1.1 |
Response.AddHeader("Cache-Control", "no-cache, must-revalidate") |
//HTTP/1.0 |
Response.AddHeader("Pragma", "no-cache") |
if(this.export_list[func_name]=="undefined") |
{ |
result = "-"+func_name+" is not callable"; |
//if(this.debug_mode) Response.write("-"+func_name+" is not callable"); |
} |
else |
{ |
rsargs_raw = Request.QueryString("rsargs[]") |
rsargs = [] |
for(rs_i=1;rs_i<=rsargs_raw.Count;rs_i++) |
{ |
rsargs[rs_i-1]=rsargs_raw(rs_i) |
} |
// if(this.debug_mode) Response.write("calling " + func_name + "(" + |
// rsargs.join(",")+")") |
eval_str = this.export_list[func_name]+"("+rsargs+")" |
try |
{ |
result = "+"+eval(eval_str); |
} |
catch(e) |
{ |
result = "-"+e.message+" (x_"+eval_str+")"; |
} |
} |
Response.write(result+"[sajax_result________end]]") |
//exit() |
} |
this.show_common_js = function() |
{ |
js_debug_mode = this.debug_mode |
js_string_out = " // remote scripting library\n" + |
" // (c) copyright 2005 modernmethod, inc\n" + |
" var rs_debug_mode = "+js_debug_mode+";\n" + |
" var rs_obj = false;\n" + |
" var rs_callback = false;\n" + |
" \n" + |
" function rs_debug(text) {\n" + |
" if (rs_debug_mode)\n" + |
" alert('RSD: ' + text)\n" + |
" }\n" + |
" \n" + |
" function rs_init_object() {\n" + |
" rs_debug('rs_init_object() called..')\n" + |
" \n" + |
" var A;\n" + |
" try {\n" + |
" A=new ActiveXObject('Msxml2.XMLHTTP');\n" + |
" } catch (e) {\n" + |
" try {\n" + |
" A=new ActiveXObject('Microsoft.XMLHTTP');\n" + |
" } catch (oc) {\n" + |
" A=null;\n" + |
" }\n" + |
" }\n" + |
" if(!A && typeof XMLHttpRequest != 'undefined')\n" + |
" A = new XMLHttpRequest();\n" + |
" if (!A)\n" + |
" rs_debug('Could not create connection object.');\n" + |
" return A;\n" + |
" }\n" |
Response.write(js_string_out) |
} |
this.rs_esc=function(val) |
{ |
} |
this.export_function = function() |
{ |
for(var i=0;i<arguments.length;i++) |
{ |
this.export_list[arguments[i]] = arguments[i]; |
} |
} |
this.show_javascript = function() |
{ |
if(!this.js_has_been_shown) |
{ |
this.show_common_js() |
this.js_has_been_shown = true |
} |
for(func_name in this.export_list) |
{ |
this.show_one(func_name); |
} |
} |
this.rs_esc = function(val) |
{ |
var dqex = /\"/g //" |
return val.replace(dqex, '\\\\"') |
} |
this.show_one=function(func_name) |
{ |
var svr, srl, qsr; |
svr = Request.ServerVariables("SERVER_NAME") |
srl = Request.ServerVariables("URL") |
qsr = Request.ServerVariables("QUERY_STRING"); |
uri = svr + srl + qsr; |
if(!(uri.indexOf('?')>-1)) |
{ |
uri += "?rs=" + escape(func_name) |
} |
else |
{ |
uri += "&rs=" + escape(func_name) |
} |
escapeduri = this.rs_esc(uri) |
js_string_out = " // wrapper for "+func_name+"\n" + |
" function x_"+func_name+"(){\n" + |
" // count args; build URL\n" + |
" var i, x, n;\n" + |
" //var url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" + |
" url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" + |
" for (i = 0; i < a.length-1; i++)\n" + |
" url = url + '&rsargs[]=' + escape(a[i]);\n" + |
" x = rs_init_object();\n" + |
" x.open('GET', url, true);\n" + |
" x.onreadystatechange = function() {\n" + |
" if (x.readyState != 4)\n" + |
" return;\n" + |
" rs_debug('received ' + x.responseText);\n" + |
" \n" + |
" var status;\n" + |
" var data;\n" + |
" status = x.responseText.charAt(0);\n" + |
" data = x.responseText;\n" + |
" var pos = data.indexOf('[sajax_result________end]]');\n " + |
" if (status == '-'){\n" + |
" if("+this.debug_mode+"){alert('Error: ' + data.substring(1,pos));}}\n" + |
" else \n" + |
" a[a.length-1](data.substring(1,pos));\n" + |
" }\n" + |
" x.send(null);\n" + |
" rs_debug('x_"+func_name+" url = ' + url);\n" + |
" rs_debug('x_"+func_name+" waiting..');\n" + |
" }\n" |
Response.write(js_string_out) |
} |
} |
%> |
/trunk/dependencies/sajax/coldfusion/Readme.txt |
---|
0,0 → 1,4 |
SAJAX COLDFUSION MX BACKEND |
--------------------------- |
Contributed by Eric Moritz <eric.moritz@gmail.com>. Maintained by Steve Smith <steve@orderedlist.com> and Anders Jenbo <anders@jenbo.dk> |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/example_multiply.cfm |
---|
0,0 → 1,48 |
<cfinclude template="sajax.cfm"> |
<cfscript> |
function multiply(x, y) { |
return x * y; |
} |
// sajax_debug_mode = true; |
sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
sajax_export("multiply"); |
sajax_handle_client_request(); |
</cfscript> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>Sajax Multiplier example</title> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<cfscript>sajax_show_javascript();</cfscript> |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
// get the folder name |
var x, y; |
x = parseFloat(document.getElementById("x").value); |
y = parseFloat(document.getElementById("y").value); |
x_multiply(x, y, do_multiply_cb); |
} |
//--> |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3" /> |
* |
<input type="text" name="y" id="y" value="3" size="3" /> |
= |
<input type="text" name="z" id="z" value="" size="3" /> |
<input type="button" name="check" value="Calculate" onclick="do_multiply(); return false;" /> |
</body> |
</html> |
/trunk/dependencies/sajax/coldfusion/example_options.cfm |
---|
0,0 → 1,100 |
<cfinclude template="sajax.cfm"> |
<cfscript> |
function test_get() { |
return test(); |
} |
function test_post() { |
return test(); |
} |
function test() { |
s = "URI: example_options.cfm"; |
s = "#s# |
-- GET -- |
"; |
if(isdefined("URL.rsargs")) |
s = "#s##URL.rsargs#"; |
s = "#s# |
-- POST -- |
"; |
if(isdefined("FORM.rsargs")) |
s = "#s##FORM.rsargs#"; |
return s; |
} |
function get_the_time() { |
return "#DateFormat(now(),"yyyy-mm-dd ")##TimeFormat(now() ,"HH:mm:ss")#"; |
} |
function pause(sec) { |
thread = CreateObject("java", "java.lang.Thread"); |
thread.sleep(sec*1000); |
} |
// $sajax_debug_mode = true; |
//GET functions |
sajax_request_type = "GET"; |
sajax_export("test_get", "get_the_time", "test", "otherefucntion2"); |
//POST functions |
sajax_request_type = "POST"; |
sajax_export("test_post"); |
//synchronous GET functions |
sajax_request_type = "GET"; |
sajax_request_asynchronous = "false"; |
sajax_export("pause"); |
//GET functions from a different uri |
sajax_request_type = "GET"; |
sajax_remote_uri = "example_otheruri.cfm"; |
sajax_export("otherefucntion"); |
sajax_handle_client_request(); |
</cfscript> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>Example of Sajax Options</title> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<cfscript>sajax_show_javascript();</cfscript> |
function print_result(v) { |
alert(v); |
} |
//--> |
</script> |
</head> |
<body> |
<!-- Testing if the browser supports GET --> |
<button onclick="x_test_get(1, 2, 3, print_result);">Test GET</button> |
<!-- Testing if the browser supports POST --> |
<button onclick="x_test_post(1, 2, 3, print_result);">Test POST</button> |
<!-- Forcing the function to POST --> |
<button onclick="sajax_request_type ='POST'; x_test(1, 2, 3, print_result); sajax_request_type ='';">Test force POST</button> |
<!-- if sajax_target_id is set, the sesponce will be inserted as HTML in an element with sajax_target_id for id--> |
<button onclick="sajax_target_id = 'time'; x_get_the_time(); sajax_target_id = '';">Test updating IDs</button> |
<!-- Calling a synchronous will cause the script to wait for the responce --> |
<button onclick="x_pause(3, function(){}); alert('Link was clicked!');">Test synchronous</button> |
<!-- Different URI set at config --> |
<button onclick="x_otherefucntion(print_result);">Call to other uri.</button> |
<!-- Forece different URI at runtime --> |
<button onclick="sajax_remote_uri = 'example_otheruri.cfm'; x_otherefucntion2(print_result); sajax_remote_uri = '';">Force call to other uri.</button> |
<div id="time"><em>Time will appear here</em></div> |
</body> |
</html> |
/trunk/dependencies/sajax/coldfusion/example_otheruri.cfm |
---|
0,0 → 1,15 |
<cfinclude template="sajax.cfm"> |
<cfscript> |
function otherefucntion() { |
return "URI: example_otheruri.cfm"; |
} |
function otherefucntion2() { |
return otherefucntion(); |
} |
//allowed functions |
sajax_export("otherefucntion", "otherefucntion2"); |
sajax_handle_client_request(); |
</cfscript> |
/trunk/dependencies/sajax/coldfusion/example_types.cfm |
---|
0,0 → 1,75 |
<cfinclude template="sajax.cfm"> |
<cfscript> |
bday = "9/5/1983"; |
age = DateFormat(now(), "yyyy")-DateFormat(bday, "yyyy")-(DateFormat(bday, "m.dd")-DateFormat(now(), "m.dd"))/10; |
function return_struct() { |
struct = structNew(); |
struct["name"] = "Anders"; |
struct["age"] = age; |
return struct; |
} |
function return_list() { |
list = ""; |
list = listappend(list, "Anders"); |
list = listappend(list, age); |
return list; |
} |
function return_float() { |
return age; |
} |
function return_int() { |
return int(age); |
} |
function return_string() { |
return "Anders is #int(age)# years old."; |
} |
sajax_request_type = "GET"; |
// sajax_debug_mode = true; |
sajax_export("return_struct", "return_list", "return_int", "return_float", "return_string"); |
sajax_handle_client_request(); |
</cfscript> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<title>Sajax ColdFusion return types example</title> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<cfscript>sajax_show_javascript();</cfscript> |
function display_result(val) { |
var repr; |
repr = ""; |
repr += "Type: " + typeof val + "\n"; |
repr += "Value: "; |
if (typeof val == "object" || |
typeof val == "array") { |
repr += "{ "; |
for (var i in val) |
repr += i + ": " + val[i] + ", "; |
repr = repr.substr(0, repr.length-2) + " }"; |
} else { |
repr += val; |
} |
alert(repr); |
} |
//--> |
</script> |
</head> |
<body> |
<button onclick="x_return_struct(display_result);">Return as struct (will become an object)</button> |
<button onclick="x_return_list(display_result);">Return as list (will become a string)</button> |
<button onclick="x_return_int(display_result);">Return as int</button> |
<button onclick="x_return_float(display_result);">Return as float/double</button> |
<button onclick="x_return_string(display_result);">Return as string</button> |
</body> |
</html> |
/trunk/dependencies/sajax/coldfusion/json2.parse.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/json2.stringify.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/json_parse.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/json_parse_state.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/json_stringify.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/coldfusion/sajax.cfm |
---|
0,0 → 1,148 |
<cfsilent> |
<cfset sajax_version = "0.13"> |
<cfset sajax_debug_mode = false> |
<cfset sajax_export_array = arraynew(1)> |
<cfset sajax_export_list = ""> |
<cfset sajax_method_list = ""> |
<cfset sajax_asynchronous_list = ""> |
<cfset sajax_uri_list = ""> |
<cfset sajax_remote_uri = ""> |
<cfset sajax_failure_redirect = ""> |
<cfset sajax_request_type = "GET"> |
<cfset sajax_request_asynchronous = "true"> |
<!--- Always call server if this is a Sajax GET call ---> |
<cfif isdefined("URL.rs")> |
<cfheader name="Cache-Control" value="max-age=0, must-revalidate"> |
<cfheader name="Pragma" value="no-cache"> |
</cfif> |
<!--- emulate the php exit keyword ---> |
<cffunction name="exit"> |
<cfabort> |
</cffunction> |
<cffunction name="sajax_handle_client_request"> |
<cftry> |
<cfsavecontent variable="output"> |
<cfscript> |
if(not isdefined("URL.rs") and not isdefined("FORM.rs")) |
return; |
if(isdefined("URL.rs")) { |
func_name = URL.rs; |
if(isdefined("URL.rsargs")) |
args = URL.rsargs; |
} else { |
func_name = FORM.rs; |
if(isdefined("FORM.rsargs")) |
args = FORM.rsargs; |
} |
if(isdefined("args")) { |
args = DeserializeJSON(args); |
} else { |
args = arraynew(1); |
} |
if(not ListFindNoCase(sajax_export_list, func_name)) { |
error = "#func_name# not callable"; |
} else { |
result = SerializeJSON(call_user_func_array(func_name, args)); |
} |
</cfscript> |
</cfsavecontent> |
<cfcatch> |
<cfheader name="Content-Type" value="text/plain; charset=UTF-8"> |
<cfoutput>-:#cfcatch.type# |
#cfcatch.message# |
#cfcatch.detail# |
<cfif arraylen(cfcatch.tagcontext) gt 0> |
in #cfcatch.tagcontext[1].template# at #cfcatch.tagcontext[1].line# |
</cfif> |
</cfoutput> |
<cfabort> |
</cfcatch> |
</cftry> |
<cfheader name="Content-Type" value="text/plain; charset=UTF-8"> |
<cfscript> |
//Remove start and end white space from output |
output = REReplace(output,"^\s*|\s*$","","ALL"); |
if(isdefined("result") and "#output#" eq "") |
writeoutput("+:#result#"); |
else if("#output#" eq "") |
writeoutput("-:#error#"); |
else |
writeoutput("-:#output#"); |
exit(); |
</cfscript> |
</cffunction> |
<cfscript> |
sajax_js_has_been_shown = false; |
function sajax_show_javascript() |
{ |
if (not sajax_js_has_been_shown) { |
writeoutput(" |
sajax_debug_mode = #iif(sajax_debug_mode, 'true', 'false')#; |
sajax_failure_redirect = ""#sajax_failure_redirect#""; |
"); |
//TODO get from an array instead of list |
size = listlen(sajax_export_list); |
for(i = 1; i lte size; i=i+1) { |
name = listgetat(sajax_export_list, i); |
method = listgetat(sajax_method_list, i); |
asynchronous = listgetat(sajax_asynchronous_list, i); |
uri = listgetat(sajax_uri_list, i); |
if(uri == "##") |
uri = ""; |
writeoutput(" |
function x_#name#() { |
return sajax_do_call(""#name#"", arguments, ""#method#"", #asynchronous#, ""#uri#""); |
}"); |
} |
sajax_js_has_been_shown = true; |
} |
} |
function sajax_export() { |
//TODO make it a multi dimentional array of options |
//TODO prevent multiple instances of the same functions |
//if(not isarray(function)) |
var keys = structkeylist(arguments); |
var size = listlen(keys); |
var key = ""; |
for(i=1; i lte size;i=i+1) { |
key = listgetat(keys, i); |
sajax_export_list = listappend(sajax_export_list, arguments[key]); |
sajax_method_list = listappend(sajax_method_list, sajax_request_type); |
sajax_asynchronous_list = listappend(sajax_asynchronous_list, sajax_request_asynchronous); |
if(sajax_remote_uri == "") |
sajax_remote_uri = "##"; |
sajax_uri_list = listappend(sajax_uri_list, sajax_remote_uri); |
if(sajax_remote_uri == "##") |
sajax_remote_uri = ""; |
} |
} |
function call_user_func_array(user_func, arg_array) { |
//TODO test with multi dimentional arrays |
var func_call = ""; |
var func_args = ""; |
var size = ArrayLen(arg_array); |
/* Loop though each of the args */ |
for(i=1; i lte size; i = i + 1) { |
func_args = func_args & "arg_array[#i#]"; |
if(i lt size) |
func_args = func_args & ","; |
} |
return evaluate("#user_func#(#func_args#)"); |
} |
SAJAX_INCLUDED = 1; |
</cfscript> |
</cfsilent> |
/trunk/dependencies/sajax/coldfusion/sajax.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/io/Sajax.io |
---|
0,0 → 1,203 |
// |
// Sajax Io Backend |
// (C) Copyright 2005 ModernMethod, Inc. |
// Released under BSD license |
// |
String interpolate := method( |
work := self clone |
last_idx := 0 |
while (1, |
idx := work find("<?io", last_idx) |
if (idx == Nil, |
// no more interps.. |
break) |
idx := idx + 3 |
end_idx := work find("?>", idx + 1) |
if (end_idx == Nil, |
// invalid interp expression.. we're done. |
break) |
// in the case of an empty interpolated expression, |
// lets move on |
if (end_idx - idx == 1, |
continue) |
// otherwise proceed with replacement. |
slotName := work substring(idx+1, end_idx) |
find_str := "<?io" .. slotName .. "?>" |
// write("doString(" .. slotName .. ")") |
replace_str := sender doString(slotName) |
work := work replace(find_str, replace_str) |
last_idx = end_idx + 1 |
) |
return work |
) |
Sajax := Object clone do ( |
debug_mode := 0 |
export_list := List clone |
js_has_been_shown := Nil |
init := method( |
return self |
) |
handle_client_request := method( |
if (my_getenv("QUERY_STRING") == Nil, |
return |
) |
form := CGI clone parse |
if (form hasKey("rs") == Nil, |
return |
) |
write("Content-type: text/html\n"); |
write("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); |
write("Cache-Control: no-cache, must-revalidate\n"); |
write("Pragma: no-cache\n\n"); |
func_name := form at("rs") |
if (export_list contains(func_name) == Nil) then ( |
write("-:$func_name not callable\n") |
) else ( |
write("+:") |
args := form at("rsargs[]") |
result := sender performWithArgList(func_name, args) |
write(result) |
) |
exit; |
} |
show_common_js := method( |
if (debug_mode == 1, |
debugModeTrueFalse := "true", |
debugModeTrueFalse := "false") |
html := """ |
// remote scripting library |
// (c) copyright 2005 modernmethod, inc |
var rs_debug_mode = <?io debugModeTrueFalse ?>; |
function rs_debug(text) { |
if (rs_debug_mode) |
alert("RSD: " + text) |
} |
function rs_init_object() { |
rs_debug("rs_init_object() called..") |
var A; |
try { |
A=new ActiveXObject("Msxml2.XMLHTTP"); |
} catch (e) { |
try { |
A=new ActiveXObject("Microsoft.XMLHTTP"); |
} catch (oc) { |
A=null; |
} |
} |
if(!A && typeof XMLHttpRequest != "undefined") |
A = new XMLHttpRequest(); |
if (!A) |
rs_debug("Could not create connection object."); |
return A; |
} |
""" |
write(html interpolate) |
} |
esc := method(val, |
return val replace("\"", "\\\\\""); |
) |
my_getenv := method(val, |
my_get := Nil |
if (?System) then ( |
my_get := System getSlot("getenv") |
) else ( |
my_get := Object getSlot("getenv") |
) |
return my_get(val) |
) |
get_my_uri := method( |
uri := "http://www.example.com/" |
if (my_getenv("REQUEST_URI") != Nil) then ( |
uri := my_getenv("REQUEST_URI") |
) else ( |
if (my_getenv("SCRIPT_NAME") != Nil) then ( |
uri := my_getenv("SCRIPT_NAME") |
if (my_getenv("QUERY_STRING") != Nil) then ( |
uri := uri .. "?" .. my_getenv("QUERY_STRING") |
) |
) |
) |
return uri |
) |
show_one := method(func_name, |
uri := get_my_uri |
func_name_encoded := CGI encodeUrlParam(func_name) |
if (uri contains("?") == Nil) then ( |
uri = uri .. "?rs=" .. func_name_encoded |
) else ( |
uri = uri .. "&rs=" .. func_name_encoded |
) |
html := """ |
// wrapper for <?io func_name ?> |
function x_<?io func_name ?>() { |
// count args; build URL |
var i, x, n; |
var url = "<?io esc(uri) ?>"; |
var a = x_<?io func_name ?>.arguments; |
for (i = 0; i < a.length-1; i++) |
url = url + "&rsargs[]=" + escape(a[i]); |
url = url + "&rsrnd=" + new Date().getTime(); |
x = rs_init_object(); |
x.open("GET", url, true); |
x.onreadystatechange = function() { |
if (x.readyState != 4) |
return; |
rs_debug("received " + x.responseText); |
var status; |
var data; |
status = x.responseText.charAt(0); |
data = x.responseText.substring(2); |
if (status == "-") |
alert("Error: " + callback_n); |
else |
a[a.length-1](data); |
} |
x.send(null); |
rs_debug("x_<?io func_name ?> url = " + url); |
rs_debug("x_<?io func_name ?> waiting.."); |
delete x; |
} |
""" |
write(html interpolate) |
) |
export := method(func, |
export_list add(func) |
} |
show_javascript := method( |
if (js_has_been_shown == Nil, |
show_common_js |
) |
export_list foreach(index, func_name, |
show_one(func_name) |
) |
) |
) |
/trunk/dependencies/sajax/io/example_multiply.io |
---|
0,0 → 1,53 |
#!/usr/bin/env ioServer |
c := CGI clone |
multiply := method(x, y, |
x := x asNumber |
y := y asNumber |
return x * y |
) |
s := Sajax clone |
s debug_mode := 1 |
s init |
s export("multiply") |
s handle_client_request |
write("Content-type: text/html\n\n") |
html := """ |
<html> |
<head> |
<title>Multiplier</title> |
<script>""" |
write(html) |
s show_javascript |
html := """ |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
// get the folder name |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_multiply(x, y, do_multiply_cb); |
} |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3"> |
* |
<input type="text" name="y" id="y" value="3" size="3"> |
= |
<input type="text" name="z" id="z" value="" size="3"> |
<input type="button" name="check" value="Calculate" |
onclick="do_multiply(); return false;"> |
</body> |
</html> |
""" |
write(html) |
/trunk/dependencies/sajax/lua/Readme.txt |
---|
0,0 → 1,6 |
SAJAX LUA BACKEND |
----------------- |
Contributed and copyighted by Javier Guerra (http://www.guerrag.com/). |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/lua/calculator.lp |
---|
0,0 → 1,46 |
<% |
require "sajax" |
function multiply(x, y) |
return x * y |
end |
sajax.init() |
-- $rs_debug_mode = 1; |
sajax.export ("multiply", multiply) |
if sajax.handle_client_request () then return end |
%><html> |
<head> |
<title>Multiplier</title> |
<script> |
<% |
sajax.show_javascript(); |
%> |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
// get the folder name |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_multiply(x, y, do_multiply_cb); |
} |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3"> |
* |
<input type="text" name="y" id="y" value="3" size="3"> |
= |
<input type="text" name="z" id="z" value="" size="3"> |
<input type="button" name="check" value="Calculate" |
onclick="do_multiply(); return false;"> |
</body> |
</html> |
/trunk/dependencies/sajax/lua/sajax.lua |
---|
0,0 → 1,135 |
module ("sajax") |
local export_list = {} |
local request_uri = "" |
function init () |
end |
function handle_client_request () |
if not cgi.rs then return end |
-- Bust cache in the head |
cgilua.header ("Expires", "Mon, 26 Jul 1997 05:00:00 GMT") -- Date in the past |
cgilua.header ("Last-Modified", os.date ("!%a, %d %b %Y %H:%M:%S GMT")) |
-- always modified |
cgilua.header ("Cache-Control", "no-cache, must-revalidate") -- HTTP/1.1 |
cgilua.header ("Pragma", "no-cache") -- HTTP/1.0 |
local funcname = cgi.rs |
if not export_list[funcname] then |
cgilua.put (string.format ("-:%s not callable", funcname)) |
else |
local func = export_list[funcname] |
local rsargs = cgi["rsargs[]"] |
local result |
if not rsargs then |
result = func() |
elseif type (rsargs) == "string" then |
result = func (rsargs) |
elseif type (rsargs) == "table" then |
result = func (unpack (rsargs)) |
else |
return |
end |
cgilua.put ("+:") |
cgilua.put (result) |
end |
return true |
end |
local function show_common_js () |
cgilua.put [[ |
// remote scripting library |
// (c) copyright 2005 modernmethod, inc |
var rs_debug_mode = false; |
function rs_debug(text) { |
if (rs_debug_mode) |
alert("RSD: " + text) |
} |
function rs_init_object() { |
rs_debug("rs_init_object() called..") |
var A; |
try { |
A=new ActiveXObject("Msxml2.XMLHTTP"); |
} catch (e) { |
try { |
A=new ActiveXObject("Microsoft.XMLHTTP"); |
} catch (oc) { |
A=null; |
} |
} |
if(!A && typeof XMLHttpRequest != "undefined") |
A = new XMLHttpRequest(); |
if (!A) |
rs_debug("Could not create connection object."); |
return A; |
} |
]] |
end |
local function show_one (funcname) |
local uri = request_uri |
if string.find (uri, "?") then |
uri = uri .. "&rs=" .. cgilua.urlcode.escape (funcname) |
else |
uri = uri .. "?rs=" .. cgilua.urlcode.escape (funcname) |
end |
cgilua.put (string.format ([[ |
// wrapper for %s |
function x_%s() { |
// count args; build URL |
var i, x, n; |
var url = "%s"; |
var a = x_%s.arguments; |
for (i = 0; i < a.length-1; i++) |
url = url + "&rsargs[]=" + escape(a[i]); |
url = url + "&rsrnd=" + new Date().getTime(); |
x = rs_init_object(); |
x.open("GET", url, true); |
x.onreadystatechange = function() { |
if (x.readyState != 4) |
return; |
rs_debug("received " + x.responseText); |
var status; |
var data; |
status = x.responseText.charAt(0); |
data = x.responseText.substring(2); |
if (status == "-") |
alert("Error: " + callback_n); |
else |
a[a.length-1](data); |
} |
x.send(null); |
rs_debug("x_%s url = " + url); |
rs_debug("x_%s waiting.."); |
delete x; |
} |
]], funcname, funcname, uri, funcname, funcname, funcname)) |
end |
function export (funcname, func) |
export_list[funcname] = func |
end |
local js_has_been_shown = false |
function show_javascript () |
if not js_has_been_shown then |
show_common_js () |
js_has_been_shown = true |
end |
for fn,_ in pairs (export_list) do |
show_one (fn) |
end |
end |
/trunk/dependencies/sajax/perl/Readme.txt |
---|
0,0 → 1,7 |
SAJAX PERL BACKEND |
------------------ |
Contributed and copyighted by Nathan Schmidt (http://www.hinathan.com/). |
Additional guidance and consultation by Jason Purdy and Nate Mueller. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/perl/Sajax.pm |
---|
0,0 → 1,184 |
package Sajax; |
use Data::Dumper; |
my $rs_debug_mode = 0; |
my $rs_js_has_been_shown = 0; |
my %rs_export_list = (); |
my %rs_coderef_list = (); |
sub incl_sajax { |
} |
sub rs_init { |
$rs_debug_mode = 0; |
$rs_js_has_been_shown = 0; |
%rs_export_list = (); |
%rs_coderef_list = (); |
} |
sub rs_handle_client_request { |
my($q)=@_; |
my $rv=""; |
if (!defined $q->param("rs")) { |
return undef; |
} |
my $func_name = $q->param("rs"); |
if ( defined $rs_export_list{$func_name}) { |
$rv .= "+:"; |
eval { |
$rv .= &$func_name($q->param("rsargs")); |
}; |
if($@) { |
print STDERR "Err:[$@]\n"; |
} |
} elsif ( defined $rs_coderef_list{$func_name}) { |
$rv .= "+:"; |
my $cr = $rs_coderef_list{$func_name}; |
eval { |
$rv .= &$cr($q->param("rsargs")); |
}; |
if($@) { |
print STDERR "Err:[$@]\n"; |
} |
} else { |
$rv .= "-:$func_name not callable"; |
} |
return $rv; |
} |
sub rs_show_common_js() { |
my $rv = ""; |
my $debug_mode = $rs_debug_mode ? "true" : "false"; |
my $CC = "\n// Perl backend version (c) copyright 2005 Nathan Schmidt"; |
$CC = ""; |
$rv .= <<EOT; |
// remote scripting library |
// (c) copyright 2005 modernmethod, inc$CC |
var rs_debug_mode = $debug_mode; |
var rs_obj = false; |
var rs_callback = false; |
function rs_debug(text) { |
if (rs_debug_mode) |
alert("RSD: " + text) |
} |
function rs_init_object() { |
rs_debug("rs_init_object() called..") |
var A; |
try { |
A=new ActiveXObject("Msxml2.XMLHTTP"); |
} catch (e) { |
try { |
A=new ActiveXObject("Microsoft.XMLHTTP"); |
} catch (oc) { |
A=null; |
} |
} |
if(!A && typeof XMLHttpRequest != "undefined") |
A = new XMLHttpRequest(); |
if (!A) |
rs_debug("Could not create connection object."); |
return A; |
} |
EOT |
return $rv; |
} |
#javascript escape a value |
sub rs_esc { |
my ($val)=@_; |
$val =~ s/\"/\\\\\"/; |
return $val; |
} |
sub rs_urlencode { |
my($enc) = @_; |
$enc =~ s/^\s+|\s+$//gs; |
$enc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; |
$enc =~ s/ /\+/g; |
$enc =~ s/%20/\+/g; |
return $enc; |
} |
sub rs_show_one { |
my($q,$func_name)=@_; |
my $rv = ""; |
my $uri = $q->url(-query=>1); |
if ($uri =~ m/\?/) { |
$uri .= "&rs=".rs_urlencode($func_name); |
} else { |
$uri .= "?rs=".rs_urlencode($func_name); |
} |
my $urie = rs_esc($uri); |
$rv .= <<EOT; |
// wrapper for $func_name |
function x_$func_name() { |
// count args; build URL |
var i, x, n; |
var url = "$urie", a = x_$func_name.arguments; |
for (i = 0; i < a.length-1; i++) |
url = url + "&rsargs=" + escape(a[i]); |
url = url.replace( /[+]/g, '%2B'); // fix the unescaped plus signs |
x = rs_init_object(); |
x.open("GET", url, true); |
x.onreadystatechange = function() { |
if (x.readyState != 4) |
return; |
rs_debug("received " + x.responseText); |
var status; |
var data; |
status = x.responseText.charAt(0); |
data = x.responseText.substring(2); |
if (status == "-") |
alert("Error: " + callback_n); |
else |
a[a.length-1](data); |
} |
x.send(null); |
rs_debug("x_$func_name url = " + url); |
rs_debug("x_$func_name waiting.."); |
} |
EOT |
return $rv; |
} |
sub rs_register { |
my($fn,$coderef)=@_; |
$rs_coderef_list{$fn} = $coderef; |
} |
sub rs_export { |
map {$rs_export_list{$_}=$_} @_; |
return; |
} |
sub rs_show_javascript { |
my ($q) = @_; |
my $rv = ""; |
if (! $rs_js_has_been_shown) { |
$rv .= rs_show_common_js(); |
$rs_js_has_been_shown = 1; |
} |
foreach my $func (keys %rs_export_list) { |
$rv .= rs_show_one($q,$func); |
} |
foreach my $func (keys %rs_coderef_list) { |
$rv .= rs_show_one($q,$func); |
} |
return $rv; |
} |
1; |
Property changes: |
Added: svn:mime-type |
+text/x-perl |
\ No newline at end of property |
/trunk/dependencies/sajax/perl/example_multiply.cgi |
---|
0,0 → 1,113 |
#! /usr/bin/perl -w |
# Perl version cloned from the original PHP by http://www.modernmethod.com/sajax/ |
# I've left commented-out examples in the code for running with static methods. |
# For moving to ModPerl it's important to no be redefining subs all the time, |
# so this code adds the rs_register(funcname,coderef) call, which takes a coderef |
# rather than the name of a sub to be called. |
use Sajax; |
use CGI; |
my $q = new CGI; |
my $rv = ""; |
$rv .= "content-type: text/html\n\n"; |
=pod |
#for static method calls |
sub Sajax::multiply { |
my($x, $y)=@_; |
return $x * $y; |
} |
sub Sajax::divide { |
my($x, $y)=@_; |
return $x / $y; |
} |
=cut |
#equivalent modperl methods |
my $msub = sub { |
my($x, $y)=@_; |
return $x * $y; |
}; |
my $dsub = sub { |
my($x, $y)=@_; |
return $x / $y; |
}; |
Sajax::rs_init(); |
#register static methods (called by name) |
#Sajax::rs_export("multiply","divide"); |
#modperl methods (called as anonymous coderefs) |
Sajax::rs_register("multiply",$msub); |
Sajax::rs_register("divide",$dsub); |
my $handled_value = Sajax::rs_handle_client_request($q); |
if(defined $handled_value) { |
$rv .= $handled_value; |
} else { |
$rv .= "<html>\n<head>\n<title>Multiplier</title>\n<script>\n\n"; |
$rv .= Sajax::rs_show_javascript($q); |
$rv .= <<EOT; |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_divide_cb(z) { |
document.getElementById("zz").value = z; |
} |
function do_multiply() { |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_multiply(x, y, do_multiply_cb); |
} |
function do_divide() { |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_divide(x, y, do_divide_cb); |
} |
EOT |
$rv .= "</script>\n\n</head>\n"; |
$rv .= <<EOT; |
<body> |
<input type="text" name="x" id="x" value="2" size="3"> |
* |
<input type="text" name="y" id="y" value="3" size="3"> |
= |
<input type="text" name="z" id="z" value="" size="5"> |
<input type="text" name="zz" id="zz" value="" size="5"> |
<input type="button" name="check" value="Multiply" onclick="do_multiply(); return false;"> |
<input type="button" name="check" value="Divide" onclick="do_divide(); return false;"> |
<input type="button" name="check" value="Both" onclick="do_multiply();do_divide(); return false;"> |
<BR> |
<A HREF=showsource.cgi>Show source</A> |
</body> |
</html> |
EOT |
} |
print $rv; |
/trunk/dependencies/sajax/php/Readme.txt |
---|
0,0 → 1,33 |
SAJAX PHP BACKEND |
----------------- |
Contributed and copyighted by Thomas Lackner (http://www.modernmethod.com/) and Anders Jenbo. |
If you are using PHP < 5.2 you will need to a substitue for JSON_encode and JSON_decode, you might want to try this out http://abeautifulsite.net/notebook/71 |
Usage: |
sajax_export() takes a list of functions that are alowed to be called from javascript, there are 4 parameters for each function you send to sajax_export. If strings are used in stead of arrays the functions will just have all options set to there default (like in older versions of Sajax). |
name = the name of the function (requred) |
method = GET : POST (default is GET) |
asynchronous = true : false (default is true, if set to false the script will pause untill the call has been compleated) |
uri = the uri where the function lives. |
The default method can be changed by setting $sajax_request_type to "POST" (this can also be done at runtime). |
The default uri can be changed by setting $sajax_remote_uri (this can also be done at runtime). |
Sample: |
sajax_export( |
"myFunction", |
array("name" => "myPostFunction", "method" => "POST"), |
array("name" => "sleep", "asynchronous" => true), |
array("name" => "myOffSitefunction", "uri" => "http://myotheresite.com/ajax.php") |
); |
sajax_export() may be called multiple times. |
To get debug alert's set $sajax_debug_mode to true. |
You can redirect the users browser to a frindly error page incase his/her borwser issn't supported by sajax by setting $sajax_failure_redirect to an URI. |
Calling sajax_get_common_js() will print the client side script. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/php/example_multiply.php |
---|
0,0 → 1,48 |
<?php |
function multiply($x, $y) { |
return $x * $y; |
} |
require("sajax.php"); |
// $sajax_debug_mode = true; |
$sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
sajax_export("multiply"); |
sajax_handle_client_request(); |
?> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>Sajax Multiplier example</title> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<?php sajax_show_javascript(); ?> |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
// get the folder name |
var x, y; |
x = parseFloat(document.getElementById("x").value); |
y = parseFloat(document.getElementById("y").value); |
x_multiply(x, y, do_multiply_cb); |
} |
//--> |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3" /> |
* |
<input type="text" name="y" id="y" value="3" size="3" /> |
= |
<input type="text" name="z" id="z" value="" size="3" /> |
<input type="button" name="check" value="Calculate" onclick="do_multiply(); return false;" /> |
</body> |
</html> |
/trunk/dependencies/sajax/php/example_options.php |
---|
0,0 → 1,83 |
<?php |
date_default_timezone_set('Europe/Copenhagen'); |
function test_get() { |
return test(); |
} |
function test_post() { |
return test(); |
} |
function test() { |
$s = "URI: ".$_SERVER['PHP_SELF']; |
$s .= "\n\n-- GET --\n"; |
if(!empty($_GET["rsargs"])) |
$s .= $_GET["rsargs"]; |
$s .= "\n-- POST --\n"; |
if(!empty($_POST["rsargs"])) |
$s .= $_POST["rsargs"]; |
return $s; |
} |
function get_the_time() { |
return date("Y-m-d h:i:s"); |
} |
require_once("sajax.php"); |
// $sajax_debug_mode = true; |
$sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
sajax_export( |
array("name" => "test_get", "method" => "GET"), |
array("name" => "test_post", "method" => "POST"), |
array("name" => "get_the_time", "method" => "GET"), |
array("name" => "test", "method" => "GET"), |
array("name" => "sleep", "asynchronous" => false), |
array("name" => "otherefucntion", "uri" => "example_otheruri.php"), |
array("name" => "otherefucntion2") |
); |
sajax_handle_client_request(); |
?> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>Example of Sajax Options</title> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<?php sajax_show_javascript(); ?> |
function print_result(v) { |
alert(v); |
} |
//--> |
</script> |
</head> |
<body> |
<!-- Testing if the browser supports GET --> |
<button onclick="x_test_get(1, 2, 3, print_result);">Test GET</button> |
<!-- Testing if the browser supports POST --> |
<button onclick="x_test_post(1, 2, 3, print_result);">Test POST</button> |
<!-- Forcing the function to POST --> |
<button onclick="sajax_request_type ='POST'; x_test(1, 2, 3, print_result); sajax_request_type ='';">Test force POST</button> |
<!-- if sajax_target_id is set, the sesponce will be inserted as HTML in an element with sajax_target_id for id--> |
<button onclick="sajax_target_id = 'time'; x_get_the_time(); sajax_target_id = '';">Test updating IDs</button> |
<!-- Calling a synchronous will cause the script to wait for the responce --> |
<button onclick="x_sleep(3, function(){}); alert('Link was clicked!');">Test synchronous</button> |
<!-- Different URI set at config --> |
<button onclick="x_otherefucntion(print_result);">Call to other uri.</button> |
<!-- Forece different URI at runtime --> |
<button onclick="sajax_remote_uri = 'example_otheruri.php'; x_otherefucntion2(print_result); sajax_remote_uri = '';">Force call to other uri.</button> |
<div id="time"><em>Time will appear here</em></div> |
</body> |
</html> |
/trunk/dependencies/sajax/php/example_otheruri.php |
---|
0,0 → 1,13 |
<?php |
function otherefucntion() { |
return "URI: ".$_SERVER['PHP_SELF']; |
} |
function otherefucntion2() { |
return otherefucntion(); |
} |
require("sajax.php"); |
sajax_export("otherefucntion", "otherefucntion2"); |
sajax_handle_client_request(); |
?> |
/trunk/dependencies/sajax/php/example_types.php |
---|
0,0 → 1,85 |
<?php |
date_default_timezone_set('Europe/Copenhagen'); |
$bday = strtotime("5 September 1983"); |
$age = (date('z')-date('z', $bday))/1000+date('Y')-date('Y', $bday); |
function return_array() { |
global $age; |
return array("name" => "Anders", "age" => $age); |
} |
function return_object() { |
global $age; |
class MyObj { |
var $name, $age; |
function MyObj($name, $age) { |
$this->name = $name; |
$this->age = $age; |
} |
} |
$o = new MyObj("Anders", $age); |
return $o; |
} |
function return_int() { |
global $age; |
return floor($age); |
} |
function return_float() { |
global $age; |
return $age; |
} |
function return_string() { |
global $age; |
return "Anders is ".floor($age)." years old."; |
} |
require("sajax.php"); |
$sajax_request_type = "GET"; |
// $sajax_debug_mode = true; |
$sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
sajax_export("return_array", "return_object", "return_int", "return_float", "return_string"); |
sajax_handle_client_request(); |
?> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<title>Sajax PHP return types example</title> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<script type="text/javascript" src="json2.stringify.js"></script> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse_state.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<?php sajax_show_javascript(); ?> |
function display_result(val) { |
var repr; |
repr = ""; |
repr += "Type: " + typeof val + "\n"; |
repr += "Value: "; |
if (typeof val == "object" || |
typeof val == "array") { |
repr += "{ "; |
for (var i in val) |
repr += i + ": " + val[i] + ", "; |
repr = repr.substr(0, repr.length-2) + " }"; |
} else { |
repr += val; |
} |
alert(repr); |
} |
//--> |
</script> |
</head> |
<body> |
<button onclick="x_return_array(display_result);">Return as array (will become an object)</button> |
<button onclick="x_return_object(display_result);">Return as object</button> |
<button onclick="x_return_int(display_result);">Return as int</button> |
<button onclick="x_return_float(display_result);">Return as float/double</button> |
<button onclick="x_return_string(display_result);">Return as string</button> |
</body> |
</html> |
/trunk/dependencies/sajax/php/example_wall.php |
---|
0,0 → 1,122 |
<?php |
// |
// The world's least efficient wall implementation (now a bit more efficient) |
// |
date_default_timezone_set('Europe/Copenhagen'); |
$filename = "tmp/wall.html"; |
function colorify_ip($ip) |
{ |
$parts = explode(".", $ip); |
$color = sprintf("%02s", dechex($parts[1])) . |
sprintf("%02s", dechex($parts[2])) . |
sprintf("%02s", dechex($parts[3])); |
return $color; |
} |
function add_line($msg) { |
global $filename; |
$f = fopen($filename, "a"); |
$date = date("Y-m-d h:i:s"); |
$msg = strip_tags(stripslashes($msg)); |
$remote = $_SERVER["REMOTE_ADDR"]; |
// generate unique-ish color for IP |
$color = colorify_ip($remote); |
fwrite($f, '<span style="color:#'.$color.'">'.$date.'</span> '.htmlspecialchars($msg).'<br />'."\r\n"); |
fclose($f); |
return refresh(0); |
} |
function refresh($lastrefresh) { |
global $filename; |
if(filemtime($filename) > $lastrefresh) { |
$lines = file($filename); |
// return the last 25 lines |
return array("wall" => join("\n", array_slice($lines, -25)), "update" => filemtime($filename)); |
} else { |
return false; |
} |
} |
require("sajax.php"); |
// $sajax_debug_mode = true; |
$sajax_failure_redirect = "http://sajax.info/sajaxfail.html"; |
sajax_export( |
array("name" => "add_line", "method" => "POST"), |
array("name" => "refresh", "method" => "GET") |
); |
sajax_handle_client_request(); |
?> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>Sajax graffiti wall example</title> |
<style type="text/css"> |
.date { |
color: blue; |
} |
</style> |
<script type="text/javascript" src="json_stringify.js"></script> |
<script type="text/javascript" src="json_parse.js"></script> |
<script type="text/javascript" src="sajax.js"></script> |
<script type="text/javascript"><!-- |
<?php sajax_show_javascript(); ?> |
var check_n = 1; |
var nextrefresh; |
function refresh_cb(data) { |
if(data !== false) { |
document.getElementById("wall").innerHTML = data["wall"]; |
lastrefresh = data["update"]; |
clearTimeout(nextrefresh); |
nextrefresh = setTimeout("refresh();", 1000); |
} else { |
clearTimeout(nextrefresh); |
nextrefresh = setTimeout("refresh();", 2500); |
} |
document.getElementById("status").innerHTML = "Checked #" + check_n++; |
} |
var lastrefresh = <?php echo(filemtime($filename)); ?>; |
function refresh() { |
document.getElementById("status").innerHTML = "Checking.."; |
x_refresh(lastrefresh, refresh_cb); |
} |
function add() { |
var line; |
var handle; |
handle = document.getElementById("handle").value; |
line = document.getElementById("line").value; |
if(line == "") |
return; |
x_add_line("[" + handle + "] " + line, refresh_cb); |
document.getElementById("line").value = ""; |
} |
function keypress(keyCode) { |
if (keyCode==13) { |
add(); |
document.getElementById("line").select(); |
return false; |
} |
return true; |
} |
nextrefresh = setTimeout("refresh();", 1000); |
//--> |
</script> |
</head> |
<body> |
<b><a href="http://www.sajax.info/">Sajax</a> v<?php echo($sajax_version); ?></b> - You are a guinea pig - This example illustrates the simplest possible graffiti wall. It isn't meant to be perfect, featureful, or even useful.<br /> |
<form action="" method="post" onsubmit="add(); return false;"> |
<input type="text" name="handle" id="handle" value="(name)" onfocus="this.select()" style="width:130px;" /> |
<input type="text" name="line" id="line" value="(enter your message here)" onfocus="this.select();" onkeypress="keypress(event.keyCode);" style="width:300px;" /> |
<input type="button" name="check" value="Post message" onclick="add(); return false;" /> |
</form> |
<div id="wall"> <?php $temp = refresh(0); echo($temp["wall"]); ?></div> |
<div id="status">Checked #0</div> |
</body> |
</html> |
/trunk/dependencies/sajax/php/json2.parse.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/json2.stringify.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/json_parse.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/json_parse_state.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/json_stringify.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/sajax.js |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/javascript |
Property changes: |
Added: svn:mime-type |
+application/javascript |
\ No newline at end of property |
/trunk/dependencies/sajax/php/sajax.php |
---|
0,0 → 1,141 |
<?php |
if (!isset($SAJAX_INCLUDED)) { |
/* |
* GLOBALS AND DEFAULTS |
* |
*/ |
$GLOBALS['sajax_version'] = "0.13"; |
$GLOBALS['sajax_debug_mode'] = false; |
$GLOBALS['sajax_export_array'] = array(); |
$GLOBALS['sajax_export_list'] = array(); |
$GLOBALS['sajax_remote_uri'] = ""; |
$GLOBALS['sajax_failure_redirect'] = ""; |
$GLOBALS['sajax_request_type'] = "GET"; |
/* |
* CODE |
* |
*/ |
function sajax_handle_client_request() { |
if (empty($_GET["rs"]) && empty($_POST["rs"])) |
return; |
ob_start(); |
if (!empty($_GET["rs"])) { |
// Always call server |
header ("Cache-Control: max-age=0, must-revalidate"); // HTTP/1.1 |
header ("Pragma: no-cache"); // HTTP/1.0 |
$func_name = $_GET["rs"]; |
if (! empty($_GET["rsargs"])) |
$args = $_GET["rsargs"]; |
} else { |
$func_name = $_POST["rs"]; |
if (! empty($_POST["rsargs"])) |
$args = $_POST["rsargs"]; |
} |
if(! empty($args)) { |
if(get_magic_quotes_gpc()) |
$args = stripslashes($args); |
$args = json_decode($args, true); |
if(get_magic_quotes_gpc()) { |
function array_addslashes($value) { |
if(is_array($value)) |
return array_map("array_addslashes", $value); |
else |
return addslashes($value); |
} |
$args = array_map("array_addslashes", $args); |
} |
} else { |
$args = array(); |
} |
global $sajax_export_list; |
if (! in_array($func_name, $sajax_export_list)) { |
$error = $func_name." not callable"; |
} else { |
$result = call_user_func_array($func_name, $args); |
$error = ob_get_contents(); |
ob_end_clean(); |
} |
header('Content-Type: text/plain; charset=UTF-8'); |
if(!empty($error)) { |
echo '-:'.$error; |
} else { |
echo "+:".json_encode($result); |
} |
exit; |
} |
$sajax_js_has_been_shown = false; |
function sajax_show_javascript() |
{ |
global $sajax_js_has_been_shown; |
global $sajax_debug_mode; |
global $sajax_failure_redirect; |
if (! $sajax_js_has_been_shown) { |
?> |
sajax_debug_mode = <?php echo($sajax_debug_mode ? "true" : "false"); ?>; |
sajax_failure_redirect = "<?php echo($sajax_failure_redirect); ?>"; |
<?php |
global $sajax_export_array; |
foreach($sajax_export_array as $function) { |
?> |
function x_<?php echo($function["name"]); ?>() { |
return sajax_do_call("<?php echo($function["name"]); ?>", arguments, "<?php echo($function["method"]); ?>", <?php echo($function["asynchronous"] ? 'true' : 'false'); ?>, "<?php echo($function["uri"]); ?>"); |
} |
<?php |
} |
$sajax_js_has_been_shown = true; |
} |
} |
function sajax_export() { |
global $sajax_export_array; |
global $sajax_export_list; |
global $sajax_request_type; |
global $sajax_remote_uri; |
$num = func_num_args(); |
for ($i=0; $i<$num; $i++) { |
$function = func_get_arg($i); |
if(!is_array($function)) |
$function = array("name" => $function); |
if(!isset($function["method"])) |
$function["method"] = $sajax_request_type; |
if(!isset($function["asynchronous"])) |
$function["asynchronous"] = true; |
if(!isset($function["uri"])) |
$function["uri"] = $sajax_remote_uri; |
$key = array_search($function["name"], $sajax_export_list); |
if ($key === false) { |
$sajax_export_array[] = $function; |
$sajax_export_list[] = $function["name"]; |
} else { |
//Overwrite old function |
$sajax_export_array[$key] = $function; |
$sajax_export_list[$key] = $function["name"]; |
} |
} |
} |
$SAJAX_INCLUDED = 1; |
} |
?> |
/trunk/dependencies/sajax/php/tmp/wall.html |
---|
0,0 → 1,46 |
<span style="color:#5b024d">2009-08-21 12:42:37</span> [Netscape 6.0] Shows fail page correctly<br /> |
<span style="color:#5b024d">2009-08-21 12:42:37</span> [Netscape 6.1] Shows fail page correctly<br /> |
<span style="color:#3ca206">2009-08-22 12:37:12</span> [Mozilla 0.9.4] Works *<br /> |
<span style="color:#5b024d">2009-08-21 08:26:49</span> [Mozilla 0.9.9] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:38:53</span> [Firefox 2.0.0.20] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:41:09</span> [Firefox 3.5.2] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:42:37</span> [IE 4] Failes horribly<br /> |
<span style="color:#fbc320">2009-08-22 03:32:36</span> [Fennec M10] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:42:37</span> [IE 5.01] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:42:30</span> [IE 5.5] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:42:20</span> [IE 6] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:41:56</span> [IE 7] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:41:41</span> [IE 8] Works<br /> |
<span style="color:#fbc320">2009-08-22 02:42:44</span> [Pocket Interrnet Explorer 7.11] Works<br /> |
<span style="color:#5b024d">2009-08-21 01:47:23</span> [iCab 3.0.5] Works **<br /> |
<span style="color:#5b024d">2009-08-21 06:13:48</span> [Safari 1.0] Shows fail page correctly<br /> |
<span style="color:#5b024d">2009-08-21 06:13:48</span> [Safari 1.1] Shows fail page correctly<br /> |
<span style="color:#5b024d">2009-08-21 06:13:48</span> [Safari 1.2] Works<br /> |
<span style="color:#5b024d">2009-08-21 08:20:58</span> [Safari 1.3] Works<br /> |
<span style="color:#5b024d">2009-08-21 09:02:25</span> [Safari 1.3.1] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:38:37</span> [Safari 1.3.2] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:17:34</span> [Safari 2.0] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:18:16</span> [Safari 2.0.2] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:18:58</span> [Safari 2.0.3] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:19:31</span> [Safari 2.0.4] Works<br /> |
<span style="color:#3ca206">2009-08-22 12:41:35</span> [Safari 3.0] Works<br /> |
<span style="color:#5b024d">2009-08-21 08:45:50</span> [Safari 3.0.4] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:15:07</span> [Safari 3.1.2] Works<br /> |
<span style="color:#fbc302">2009-08-24 03:15:54</span> [Safari 3.2.1] Works<br /> |
<span style="color:#fbc31f">2009-08-23 02:23:18</span> [Safari 3.2.3] Works<br /> |
<span style="color:#5b024d">2009-08-21 10:17:10</span> [Safari 4.0.3] Works<br /> |
<span style="color:#fbc320">2009-08-22 01:58:58</span> [iPhone 3.0.1] Works<br /> |
<span style="color:#5b024d">2009-08-21 08:36:46</span> [Google Chrome 2.0.172.39] Works<br /> |
<span style="color:#3ca206">2009-08-22 12:39:57</span> [Opera 8.0] Works *<br /> |
<span style="color:#3ca206">2009-08-22 02:30:58</span> [Opera 8.01] Only with GET<br /> |
<span style="color:#3ca206">2009-08-22 01:57:33</span> [Opera 8.02] Works<br /> |
<span style="color:#3ca206">2009-08-22 01:50:09</span> [Opera 8.50] Works<br /> |
<span style="color:#5b024d">2009-08-21 06:32:43</span> [Opera 8.54] Works<br /> |
<span style="color:#5b024d">2009-08-21 12:41:17</span> [Opera 9.64] Works<br /> |
<span style="color:#5b024d">2009-08-21 06:31:49</span> [Opera 10b] Works<br /> |
<span style="color:#5b024d">2009-08-24 12:26:46</span> [Opera 10b3] Works<br /> |
<span style="color:#fbc320">2009-08-22 03:15:22</span> [Opera Mobile 8.65] Works<br /> |
<span style="color:#fbc320">2009-08-22 02:38:22</span> [Opera Mobile 9.5] Works<br /> |
<span style="color:#fbc320">2009-08-22 03:07:59</span> [Opera Mobile 9.7b] Works<br /> |
<span style="color:#cb6018">2009-08-22 03:09:52</span> [Opera Mobile 9.7b Turbo] Works<br /> |
<span style="color:#bd8e2a">2009-08-22 02:40:12</span> [Opera Mini 4.2] Works<br /> |
Property changes: |
Added: svn:mime-type |
+text/html |
\ No newline at end of property |
/trunk/dependencies/sajax/python/License.txt |
---|
0,0 → 1,0 |
This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/python/Readme.txt |
---|
0,0 → 1,9 |
SAJAX PYTHON BACKEND |
-------------------- |
Contributed and copyighted by Adam Collard. Additional guidance and |
consultation by Carlos Bueno. |
IMPORTANT: This backend is NOT licensed under the BSD-L. It is licensed |
under the Creative Commons "By" License version 2.0. Please see |
License.txt for details. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/python/multiply.py |
---|
0,0 → 1,46 |
#!/usr/bin/env python |
import cgitb;cgitb.enable() |
import sajax1 |
def multiply(x,y): |
try: |
float_x, float_y = float(x), float(y) |
except: |
return 0 |
return float_x * float_y |
sajax1.sajax_init() |
sajax1.sajax_export(multiply) |
sajax1.sajax_handle_client_request() |
print """ |
<html> |
<head> |
<title>PyMultiplier</title> |
<script> |
""" |
sajax1.sajax_show_javascript() |
print """ |
function do_multiply_cb(z) { |
document.getElementById("z").value = z; |
} |
function do_multiply() { |
var x, y; |
x = document.getElementById("x").value; |
y = document.getElementById("y").value; |
x_multiply(x, y, do_multiply_cb); |
} |
</script> |
</head> |
<body> |
<input type="text" name="x" id="x" value="2" size="3"> |
* |
<input type="text" name="y" id="y" value="3" size="3"> |
= |
<input type="text" name="z" id="z" value="" size="3"> |
<input type="button" name="check" value="Calculate" |
onclick="do_multiply(); return false;"> |
</body> |
</html> |
""" % locals() |
Property changes: |
Added: svn:mime-type |
+text/x-python |
\ No newline at end of property |
/trunk/dependencies/sajax/python/sajax1.py |
---|
0,0 → 1,149 |
#!/usr/bin/env python |
import cgi |
import cgitb; cgitb.enable() |
import os |
import sys |
import datetime |
import urllib |
print "Content-type: text/html" |
sajax_debug_mode = False |
sajax_export_list = {} |
sajax_js_has_been_shown = False |
form = cgi.FieldStorage() |
def sajax_init(): |
pass |
def sajax_handle_client_request(): |
func_name = form.getfirst('rs') |
if func_name is None: |
return |
# Bust cache in the head |
print "Expires: Mon, 26 Jul 1997 05:00:00 GMT" |
print "Last-Modified: %s GMT" % datetime.datetime.utcnow().strftime( |
"%a, %d %m %H:%M:%S") |
# always modified |
print "Cache-Control: no-cache, must-revalidate" # HTTP/1.1 |
print "Pragma: no-cache" # HTTP/1.0 |
if not func_name in sajax_export_list: |
print "-:%s not callable" % func_name |
else: |
print "+:", |
rsargs = form.getlist('rsargs[]') |
result = sajax_export_list[func_name](*rsargs) |
print result |
sys.exit() |
def sajax_get_common_js(): |
sajax_debug_modeJS = str(sajax_debug_mode).lower() |
return """\ |
// remote scripting library |
// (c) copyright 2005 modernmethod, inc |
var sajax_debug_mode = %(sajax_debug_modeJS)s; |
function sajax_debug(text) { |
if (sajax_debug_mode) |
alert("RSD: " + text) |
} |
function sajax_init_object() { |
sajax_debug("sajax_init_object() called..") |
var A; |
try { |
A=new ActiveXObject("Msxml2.XMLHTTP"); |
} catch (e) { |
try { |
A=new ActiveXObject("Microsoft.XMLHTTP"); |
} catch (oc) { |
A=null; |
} |
} |
if(!A && typeof XMLHttpRequest != "undefined") |
A = new XMLHttpRequest(); |
if (!A) |
sajax_debug("Could not create connection object."); |
return A; |
} |
function sajax_do_call(func_name, url, args) { |
var i, x, n; |
for (i = 0; i < args.length-1; i++) |
url = url + "&rsargs[]=" + escape(args[i]); |
url = url + "&rsrnd=" + new Date().getTime(); |
x = sajax_init_object(); |
x.open("GET", url, true); |
x.onreadystatechange = function() { |
if (x.readyState != 4) |
return; |
sajax_debug("received " + x.responseText); |
var status; |
var data; |
status = x.responseText.charAt(0); |
data = x.responseText.substring(2); |
if (status == "-") |
alert("Error: " + data); |
else |
args[args.length-1](data); |
} |
x.send(null); |
sajax_debug(func_name + " url = " + url); |
sajax_debug(func_name + " waiting.."); |
delete x; |
} |
""" % locals() |
def sajax_show_common_js(): |
print sajax_get_common_js() |
def sajax_esc(val): |
return val.replace('"', '\\\\"') |
def sajax_get_one_stub(func_name): |
uri = os.environ['SCRIPT_NAME'] |
if os.environ.has_key('QUERY_STRING'): |
uri += "?" + os.environ['QUERY_STRING'] + "&rs=%s" % urllib.quote_plus(func_name) |
else: |
uri += "?rs=%s" % urllib.quote_plus(func_name) |
escapeduri = sajax_esc(uri) |
return """ |
// wrapper for %(func_name)s |
function x_%(func_name)s(){ |
// count args; build URL |
sajax_do_call("%(func_name)s", |
"%(escapeduri)s", |
x_%(func_name)s.arguments); |
} |
""" % locals() |
def sajax_show_one_stub(func_name): |
print sajax_get_one_stub(func_name) |
def sajax_export(*args): |
decorated = [(f.func_name, f) for f in args] |
sajax_export_list.update(dict(decorated)) |
def sajax_get_javascript(): |
global sajax_js_has_been_shown |
html = '' |
if not sajax_js_has_been_shown: |
html += sajax_get_common_js() |
sajax_js_has_been_shown = True |
for func_name in sajax_export_list.iterkeys(): |
html += sajax_get_one_stub(func_name) |
return html |
def sajax_show_javascript(): |
print sajax_get_javascript() |
Property changes: |
Added: svn:mime-type |
+text/x-python |
\ No newline at end of property |
/trunk/dependencies/sajax/python/wall.py |
---|
0,0 → 1,90 |
#!/usr/bin/env python |
import cgi |
import cgitb;cgitb.enable() |
import datetime |
import os |
import sajax1 |
WALLFILE = '/tmp/wall.html' |
if not os.path.exists(WALLFILE): |
fh = open(WALLFILE, 'w') |
fh.close() |
def colourify_ip(ip): |
colour = ''.join(['%02x' % int(part) for part in ip.split('.')[-3:]]) |
return colour |
def add_line(msg): |
f = open("/tmp/wall.html","a") |
dt = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") |
msg = cgi.escape(msg) |
remote = os.environ['REMOTE_ADDR'] |
colour = colourify_ip(remote) |
f.write('<span style="color:#%(colour)s">%(dt)s</span> %(msg)s<br />\n' % locals()) |
f.close() |
def refresh(): |
f = open("/tmp/wall.html") |
return '\n'.join(list(f)[-25:]) |
sajax1.sajax_init() |
sajax1.sajax_export(refresh, add_line) |
sajax1.sajax_handle_client_request() |
print """ |
<html> |
<head> |
<title>PyWall</title> |
<script> |
""" |
sajax1.sajax_show_javascript() |
print """ |
var check_n = 0; |
function refresh_cb(new_data) { |
document.getElementById("wall").innerHTML = new_data; |
document.getElementById("status").innerHTML = "Checked #" + check_n++; |
setTimeout("refresh()", 1000); |
} |
function refresh() { |
document.getElementById("status").innerHTML = "Checking.."; |
x_refresh(refresh_cb); |
} |
function add_cb() { |
// we don't care.. |
} |
function add() { |
var line; |
var handle; |
handle = document.getElementById("handle").value; |
line = document.getElementById("line").value; |
if (line == "") |
return; |
x_add_line("[" + handle + "] " + line, add_cb); |
document.getElementById("line").value = ""; |
} |
</script> |
</head> |
<body onload="refresh();"> |
<a href="http://">Sajax</a> - Wall Example<br/> |
<input type="text" name="handle" id="handle" value="(name)" |
onfocus="this.select()" style="width:130px;"> |
<input type="text" name="line" id="line" value="(enter your message here)" |
onfocus="this.select()" |
style="width:300px;"> |
<input type="button" name="check" value="Post message" |
onclick="add(); return false;"> |
<div id="wall"></div> |
<div id="status"><em>Loading..</em></div> |
</body> |
</html> |
""" % locals() |
Property changes: |
Added: svn:mime-type |
+text/x-python |
\ No newline at end of property |
/trunk/dependencies/sajax/ruby/Readme.txt |
---|
0,0 → 1,9 |
SAJAX RUBY BACKEND |
------------------ |
Contributed and put into the public domain by an anonymous member |
of the Sajax forum. If anyone wants to take control of this port |
and improve it, it would be welcomed. |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/trunk/dependencies/sajax/ruby/Sajax.rb |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/x-ruby |
Property changes: |
Added: svn:mime-type |
+application/x-ruby |
\ No newline at end of property |