Subversion Repositories cryptochat

Compare Revisions

No changes between revisions

Regard whitespace Rev 1 → Rev 2

/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