1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
| /* Un script de FremyCompany */
// Cet objet contient en mémoire les objet stockés.
// Son utilisation doit se faire uniquement via
// la fonction Store pour des raisons de
// sécurité. Merci d'avance
var StoringSpace = new Array();
// Stocke un objet en mémoire et renvoie sa position
// dans celle-ci.
// Il vaut mieux ne stoker un même objet qu'une fois
// en mémoire pour ne pas faire d'encombrements.
var Store = function (obj) {
var StoringLocation = StoringSpace.length;
StoringSpace[StoringLocation]=obj;
return StoringLocation
}
// Crée une fonction identique à la première mais
// qui est liée à son objet de départ.
// Cette liaison se fait grâce à un emplacement mémoire.
// Cet emplacement s'obtient via la fonction Store.
var CreateDelegate = function (Method, StoringLocation) {
var f = Method;
f = ("" + f + "").replace(new RegExp("this","g"), "StoringSpace[" + StoringLocation + "]")
eval("f = " + f)
return f
}
// Interface Disposable : Il contient une fonction Dispose à invoquer quand
// son utilisation est terminée pour liberer la mémoire alouée.
// Les methodes sont executées dans l'ordre inverse de leur ajout
// (Dernière --> Première (Suppression des variables))
var IDisposable = function () {
// Crée l'objet contenant les fonctions de suppression de l'objet
this.DisposingMethods=new Array();
// Ajoute une fonction de suppression de l'objet
this.AddDisposingMethod=function(Func) {
this.DisposingMethods[this.DisposingMethods.length]=Func
}
// Ajoute la fonction Disposing de base (suppression des propriétés)
this.AddDisposingMethod(function () {
for (key in this) {
this[key]=null
}
})
// Execute toutes les fonctions de suppression de l'objet
this.Dispose=function() {
for (var i=this.DisposingMethods.length-1;i!=-1;i--) {
this.DisposingMethods[i]()
}
}
}
// Interface Storable : Il contient une propriété StoringLocation qui
// renvoie sa position dans la mémoire.
// L'interface IStorable hérite de l'interface IDisposable
var IStorable = function () {
// Construction de l'héritable de IDisposable
this.IDisposable=IDisposable;
this.IDisposable();
// Stockage de l'objet
this.StoringLocation=Store(this);
// Ajout d'une fonction de suppression de l'objet qui le supprime
// définitivement de la mémoire
this.AddDisposingMethod(CreateDelegate(function () {
// Enlève l'objet de la mémoire
// Notez que this est remplacé par StoringSpace[{x}]
eval("this" + "=null");
}, this.StoringLocation))
// Crée un délégué pour la méthode suivante
this.CreateDelegate=function(Method) {
return CreateDelegate(Method, this.StoringLocation)
}
// Convertit toutes les methodes d'un objet en délégué
this.CreateDelegateForAll=function() {
for (key in this) {
if (typeof (this[key]) == "function") {
this[key]=CreateDelegate(this[key], this.StoringLocation)
}
}
}
}
// Class UserError : Contient les informations sur une erreur
var UserError = function (ErrorCode, Message, InnerException, Source, Data) {
this.ErrorCode=ErrorCode;
this.Message=Message;
this.InnerException=InnerException;
this.Source=Source;
this.Data=Data
this.toString=function () {
var text = "Erreur non-gérée à : " + Source + " (Code d'erreur :" + this.ErrorCode + ")\n\n";
text += "Message :\n";
text += this.Message + "\n\n";
text += "Informations complémentaires :\n";
text += this.InnerException.message;
text += ((this.Data) ? ("\nDes données sont disponibles") : (""))
return text;
}
}
// Interface ErrorGestable : Il contient un evenement OnError qui s'execute en
// cas d'erreur dans les fonctions.
// Il demande un effort de codage pour le programmeur mais reste némaoins
// très pratique pour la gestion d'erreur.
var IErrorGestable = function () {
this.OnError=function () {return false;}
this.Errors=new Array();
this.AddError=function (ErrorCode, Message) {
this.Errors[ErrorCode]=Message;
}
this.ThrowError= function(ErrorCode, e, Source, Data) {
if (this.OnError(new UserError(ErrorCode, this.Errors[ErrorCode], e, Source, Data))==false) {
throw (e);
}
}
this.AddError(-1, "Erreur de type inconnu")
}
// Classe Xhr : Cette classe offre un interface simple pour gerer
// l'objet XmlHttpRequest de manière simple et cross-browser
// Il implémente l'interface IStorable et IErrorGestable
var Xhr = function () {
// Implémente l'interface IStorable
this.IStorable=IStorable;
this.IStorable();
// Implémente l'interface IErrorGestable
this.IErrorGestable=IErrorGestable;
this.IErrorGestable();
this.CreateXhrError=0;
this.OpenXhrError=1;
this.SendXhrError=2;
this.GestureError=3;
this.RequestError=4;
this.ServerError=5;
this.AddError(0, "Votre navigateur ne prend pas en charge l'objet XmlHttpRequest")
this.AddError(1, "Impossible d'ouvrir la connexion avec le serveur")
this.AddError(2, "Impossible d'envoyer les données au serveur")
this.AddError(3, "La gestion de la reception des données par le code client a renvoyé une erreur")
this.AddError(4, "Le serveur a renvoyé une erreur de type requête")
this.AddError(5, "Le serveur a renvoyé une erreur de type serveur (le serveur est peut-être sur chargé)")
// Declare les variables
this.Xhr=null;
this.OnReayStateChange=function () {}
// Fonction de recuperation automatique de données
this.GetDataFromDiv=function (El) {
try {
var Inputs=El.getElementsByTagName("INPUT")
var datas="";
for (var key=0;key<Inputs.length;key++) {
try {
var Input=Inputs[key]
var DataName = escape(Input.name)
if (DataName != "" && DataName != null) {
var DataValue = escape(Input.value)
var Data = DataName + "=" + DataValue
if (datas != "") {
datas = datas + "&"
}
datas=datas+Data
}
} catch (ex) {}
}
Inputs=El.getElementsByTagName("TEXTAREA")
for (var key=0;key<Inputs.length;key++) {
try {
var Input=Inputs[key]
var DataName = escape(Input.name)
if (DataName != "" && DataName != null) {
var DataValue = escape(Input.value)
var Data = DataName + "=" + DataValue
if (datas != "") {
datas = datas + "&"
}
datas=datas+Data
}
} catch (ex) {}
}
return datas
} catch (ex) {
this.ThrowError(-1, ex, "Xhr.GetDataFormDiv", El)
}
}
// Fonction d'ouverture
this.Send=function(Mode, Url, Async, Data, OnReadyStateChange, PrepareSub, UserName, Pwd) {
// Verrification de l'état actuel de l'objet
if (this.Xhr!=null) {
var e="Objet occupé !";
try {
throw (e);
}
catch (ex) {
e=ex;
}
finally {
this.ThrowError(0, e, "Xhr.Send");
}
}
// Creation de l'objet XHR
try {
this.Xhr=GetXmlHttpRequest()
} catch (ex) {
this.ThrowError(0, ex, "Xhr.Send")
}
// Overture de l'objet
try {
this.Xhr.open(Mode, Url, Async, UserName, Pwd)
} catch (ex) {
this.ThrowError(1, ex, "Xhr.Send", Xhr)
}
// Preparation
try {
if (PrepareSub) {
PrepareSub(this.Xhr);
}
} catch (ex) {
this.ThrowError(-1, ex, "Xhr.Send:PrepareSub(this.Xhr)", PrepareSub)
}
// OnReadyStateChange
try {
if (OnReadyStateChange && typeof (OnReadyStateChange) == "function") {
this.OnReadyStateChange=OnReadyStateChange;
}
this.Xhr.onreadystatechange=CreateDelegate(function () {
try {
try {
var Status="" + this.Xhr.status + ""
Staus=Status.charAt(0);
if (Status == 4) {
this.ThrowError(4, "", "Xhr.OnReadyStateChange")
}
else if (Status == 5) {
this.ThrowError(5, "", "Xhr.OnReadyStateChange")
}
} catch (ex_1) {}
this.OnReadyStateChange(this.Xhr);
} catch (ex) {
this.ThrowError(3,ex,"Xhr.OnReadyStateChange")
}
}, this.StoringLocation);
} catch (ex) {
this.ThrowError(-1, ex, "Xhr.Send:this.Xhr.onreadystatechange=OnReadyStateChange", OnReadyStateChange)
}
// Envoi des données
try {
this.Xhr.send(Data)
} catch (ex) {
this.ThrowError(2, ex, "Xhr:Send")
}
}
// Modifie le contenu d'une Div ciblée au moyen du texte de retour serveur
// Cette fonction evalue les scripts et tente de valider les ID
this.UpdateDiv=function(Mode, Url, Async, Data, Div, PrepareSub, UserName, Pwd) {
this.divContent=Div;
var OnReadyStateChange=CreateDelegate(function () {
if (this.Xhr.readyState==4) {
this.divContent.innerHTML=this.Xhr.responseText;
try {
var Elements = this.divContent.childNodes;
var i=0;
while (Elements[i]) {
Elements[i].id=Elements[i].getAttribute("id")
i++
}
} catch (ex) {}
try {
var Scripts = this.divContent.getElementsByTagName("SCRIPT")
for (var i=0;i<Scripts.length;i++) {
try {
var Script = '"' + (Scripts[i].innerHTML).replace(new RegExp('"',"g"),'\\"') + '"';
var Func = function() {
eval("");
}
Func = "" + Func + ""
Func=Func.replace('""', Script)
eval("Func = " + Func)
AsyncCall(Func)
} catch (ex) {}
}
} catch (ex) {}
}
}, this.StoringLocation)
this.Send(Mode, Url, Async, Data, OnReadyStateChange, PrepareSub, UserName, Pwd)
}
this.EvalJS=function (Mode, Url, Async, Data, PrepareSub, UserName, Pwd) {
var OnReadyStateChange=CreateDelegate(function () {
if (this.Xhr.redyState==4) {
eval(this.Xhr.responseText)
}
}, this.StoringLocation)
this.Send(Mode, Url, Async, Data, OnReadyStateChange, PrepareSub, UserName, Pwd)
}
}
// Renvoie le texte de l'objet ActiveXObject le plus récent depuis une liste
var pickRecentProgID = function (idList){
// found progID flag
var bFound = false;
for(var i=0; i < idList.length && !bFound; i++){
try{
var oDoc = new ActiveXObject(idList[i]);
o2Store = idList[i];
bFound = true;
}catch (objException){
// trap; try next progID
};
};
if (!bFound)
throw ("Aucun ActiveXObject n'est valide sur votre ordinateur, pensez à mettre à jour votre navigateur");
idList = null;
return o2Store;
}
// Retourne un nouvel objet XmlHttpRequest
var GetXmlHttpRequest_AXO=null
var GetXmlHttpRequest=function () {
if (window.XMLHttpRequest) {
return new XMLHttpRequest()
}
else if (window.ActiveXObject) {
if (!GetXmlHttpRequest_AXO) {
GetXmlHttpRequest_AXO=pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
}
return new ActiveXObject(GetXmlHttpRequest_AXO)
}
return false;
}
// Execute une fonction indépendante de manière asynchrone
var AsyncCall = function (Method, Time) {
var T = ((Time) ? (Time) : 0)
setTimeout(Method, T)
}
// Crée une propriété pour un objet
var CreateProperty = function (Obj,Name, Get, Set) {
eval("Obj[Name]=function(value) {\n" +
" if (value || typeof (value) == 'boolean') {\n" +
" this['set_" + Name + "'](value)\n" +
" }\n" +
" else {\n" +
" return this['get_" + Name + "']()\n" +
" }\n" +
"}");
if (Get) {
Obj["get_"+Name]=Get;
}
if (Set) {
Obj["set_"+Name]=Set;
}
}
String.prototype.trim = function(Char) {
if (!Char) {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
else {
return this.replace(new RegExp("(^" + Char + "*)|(" + Char + "*$)","g"),"")
}
} |
Partager