Utilisateur:GôTô/objects.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.// {{Projet:JavaScript/Script|Objects}}
//--------------------------------------------------------------------------------------------objAJAX
window.objAJAX = function () {
// AJAX taken from http://jibbering.com/2002/4/httprequest.html. Thanx :)
try {
this.conn = new XMLHttpRequest();
} catch (e) {
this.conn = false;
}
this.url = null;
this.requestType = "GET";
this.unsync = true;
};
window.ajax = new objAJAX();
window.objAJAX.prototype.sendRequest = function (url, type, unsync, data) {
if (!this.conn)
return null;
if (this.conn.readyState != 0 && this.conn.readyState != 4)
return "busy";
if (url)
this.url = url;
if (type)
this.requestType = type;
if (unsync != null)
this.unsync = unsync;
//alert(this.requestType + " ++ " + this.url + " ++ " + this.unsync)
this.conn.open(this.requestType, this.url, this.unsync);
this.conn.send(data);
};
window.objAJAX.prototype.getResult = function () {
if (!this.conn)
return null;
return this.conn.responseText;
};
window.objAJAX.prototype.abort = function () {
this.conn.onreadystatechange = null;
this.conn.abort();
};
//------------------------------------------------------------------------------------------ObjCookie
window.objCookies = function () {
this.value = null;
this.name = null;
this.expires = null;
};
window.cookies = new objCookies();
window.objCookies.prototype.get = function (which) {
this.allcookies = document.cookie;
var start = this.allcookies.indexOf("; " + which + "=");
if (start == -1) {
start = this.allcookies.indexOf(which + "=");
if (start != 0)
return null;
} else
start += "; ".length;
this.name = which;
var end = this.allcookies.indexOf(";", start);
if (end == -1)
end = this.allcookies.length;
this.value = this.allcookies.substring(start + which.length + 1, end);
var arr = this.allcookies.substring(start, this.allcookies.length).split("; ");
this.expires = null;
if (arr.length > 0)
if (/expires=/.test(arr[1]))
this.expires = arr[1].substring("expires=".length, arr[1].length);
return decodeURIComponent(this.value);
};
window.objCookies.prototype.set = function (name, value, expires) {
document.cookie = name + "=" + encodeURIComponent(value) + ";" +
(expires ? "expires=" + expires + ";" : "") +
"path=/;domain=" + location.hostname + ";";
this.allcookies = document.cookie;
};
window.objCookies.prototype.setWithDelay = function (name, value, delay) {
// delay is in millisecond
var d = new Date();
d.setTime(d.getTime() + delay);
this.set(name, value, d.toGMTString());
};
window.objCookies.prototype.kill = function (which) {
if (this.get(which))
this.set(which, null, "Thu, 01-Jan-70 00:00:01 GMT");
};