From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojo/tests/io/iframe.html | 124 +++++++++++++++++++++ includes/js/dojo/tests/io/iframe.js | 8 ++ includes/js/dojo/tests/io/iframeResponse.html | 8 ++ includes/js/dojo/tests/io/iframeResponse.js.html | 7 ++ includes/js/dojo/tests/io/iframeResponse.json.html | 7 ++ includes/js/dojo/tests/io/iframeResponse.text.html | 7 ++ includes/js/dojo/tests/io/iframeUploadTest.html | 50 +++++++++ includes/js/dojo/tests/io/script.html | 101 +++++++++++++++++ includes/js/dojo/tests/io/script.js | 8 ++ includes/js/dojo/tests/io/scriptJsonp.js | 57 ++++++++++ includes/js/dojo/tests/io/scriptSimple.js | 5 + includes/js/dojo/tests/io/scriptTimeout.html | 67 +++++++++++ includes/js/dojo/tests/io/upload.cgi | 60 ++++++++++ 13 files changed, 509 insertions(+) create mode 100644 includes/js/dojo/tests/io/iframe.html create mode 100644 includes/js/dojo/tests/io/iframe.js create mode 100644 includes/js/dojo/tests/io/iframeResponse.html create mode 100644 includes/js/dojo/tests/io/iframeResponse.js.html create mode 100644 includes/js/dojo/tests/io/iframeResponse.json.html create mode 100644 includes/js/dojo/tests/io/iframeResponse.text.html create mode 100644 includes/js/dojo/tests/io/iframeUploadTest.html create mode 100644 includes/js/dojo/tests/io/script.html create mode 100644 includes/js/dojo/tests/io/script.js create mode 100644 includes/js/dojo/tests/io/scriptJsonp.js create mode 100644 includes/js/dojo/tests/io/scriptSimple.js create mode 100644 includes/js/dojo/tests/io/scriptTimeout.html create mode 100644 includes/js/dojo/tests/io/upload.cgi (limited to 'includes/js/dojo/tests/io') diff --git a/includes/js/dojo/tests/io/iframe.html b/includes/js/dojo/tests/io/iframe.html new file mode 100644 index 0000000..c37bcb1 --- /dev/null +++ b/includes/js/dojo/tests/io/iframe.html @@ -0,0 +1,124 @@ + + + + Testing dojo.io.iframe + + + + + + + + diff --git a/includes/js/dojo/tests/io/iframe.js b/includes/js/dojo/tests/io/iframe.js new file mode 100644 index 0000000..6e20af5 --- /dev/null +++ b/includes/js/dojo/tests/io/iframe.js @@ -0,0 +1,8 @@ +if(!dojo._hasResource["tests.io.iframe"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["tests.io.iframe"] = true; +dojo.provide("tests.io.iframe"); +if(dojo.isBrowser){ + doh.registerUrl("tests.io.iframe", dojo.moduleUrl("tests.io", "iframe.html")); +} + +} diff --git a/includes/js/dojo/tests/io/iframeResponse.html b/includes/js/dojo/tests/io/iframeResponse.html new file mode 100644 index 0000000..cd26e21 --- /dev/null +++ b/includes/js/dojo/tests/io/iframeResponse.html @@ -0,0 +1,8 @@ + + + + +

SUCCESSFUL HTML response

+ + + diff --git a/includes/js/dojo/tests/io/iframeResponse.js.html b/includes/js/dojo/tests/io/iframeResponse.js.html new file mode 100644 index 0000000..50c1855 --- /dev/null +++ b/includes/js/dojo/tests/io/iframeResponse.js.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/includes/js/dojo/tests/io/iframeResponse.json.html b/includes/js/dojo/tests/io/iframeResponse.json.html new file mode 100644 index 0000000..cb04ed7 --- /dev/null +++ b/includes/js/dojo/tests/io/iframeResponse.json.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/includes/js/dojo/tests/io/iframeResponse.text.html b/includes/js/dojo/tests/io/iframeResponse.text.html new file mode 100644 index 0000000..2a05b83 --- /dev/null +++ b/includes/js/dojo/tests/io/iframeResponse.text.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/includes/js/dojo/tests/io/iframeUploadTest.html b/includes/js/dojo/tests/io/iframeUploadTest.html new file mode 100644 index 0000000..6f6db6f --- /dev/null +++ b/includes/js/dojo/tests/io/iframeUploadTest.html @@ -0,0 +1,50 @@ + + + + + + + + +

This file tests dojo.io.iframe upload using a form POST with a file upload button.

+ +

+ Note: This test makes a form POST to upload.cgi. This cgi needs to be made executable for this test to work, and it won't work from local disk. +

+
+ + + +
+ + + diff --git a/includes/js/dojo/tests/io/script.html b/includes/js/dojo/tests/io/script.html new file mode 100644 index 0000000..db24ac9 --- /dev/null +++ b/includes/js/dojo/tests/io/script.html @@ -0,0 +1,101 @@ + + + + Testing dojo.io.script + + + + + + + + diff --git a/includes/js/dojo/tests/io/script.js b/includes/js/dojo/tests/io/script.js new file mode 100644 index 0000000..722a805 --- /dev/null +++ b/includes/js/dojo/tests/io/script.js @@ -0,0 +1,8 @@ +if(!dojo._hasResource["tests.io.script"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["tests.io.script"] = true; +dojo.provide("tests.io.script"); +if(dojo.isBrowser){ + doh.registerUrl("tests.io.script", dojo.moduleUrl("tests.io", "script.html")); +} + +} diff --git a/includes/js/dojo/tests/io/scriptJsonp.js b/includes/js/dojo/tests/io/scriptJsonp.js new file mode 100644 index 0000000..ad1a196 --- /dev/null +++ b/includes/js/dojo/tests/io/scriptJsonp.js @@ -0,0 +1,57 @@ +function getJsonpCallback(url){ + var result = null; + var idMatch = url.match(/jsonp=(.*?)(&|$)/); + if(idMatch){ + result = idMatch[1]; + }else{ + //jsonp didn't match, so maybe it is the jsonCallback thing. + idMatch = url.match(/callback=(.*?)(&|$)/); + if(idMatch){ + result = idMatch[1]; + } + } + + if(result){ + result = decodeURIComponent(result); + } + return result; +} + +function findJsonpDone(){ + var result = false; + var scriptUrls = getScriptUrls(); + + for(var i = 0; i < scriptUrls.length; i++){ + var jsonp = getJsonpCallback(scriptUrls[i]); + if(jsonp){ + eval(jsonp + "({animalType: 'mammal'});"); + result = true; + break; + } + } + return result; +} + +function getScriptUrls(){ + //Get the script tags in the page to figure what state we are in. + var scripts = document.getElementsByTagName('script'); + var scriptUrls = new Array(); + for(var i = 0; scripts && i < scripts.length; i++){ + var scriptTag = scripts[i]; + if(scriptTag.id.indexOf("dojoIoScript") == 0){ + scriptUrls.push(scriptTag.src); + } + } + + return scriptUrls; +} + +function doJsonpCallback(){ + if(!findJsonpDone()){ + alert('ERROR: Could not jsonp callback!'); + } +} + +//Set a timeout to do the callback check, since MSIE won't see the SCRIPT tag until +//we complete processing of this page. +setTimeout(function(){doJsonpCallback();}, 300); diff --git a/includes/js/dojo/tests/io/scriptSimple.js b/includes/js/dojo/tests/io/scriptSimple.js new file mode 100644 index 0000000..8ca316c --- /dev/null +++ b/includes/js/dojo/tests/io/scriptSimple.js @@ -0,0 +1,5 @@ +myTasks = new Array(); +myTasks[0] = 'Take out trash.'; +myTasks[1] = 'Do dishes.'; +myTasks[2] = 'Brush teeth.'; + diff --git a/includes/js/dojo/tests/io/scriptTimeout.html b/includes/js/dojo/tests/io/scriptTimeout.html new file mode 100644 index 0000000..563e37c --- /dev/null +++ b/includes/js/dojo/tests/io/scriptTimeout.html @@ -0,0 +1,67 @@ + + + + Testing dojo.io.script + + + + + +

Timeout test

+ +

+ This test page tests the timeout functionality of dojo.io.script, and to make + sure that requests that time out get removed quickly. If the server response + is received after the script has been timed out, there should not be weird + errors as the browser tries to evaluate the responses after the desired time + period. +

+ +

This test requires a server running PHP to work.

+ +

+

Firefox Oddity: Firefox + will print an error after the script response is received from the server:
+ dojo.io.script.jsonp_dojoIoScript1 has no properties + This is bad because Firefox goes ahead and evaluates the script contents in the page's + JavaScript space (this happens even when I turn off Firefox Add-Ons). All other browsers + do not evaluate the script (given the weird Opera 9.22 behavior below). You can test this + by clicking the Test for SuperXFooBarVariable button after receiving the response + for timeout.php (check Firebug Net tab to see when request is received). All other browsers + show an error or show the "undefined" value for SuperXFooBarVariable, but Firefox will show its + value as being: "Oh no! SuperXFooBarVariable is defined (should not be for timeout case)". + +

Opera Oddity: Opera 9.22 does not seem to trigger the timeout case, + but rather it waits for the server to send a response to the script before continuing past the + point where the script is added to the DOM? That seems wrong. Dynamic script tags are no longer + an async operation? +

+ + + + + diff --git a/includes/js/dojo/tests/io/upload.cgi b/includes/js/dojo/tests/io/upload.cgi new file mode 100644 index 0000000..a13656f --- /dev/null +++ b/includes/js/dojo/tests/io/upload.cgi @@ -0,0 +1,60 @@ +#!/usr/bin/python + +# FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844 + +import cgi +import cgitb; cgitb.enable() +import os, sys +import string + +UPLOAD_DIR = "/tmp/upload/" +form = cgi.FieldStorage() + +dbg = [] + +def debug(dbgstr): + dbg.append(str(dbgstr)) + +def save_uploaded_file(form_field, upload_dir): + global form + if not form.has_key(form_field): + debug("didn't find it! (1)") + return + fileitem = form[form_field] + if not fileitem.file: + debug(form.getvalue(form_field, "")) + debug(fileitem.__dict__) + debug("didn't find it! (2)") + return + fout = file(os.path.join(upload_dir, fileitem.filename), 'wb') + while 1: + chunk = fileitem.file.read(100000) + if not chunk: break + fout.write (chunk) + fout.close() + +retval = "false"; +fileFields = "" + +if form.has_key("fileFields"): + fval = str(form.getvalue("fileFields", "")) + fileFields = fval.split(",") + debug("'fileCount': '" + str(len(fileFields)) + "',") + for field in fileFields: + debug("'fileField' : '"+field + "',") + save_uploaded_file(str(field).strip(), UPLOAD_DIR) + retval = "true"; + +debug("'retval': " + retval) + +print """Content-Type: text/html + + + + + + + + + +""" % (string.join(dbg, "\n")) -- cgit v1.2.3-54-g00ecf