X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Fformater.js;h=a4fbc2366d4e3217c466c79d6ca5a89c485cdcbd;hb=0fd41878c239877c274bd2bf58caf65b24977e52;hp=349abe759871cdf8e8d96620dea61de88c743678;hpb=eb44db02bab9c8b082201aa153dea8229432e894;p=euphorik.git
diff --git a/js/formater.js b/js/formater.js
index 349abe7..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 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();
};
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
- * @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) {
- 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;
@@ -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);
@@ -111,13 +118,13 @@ euphorik.Formater.prototype.traiterURL = function(m, nick) {
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], "");
}
@@ -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) {