// 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.regexNomProtocole = new RegExp("^(.*?)://");\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 pseudo saise par l'utilisateur.\r
- * @param pseudo le pseudo brut\r
- * @return le pseudo 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(pseudo) {\r
- return pseudo.replace(/\{|\}/g, "").trim();\r
+euphorik.Formater.prototype.formatNick = function(nick) {\r
+ return nick.replace(/\{|\}/g, "").trim();\r
};\r
\r
euphorik.Formater.prototype.getSmilesHTML = function() {\r
var XHTML = "";\r
- objectEach(this.smiles, function(nom) {\r
- XHTML += "<img class=\"" + nom + "\" src=\"img/smileys/" + nom + ".gif\" alt =\"" + nom + "\" />";\r
+ objectEach(this.smiles, function(name) {\r
+ XHTML += "<img class=\"" + name + "\" src=\"img/smileys/" + name + ".gif\" alt =\"" + name + "\" />";\r
});\r
return XHTML;\r
};\r
\r
/**\r
- * Formatage complet d'un texte.\r
- * @m le message\r
- * @pseudo 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, pseudo) {\r
- return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), pseudo)));\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
- objectEach(this.smiles, function(nom, smiles) {\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/" + nom + ".gif\" alt =\"" + nom + "\" />");\r
+ m = m.replace(smiles[i], "<img src=\"img/smileys/" + name + ".gif\" alt =\"" + name + "\" />");\r
}\r
});\r
return m;\r
return m.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);\r
};\r
\r
-euphorik.Formater.prototype.traiterURL = function(m, pseudo) {\r
+euphorik.Formater.prototype.traiterURL = function(m, nick) {\r
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
- return "<a " + (extension[1] ? "title=\"" + (pseudo ? thisFormater.traiterPourFenetreLightBox(pseudo, url) + ": " : "") + thisFormateur.traiterPourFenetreLightBox(m, url) + "\"" + " rel=\"lightbox\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>";\r
+ return "<a " + (extension[1] ? "title=\"" + (nick ? thisFormater.traiterPourFenetreLightBox(nick, url) + ": " : "") + thisFormateur.traiterPourFenetreLightBox(m, url) + "\"" + " rel=\"lightbox\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>";\r
};\r
return m.replace(this.regexUrl, traitementUrl);\r
};\r
euphorik.Formater.prototype.traiterWikiSyntaxe = function(m) {\r
return m.replace(\r
/(?:^| )_(.*?)_(?:$| )/g,\r
- function(texte, capture) {\r
- return '<em class="leger">' + capture + '</em>';\r
+ function(texte, c1, c2, c3) {\r
+ return '<em>' + c1 + c2 + c3 + '</em>';\r
}\r
).replace(\r
/(?:^| )\*(.*?)\*(?:$| )/g,\r
- function(texte, capture) {\r
- return '<em class="fort">' + capture + '</em>';\r
+ function(texte, c1, c2, c3) {\r
+ return '<strong>' + c1 + c2 + c3 + '</strong>';\r
}\r
);\r
};\r
}\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
- var nomProtocole = this.regexNomProtocole.exec(url);\r
- if (nomProtocole && nomProtocole.length >= 2) {\r
- versionShort = nomProtocole[1];\r
+ var protocolName = this.regexProtocolName.exec(url);\r
+ if (protocolName && protocolName.length >= 2) {\r
+ versionShort = protocolName[1];\r
}\r
}\r
}\r
};\r
\r
euphorik.Formater.prototype.supprimerSmiles = function(m) {\r
- objectEach(this.smiles, function(nom, smiles) {\r
+ objectEach(this.smiles, function(name, smiles) {\r
for (var i = 0; i < smiles.length; i++) {\r
m = m.replace(smiles[i], "");\r
}\r
};\r
\r
/**\r
- * Traite les pseudo 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
+ * 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 'processSmiles'.\r
* TODO : trouver un moyen pour que les smiles puissent être conservés\r
*/\r
euphorik.Formater.prototype.traiterPourFenetreLightBox = function(M, urlCourante) {\r