summaryrefslogtreecommitdiff
path: root/lib/scripts/tw-sack.js
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-06-08 20:27:58 +0200
committerandi <andi@splitbrain.org>2005-06-08 20:27:58 +0200
commit95657bc6773c23c04843d51d5224df0bbd5191f0 (patch)
tree119d23ef8bfb8977f79acc114e016ea66691d2c6 /lib/scripts/tw-sack.js
parent2765ac2310959056fc3548fbdd745258de6c048c (diff)
downloadrpg-95657bc6773c23c04843d51d5224df0bbd5191f0.tar.gz
rpg-95657bc6773c23c04843d51d5224df0bbd5191f0.tar.bz2
Spellchecker fixes
The spellchecker now works in IE6, Firefox and Opera 8 :-) SACK was updated to the latest release (plus a minor fix) Proper UTF-8 headers were added to the AJAX PHP backends darcs-hash:20050608182758-9977f-1eacd0ba9993a62f094433d982f668e38d17ba14.gz
Diffstat (limited to 'lib/scripts/tw-sack.js')
-rw-r--r--lib/scripts/tw-sack.js216
1 files changed, 127 insertions, 89 deletions
diff --git a/lib/scripts/tw-sack.js b/lib/scripts/tw-sack.js
index 18b63730a..f9b8f247f 100644
--- a/lib/scripts/tw-sack.js
+++ b/lib/scripts/tw-sack.js
@@ -1,95 +1,133 @@
-// ====== Simple Ajax Code Kit =======
-// code by Gregory Wild-Smith (c)2005
-// http://twilightuniverse.com
-// If you use this code please keep this credit intact.
-// A link or email would be nice, but is not required.
-// v1.01
+/* Simple AJAX Code-Kit (SACK) */
+/* ©2005 Gregory Wild-Smith */
+/* www.twilightuniverse.com */
+/* Software licenced under a modified X11 licence, see documentation or authors website for more details */
function sack(file){
- this.AjaxFailedAlert = "Your browser doesn't support the extended functionality of this website, and therefore you have have an experience that differs from the intended one.\n";
- this.requestFile = file;
- this.method = "POST";
- this.URLString = "";
- this.encodeURIString = true;
- this.execute = false;
+ this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
+ this.requestFile = file;
+ this.method = "POST";
+ this.URLString = "";
+ this.encodeURIString = true;
+ this.execute = false;
- this.onLoading = function() { };
- this.onLoaded = function() { };
- this.onInteractive = function() { };
- this.onCompletion = function() { };
-
- this.createAJAX = function() {
- try {
- this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (oc) {
- this.xmlhttp = null;
- }
- }
- if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
- this.xmlhttp = new XMLHttpRequest();
- if (!this.xmlhttp){
- // no XMLHttpRequest support, so no AJAX.
- this.failed = true;
- }
- };
+ this.onLoading = function() { };
+ this.onLoaded = function() { };
+ this.onInteractive = function() { };
+ this.onCompletion = function() { };
- this.encodeURLString = function(string){
- varArray = string.split('&');
- for (i = 0; i < varArray.length; i++){
- urlVars = varArray[i].split('=');
- if (urlVars[0].indexOf('amp;') != -1){
- urlVars[0] = urlVars[0].substring(4);
- }
- urlVars[0] = encodeURIComponent(urlVars[0]);
- urlVars[1] = encodeURIComponent(urlVars[1]);
- varArray[i] = urlVars.join("=");
- }
- return varArray.join('&');
- }
-
- this.runResponse = function(){
- eval(this.response);
- }
-
- this.runAJAX = function(urlstring){
- if (urlstring){ this.URLString = urlstring; }
- if (this.element) { this.elementObj = document.getElementById(this.element); }
- if (this.xmlhttp) {
- var self = this; // wierd fix for odd behavior where "this" wouldn't work in the readystate function.
- this.xmlhttp.open(this.method, this.requestFile ,true);
- if (this.method == "POST" && this.xmlhttp.setRequestHeader) {
- this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
- }
- if (this.encodeURIString){ this.URLString = this.encodeURLString(this.URLString); }
- this.xmlhttp.send(this.URLString);
- this.xmlhttp.onreadystatechange = function() {
- switch (self.xmlhttp.readyState){
- case 1: // Loading.
- self.onLoading();
- break;
- case 2: // Loaded.
- self.onLoaded();
- break;
- case 3: // Interactive - is called every 4096 bytes.. pretty much just tells you it's downloading data.
- self.onInteractive();
- break;
- case 4: // Completed.
- self.response = self.xmlhttp.responseText;
- self.responseXML = self.xmlhttp.responseXML;
- self.onCompletion();
- if(self.execute){ self.runResponse(); }
- if (self.elementObj) {
- self.elementObj.innerHTML = self.response;
- }
- break;
- }
- };
- }
- };
+ this.createAJAX = function() {
+ try {
+ this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (err) {
+ this.xmlhttp = null;
+ }
+ }
+ if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
+ this.xmlhttp = new XMLHttpRequest();
+ if (!this.xmlhttp){
+ this.failed = true;
+ }
+ };
+
+ this.setVar = function(name, value){
+ if (this.URLString.length < 3){
+ this.URLString = name + "=" + value;
+ } else {
+ this.URLString += "&" + name + "=" + value;
+ }
+ }
+
+ this.encVar = function(name, value){
+ var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
+ return varString;
+ }
+
+ this.encodeURLString = function(string){
+ varArray = string.split('&');
+ for (i = 0; i < varArray.length; i++){
+ urlVars = varArray[i].split('=');
+ if (urlVars[0].indexOf('amp;') != -1){
+ urlVars[0] = urlVars[0].substring(4);
+ }
+ varArray[i] = this.encVar(urlVars[0],urlVars[1]);
+ }
+ return varArray.join('&');
+ }
+
+ this.runResponse = function(){
+ eval(this.response);
+ }
+
+ this.runAJAX = function(urlstring){
+ this.responseStatus = new Array(2);
+ if(this.failed && this.AjaxFailedAlert){
+ alert(this.AjaxFailedAlert);
+ } else {
+ if (urlstring){
+ if (this.URLString.length){
+ this.URLString = this.URLString + "&" + urlstring;
+ } else {
+ this.URLString = urlstring;
+ }
+ }
+ if (this.encodeURIString){
+ var timeval = new Date().getTime();
+ this.URLString = this.encodeURLString(this.URLString);
+ this.setVar("rndval", timeval);
+ }
+ if (this.element) { this.elementObj = document.getElementById(this.element); }
+ if (this.xmlhttp) {
+ var self = this;
+ if (this.method == "GET") {
+ var totalurlstring = this.requestFile + "?" + this.URLString;
+ this.xmlhttp.open(this.method, totalurlstring, true);
+ } else {
+ this.xmlhttp.open(this.method, this.requestFile, true);
+ }
+ if (this.method == "POST"){
+ try {
+ this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
+ } catch (e) {}
+ }
+
+ this.xmlhttp.send(this.URLString);
+ this.xmlhttp.onreadystatechange = function() {
+ switch (self.xmlhttp.readyState){
+ case 1:
+ self.onLoading();
+ break;
+ case 2:
+ self.onLoaded();
+ break;
+ case 3:
+ self.onInteractive();
+ break;
+ case 4:
+ self.response = self.xmlhttp.responseText;
+ self.responseXML = self.xmlhttp.responseXML;
+ self.responseStatus[0] = self.xmlhttp.status;
+ self.responseStatus[1] = self.xmlhttp.statusText;
+ self.onCompletion();
+ if(self.execute){ self.runResponse(); }
+ if (self.elementObj) {
+ var elemNodeName = self.elementObj.nodeName;
+ elemNodeName.toLowerCase();
+ if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
+ self.elementObj.value = self.response;
+ } else {
+ self.elementObj.innerHTML = self.response;
+ }
+ }
+ self.URLString = "";
+ break;
+ }
+ };
+ }
+ }
+ };
this.createAJAX();
-//if(this.failed && this.AjaxFailedAlert){ alert(this.AjaxFailedAlert); }
}
-//Setup VIM: ex: et ts=2 enc=utf-8 :