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