X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Feuphorik.js;h=400f2154b0ac01b45932600d81f44f6232cd57f9;hp=b93498f7e071632aa33f29f58ffb404a20d2b6f4;hb=107016b49c680e6bc4ff8ae9685f7c57e46cc450;hpb=7fb422d6d4a7a59c8f74d938371a4a10474e8ea4 diff --git a/js/euphorik.js b/js/euphorik.js index b93498f..400f215 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -614,10 +614,10 @@ Client.prototype.kick = function(userId, raison) * { * "reply" : * } - * @page la page + * @page la page courante pour laquelle on écoute des événements + * @util le helper 'util' */ -function PageEvent(page, util) -{ +function PageEvent(page, util) { this.page = page this.util = util @@ -631,12 +631,10 @@ function PageEvent(page, util) /** * Arrête l'attente courante s'il y en a une. */ -PageEvent.prototype.stopAttenteCourante = function() -{ +PageEvent.prototype.stopAttenteCourante = function() { this.stop = true - if (this.attenteCourante != null) - { + if (this.attenteCourante != null) { this.attenteCourante.abort() } } @@ -648,8 +646,7 @@ PageEvent.prototype.stopAttenteCourante = function() * les fonctions acceptent un paramètre correspondant au données reçues. * exemple : {"new_message" : function(data){ ... }} */ -PageEvent.prototype.waitEvent = function(funSend, funsReceive) -{ +PageEvent.prototype.waitEvent = function(funSend, funsReceive) { this.stopAttenteCourante() this.stop = false @@ -658,14 +655,14 @@ PageEvent.prototype.waitEvent = function(funSend, funsReceive) // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole) // TODO : ya pas mieux ? - var dataToSend = - { + var dataToSend = { "header" : { "action" : "wait_event", "version" : euphorik.conf.versionProtocole }, "page" : this.page } var poulpe = funSend() - for (var v in poulpe) - dataToSend[v] = poulpe[v] + for (var v in poulpe) { + dataToSend[v] = poulpe[v] + } this.attenteCourante = jQuery.ajax({ type: "POST", @@ -675,31 +672,29 @@ PageEvent.prototype.waitEvent = function(funSend, funsReceive) timeout: 180000, // timeout de 3min. Gros HACK pas beau. FIXME problème décrit ici : http://groups.google.com/group/jquery-en/browse_thread/thread/8724e64af3333a76 data: this.util.jsonVersAction(dataToSend), success: - function(data) - { + function(data) { funsReceive[data["reply"]](data) // rappel de la fonction dans 100 ms setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funsReceive) }, 100) }, error: - function(XMLHttpRequest, textStatus, errorThrown) - { - ;; console.log("Connexion perdue dans waitEvent") + function(XMLHttpRequest, textStatus, errorThrown) { + ;; console.log("Connexion perdue dans PageEvent.prototype.waitEvent()") setTimeout(function(){ thisPageEvent.waitEvent2(funSend, funsReceive) }, 1000) } - }) -} + }); +}; /** * Si un stopAttenteCourante survient un peu n'importe quand il faut imédiatement arreter de boucler. */ -PageEvent.prototype.waitEvent2 = function(funSend, funsReceive) -{ - if (this.stop) - return - this.waitEvent(funSend, funsReceive) -} +PageEvent.prototype.waitEvent2 = function(funSend, funsReceive) { + if (this.stop) { + return; + } + this.waitEvent(funSend, funsReceive); +}; ///////////////////////////////////////////////////////////////////////////////////////////////////