X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fformater.js;fp=js%2Fformater.js;h=a4fbc2366d4e3217c466c79d6ca5a89c485cdcbd;hp=78e240778a6b8bfa9cef54f12ef899a3000c651e;hb=5dc140390551c133ac5525725a86854ca69679af;hpb=24ed7a141aa345454300dd260bbabae3a9f92408 diff --git a/js/formater.js b/js/formater.js index 78e2407..a4fbc23 100644 --- a/js/formater.js +++ b/js/formater.js @@ -16,29 +16,30 @@ // 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.regexDomain = new RegExp("^(?:(?:" + this.protocols + ")://)(.*?)(?:$|/).*$", "i"); + this.regexTestIfProtocolExists = new RegExp("^(?:" + this.protocols + ")://.*$", "i"); this.regexProtocolName = new RegExp("^(.*?)://"); }; /** - * Formate un nick saise par l'utilisateur. - * @param nick le nick brut - * @return le nick 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(nick) { +euphorik.Formater.prototype.formatNick = function(nick) { return nick.replace(/\{|\}/g, "").trim(); }; @@ -51,34 +52,40 @@ euphorik.Formater.prototype.getSmilesHTML = function() { }; /** - * Formatage complet d'un texte. - * @m le message - * @nick 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, nick) { - return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), nick))); +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) { +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], "\"""); @@ -95,7 +102,7 @@ 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); @@ -138,7 +145,7 @@ 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 { @@ -163,7 +170,7 @@ euphorik.Formater.prototype.supprimerSmiles = function(m) { /** * 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 'traiterSmiles'. + * 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) {