X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fformater.js;h=a4fbc2366d4e3217c466c79d6ca5a89c485cdcbd;hp=eec87f8180014b8f5a10c7e85f9e87699502aac7;hb=5dc140390551c133ac5525725a86854ca69679af;hpb=09608ab29e1c39ea51b51a5f8669dcde36efb306 diff --git a/js/formater.js b/js/formater.js index eec87f8..a4fbc23 100644 --- a/js/formater.js +++ b/js/formater.js @@ -16,72 +16,79 @@ // You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . +/*jslint laxbreak:true */ /** - * Objet permettant de formater du texte par exemple pour la substitution des liens dans les - * message par "[url]". - * TODO : améliorer l'efficacité des méthods notamment lié au smiles. + * An object for text formatting like Wiki syntax or smiles substitution. + * TODO : improve the performance of the smiles substitution */ euphorik.Formater = function() { this.smiles = euphorik.conf.smiles; - this.protocoles = "http|https|ed2k"; + this.protocols = "http|https|ed2k"; - this.regexUrl = new RegExp("(?:(?:" + this.protocoles + ")://|www\\.)[^ ]*", "gi"); + this.regexUrl = new RegExp("(?:(?:" + this.protocols + ")://|www\\.)[^ ]*", "gi"); this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i"); - this.regexDomaine = new RegExp("^(?:(?:" + this.protocoles + ")://)(.*?)(?:$|/).*$", "i"); - this.regexTestProtocoleExiste = new RegExp("^(?:" + this.protocoles + ")://.*$", "i"); - this.regexNomProtocole = new RegExp("^(.*?)://"); + this.regexDomain = new RegExp("^(?:(?:" + this.protocols + ")://)(.*?)(?:$|/).*$", "i"); + this.regexTestIfProtocolExists = new RegExp("^(?:" + this.protocols + ")://.*$", "i"); + this.regexProtocolName = new RegExp("^(.*?)://"); }; /** - * Formate un pseudo saise par l'utilisateur. - * @param pseudo le pseudo brut - * @return le pseudo filtré + * Formats a nick given by the user. + * Trim and remove "{..}". + * @param nick the given nick + * @return the cleaned nick */ -euphorik.Formater.prototype.filtrerInputPseudo = function(pseudo) { - return pseudo.replace(/\{|\}/g, "").trim(); +euphorik.Formater.prototype.formatNick = function(nick) { + return nick.replace(/\{|\}/g, "").trim(); }; euphorik.Formater.prototype.getSmilesHTML = function() { var XHTML = ""; - objectEach(this.smiles, function(nom) { - XHTML += "\"""; + objectEach(this.smiles, function(name) { + XHTML += "\"""; }); return XHTML; }; /** - * Formatage complet d'un texte. - * @m le message - * @pseudo facultatif, permet de contruire le label des images sous la forme : " : " + * Complete fomratting process applied to a text. + * - Remove HTML markups + * - Substitutes wiki syntax with HTML + * - Replaces URL with 'a' tag + * - Replaces smiles with HTML + * - Replaces the link to a conversation with HTML + * @m the raw message + * @nick optional, attaches the nick and the message to each images like " : " */ -euphorik.Formater.prototype.traitementComplet = function(m, pseudo) { - return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), pseudo))); +euphorik.Formater.prototype.completeProcessing = function(m, nick) { + return this.processConversationLinks(this.processSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), nick))); }; /** - * Transforme les liens en entités clickables. - * Un lien vers une conversation permet d'ouvrire celle ci, elle se marque comme ceci dans un message : - * "{5F}" ou 5F est la racine de la conversation. - * Ce lien sera transformer en {5F} pouvant être clické pour créer la conv 5F. + * Processes all conversation links. + * The user can click on a conversation link to open it. + * A link is a number in between brackets like that : "{5F}" where '5F' is the id of the root message. + * This link will be turn in '{5F}' which can be clicked to open the '5F' conversation. */ -euphorik.Formater.prototype.traiterLiensConv = function(m) { +euphorik.Formater.prototype.processConversationLinks = function(m) { return m.replace( /\{\w+\}/g, function(lien) { - return "" + lien + ""; + return "" + lien + ""; } ); }; /** - * FIXME : Cette méthode est attrocement lourde ! A optimiser. - * moyenne sur échantillon : 234ms + * Substitute the smiles (':)', ':P', etc.) with HTML. + * FIXME : This function is very heavy, to optimize ! + * Average : 234ms */ -euphorik.Formater.prototype.traiterSmiles = function(m) { - objectEach(this.smiles, function(nom, smiles) { +euphorik.Formater.prototype.processSmiles = function(m) { + objectEach(this.smiles, function(name, smiles) { for (var i = 0; i < smiles.length; i++) { - m = m.replace(smiles[i], "\"""); + m = m.replace(smiles[i], "\"""); } }); return m; @@ -91,15 +98,15 @@ euphorik.Formater.prototype.remplacerBalisesHTML = function(m) { return m.replace(//g, ">").replace(/"/g, """); }; -euphorik.Formater.prototype.traiterURL = function(m, pseudo) { +euphorik.Formater.prototype.traiterURL = function(m, nick) { var thisFormater = this; var traitementUrl = function(url) { // si ya pas de protocole on rajoute "http://" - if (!thisFormater.regexTestProtocoleExiste.test(url)) { + if (!thisFormater.regexTestIfProtocolExists.test(url)) { url = "http://" + url; } var extension = thisFormater.getShort(url); - return "[" + extension[0] + "]"; + return "[" + extension[0] + "]"; }; return m.replace(this.regexUrl, traitementUrl); }; @@ -111,13 +118,13 @@ euphorik.Formater.prototype.traiterURL = function(m, pseudo) { euphorik.Formater.prototype.traiterWikiSyntaxe = function(m) { return m.replace( /(?:^| )_(.*?)_(?:$| )/g, - function(texte, capture) { - return '' + capture + ''; + function(texte, c1, c2, c3) { + return '' + c1 + c2 + c3 + ''; } ).replace( /(?:^| )\*(.*?)\*(?:$| )/g, - function(texte, capture) { - return '' + capture + ''; + function(texte, c1, c2, c3) { + return '' + c1 + c2 + c3 + ''; } ); }; @@ -138,13 +145,13 @@ euphorik.Formater.prototype.getShort = function(url) { } estUneImage = true; } else { - var rechercheDomaine = this.regexDomaine.exec(url); + var rechercheDomaine = this.regexDomain.exec(url); if (rechercheDomaine && rechercheDomaine.length >= 2) { versionShort = rechercheDomaine[1]; } else { - var nomProtocole = this.regexNomProtocole.exec(url); - if (nomProtocole && nomProtocole.length >= 2) { - versionShort = nomProtocole[1]; + var protocolName = this.regexProtocolName.exec(url); + if (protocolName && protocolName.length >= 2) { + versionShort = protocolName[1]; } } } @@ -153,7 +160,7 @@ euphorik.Formater.prototype.getShort = function(url) { }; euphorik.Formater.prototype.supprimerSmiles = function(m) { - objectEach(this.smiles, function(nom, smiles) { + objectEach(this.smiles, function(name, smiles) { for (var i = 0; i < smiles.length; i++) { m = m.replace(smiles[i], ""); } @@ -162,8 +169,8 @@ euphorik.Formater.prototype.supprimerSmiles = function(m) { }; /** - * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox. - * Supprime les smiles pour pas qu'ils puissent être remplacés par la fonction 'traiterSmiles'. + * Traite les nick et messages à être affiché dans le titre d'une image visualisé avec lightbox. + * Supprime les smiles pour pas qu'ils puissent être remplacés par la fonction 'processSmiles'. * TODO : trouver un moyen pour que les smiles puissent être conservés */ euphorik.Formater.prototype.traiterPourFenetreLightBox = function(M, urlCourante) {