Skip to content

Commit

Permalink
Various connection functions to experimental or fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Apr 2, 2009
1 parent bfe2bc5 commit 9ebdbde
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 34 deletions.
38 changes: 24 additions & 14 deletions _experimental/misc/connection_aborted.js
@@ -1,23 +1,33 @@
function connection_aborted() {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brettz9.blogspot.com)
// % note 1: Really should be defined as a closure to avoid re-adding
// % note 1: event listeners (could also remove each time)
// * example 1: connection_aborted();
// * returns 1: 0

var retVal = 0;
if (!this.php_js) {
this.php_js = {};
}
if (!this.php_js.abortStatus) {
this.php_js.abortStatus = 0;
}

window.addEventListener('abort', function(e){
retVal = 1;
}, false);
window.addEventListener('unload', function(e){
retVal = 1;
}, false);
window.addEventListener('stop', function(e){
retVal = 1;
}, false);
// These functions should really be set automatically (added with addEventListener once), but for now this function can be used as a trigger to set these checks up
var that = this;
window.onabort = function(e){
if (!that.php_js.ignoreAbort) {
that.php_js.abortStatus = 1;
}
};
window.onunload = function(e){
if (!that.php_js.ignoreAbort) {
that.php_js.abortStatus = 1;
}
};
window.onstop = function(e){
if (!that.php_js.ignoreAbort) {
that.php_js.abortStatus = 1;
}
};

return retVal;
// return function () {return retVal;}
return this.php_js.abortStatus;
}
15 changes: 15 additions & 0 deletions _experimental/misc/connection_status.js
@@ -0,0 +1,15 @@
function connection_status () {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brettz9.blogspot.com)
// * example 1: connection_status();
// * returns 1: 3

var ret = 0; // NORMAL
if (this.php_js && this.php_js.abortStatus) {
ret += 1; // ABORTED
}
if (this.php_js && this.php_js.timeoutStatus) {
ret += 2; // TIMEOUT
}
return ret;
}
8 changes: 8 additions & 0 deletions _experimental/misc/connection_timeout.js
@@ -0,0 +1,8 @@
function connection_timeout () {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brettz9.blogspot.com)
// * example 1: connection_timeout();
// * returns 1: 0

return this.php_js && this.php_js.timeoutStatus ? 1 : 0;
}
41 changes: 25 additions & 16 deletions _experimental/misc/ignore_user_abort.js
@@ -1,4 +1,4 @@
function ignore_user_abort() {
function ignore_user_abort (setting) {
// http://kevin.vanzonneveld.net
// + original by: Brett Zamir (http://brettz9.blogspot.com)
// % note 1: We cannot get the exact PHP meaning of abort, since 'abort', per the
Expand All @@ -7,25 +7,34 @@ function ignore_user_abort() {
// % note 1: clicking "stop" as the page is loading
// % note 2: While this code presumably should work, at least in Firefox, it
// % note 2: does not (perhaps due to a bug in Firefox)
// % note 3: This function should be defined as a closure, with "();" after the last
// % note 3: brace and defined as var ignore_user_abort = function () { ...
// * example 1: ignore_user_abort(true);
// * returns 1: 0

var prev_setting = 0;
if (!this.php_js) {
this.php_js = {};
}
if (!this.php_js.ignoreUserAbort) {
this.php_js.ignoreUserAbort = 0;
}

return function (setting) {
var old_prev_setting = prev_setting;

if (setting) {
window.addEventListener('unload', function(e){e.preventDefault();e.stopPropagation();}, false);
window.addEventListener('abort', function(e){e.preventDefault();e.stopPropagation();}, false);
window.addEventListener('stop', function(e){e.preventDefault();e.stopPropagation();}, false);
prev_setting = 1;
return old_prev_setting;
}
prev_setting = 0;
var old_prev_setting = this.php_js.ignoreUserAbort;

if (setting) {
if (!this.php_js.ignoreAbort) {
this.php_js.ignoreAbort = true;
}
window.onunload = function(e){e.preventDefault();e.stopPropagation();};
window.onabort = function(e){e.preventDefault();e.stopPropagation();};
window.onstop = function(e){e.preventDefault();e.stopPropagation();};
this.php_js.ignoreUserAbort = 1;
return old_prev_setting;
};
}
else if (setting === false) {
if (!this.php_js.ignoreAbort) {
this.php_js.ignoreAbort = false;
}
}
this.php_js.ignoreUserAbort = 0;

return old_prev_setting;
}
1 change: 0 additions & 1 deletion _notporting/misc/connection_status.js

This file was deleted.

1 change: 0 additions & 1 deletion _notporting/misc/connection_timeout.js

This file was deleted.

12 changes: 10 additions & 2 deletions functions/info/set_time_limit.js
Expand Up @@ -3,6 +3,14 @@ function set_time_limit(seconds) {
// + original by: Brett Zamir (http://brettz9.blogspot.com)
// * example 1: set_time_limit(4);
// * returns 1: undefined

window.setTimeout(function () {throw 'Maximum execution time exceeded';}, seconds*1000);
if (!this.php_js) {
this.php_js = {};
}

window.setTimeout(function () {
if (!this.php_js.timeoutStatus) {
this.php_js.timeoutStatus = true;
}
throw 'Maximum execution time exceeded';
}, seconds*1000);
}

0 comments on commit 9ebdbde

Please sign in to comment.