Do not ignore our handlebars plugins in eslint

This commit is contained in:
Pavel Djundik 2016-05-12 16:07:15 +03:00
parent bbf7b8086f
commit 876ce4bc6e
6 changed files with 68 additions and 59 deletions

View file

@ -1,3 +1,7 @@
# built by tools
client/js/libs.min.js client/js/libs.min.js
client/js/libs/**/*.js
client/js/lounge.templates.js client/js/lounge.templates.js
# third party
client/js/libs/jquery/*.js
client/js/libs/*.js

View file

@ -2,7 +2,7 @@ var diff;
Handlebars.registerHelper( Handlebars.registerHelper(
"diff", function(a, opt) { "diff", function(a, opt) {
if (a != diff) { if (a !== diff) {
diff = a; diff = a;
return opt.fn(this); return opt.fn(this);
} else { } else {

View file

@ -2,7 +2,7 @@ Handlebars.registerHelper(
"equal", function(a, b, opt) { "equal", function(a, b, opt) {
a = a.toString(); a = a.toString();
b = b.toString(); b = b.toString();
if (a == b) { if (a === b) {
return opt.fn(this); return opt.fn(this);
} else { } else {
return opt.inverse(this); return opt.inverse(this);

View file

@ -9,7 +9,7 @@ Handlebars.registerHelper(
); );
function uri(text) { function uri(text) {
return URI.withinString(text, function(url, start, end, source) { return window.URI.withinString(text, function(url) {
if (url.indexOf("javascript:") === 0) { if (url.indexOf("javascript:") === 0) {
return url; return url;
} }
@ -43,77 +43,82 @@ function channels(text) {
* https://github.com/megawac/irc-style-parser/tree/shout * https://github.com/megawac/irc-style-parser/tree/shout
*/ */
var styleCheck_Re = /[\x00-\x1F]/, var styleCheck_Re = /[\x00-\x1F]/,
back_re = /^([0-9]{1,2})(,([0-9]{1,2}))?/, back_re = /^([0-9]{1,2})(,([0-9]{1,2}))?/,
colourKey = "\x03", colourKey = "\x03",
// breaks all open styles ^O (\x0F) // breaks all open styles ^O (\x0F)
styleBreak = "\x0F"; styleBreak = "\x0F";
function styleTemplate(settings) { function styleTemplate(settings) {
return "<span class='" + settings.style + "'>" + settings.text + "</span>"; return "<span class='" + settings.style + "'>" + settings.text + "</span>";
} }
var styles = [ var styles = [
["normal", "\x00", ""], ["underline", "\x1F"], ["normal", "\x00", ""], ["underline", "\x1F"],
["bold", "\x02"], ["italic", "\x1D"] ["bold", "\x02"], ["italic", "\x1D"]
].map(function(style) { ].map(function(style) {
var escaped = encodeURI(style[1]).replace("%", "\\x"); var escaped = encodeURI(style[1]).replace("%", "\\x");
return { return {
name: style[0], name: style[0],
style: style[2] != null ? style[2] : "irc-" + style[0], style: style[2] ? style[2] : "irc-" + style[0],
key: style[1], key: style[1],
keyregex: new RegExp(escaped + "(.*?)(" + escaped + "|$)") keyregex: new RegExp(escaped + "(.*?)(" + escaped + "|$)")
}; };
}); });
function colors(line) { function colors(line) {
// http://www.mirc.com/colors.html // http://www.mirc.com/colors.html
// http://www.aviran.org/stripremove-irc-client-control-characters/ // http://www.aviran.org/stripremove-irc-client-control-characters/
// https://github.com/perl6/mu/blob/master/examples/rules/Grammar-IRC.pm // https://github.com/perl6/mu/blob/master/examples/rules/Grammar-IRC.pm
// regexs are cruel to parse this thing // regexs are cruel to parse this thing
// already done? // already done?
if (!styleCheck_Re.test(line)) return line; if (!styleCheck_Re.test(line)) {
return line;
}
// split up by the irc style break character ^O // split up by the irc style break character ^O
if (line.indexOf(styleBreak) >= 0) { if (line.indexOf(styleBreak) >= 0) {
return line.split(styleBreak).map(colors).join(""); return line.split(styleBreak).map(colors).join("");
} }
var result = line; var result = line;
var parseArr = result.split(colourKey); var parseArr = result.split(colourKey);
var text, match, colour, background = ""; var text, match, colour, background = "";
for (var i = 0; i < parseArr.length; i++) { for (var i = 0; i < parseArr.length; i++) {
text = parseArr[i]; text = parseArr[i];
match = text.match(back_re); match = text.match(back_re);
if (!match) { if (!match) {
// ^C (no colour) ending. Escape current colour and carry on // ^C (no colour) ending. Escape current colour and carry on
background = ""; background = "";
continue; continue;
} }
colour = "irc-fg" + +match[1]; colour = "irc-fg" + +match[1];
// set the background colour // set the background colour
if (match[3]) { if (match[3]) {
background = " irc-bg" + +match[3]; background = " irc-bg" + +match[3];
} }
// update the parsed text result // update the parsed text result
result = result.replace(colourKey + text, styleTemplate({ result = result.replace(colourKey + text, styleTemplate({
style: colour + background, style: colour + background,
text: text.slice(match[0].length) text: text.slice(match[0].length)
})); }));
} }
// Matching styles (italics/bold/underline) // Matching styles (italics/bold/underline)
// if only colours were this easy... // if only colours were this easy...
styles.forEach(function(style) { styles.forEach(function(style) {
if (result.indexOf(style.key) < 0) return; if (result.indexOf(style.key) < 0) {
result = result.replace(style.keyregex, function(match, text) { return;
return styleTemplate({ }
"style": style.style,
"text": text
});
});
});
return result; result = result.replace(style.keyregex, function(match, text) {
return styleTemplate({
"style": style.style,
"text": text
});
});
});
return result;
} }

View file

@ -1,5 +1,5 @@
Handlebars.registerHelper( Handlebars.registerHelper(
"stringcolor", function(str) { "stringcolor", function(str) {
return stringcolor(str); return window.stringcolor(str);
} }
); );

View file

@ -1,5 +1,5 @@
Handlebars.registerHelper( Handlebars.registerHelper(
"users", function(count) { "users", function(count) {
return count + " " + (count == 1 ? "user" : "users"); return count + " " + (count === 1 ? "user" : "users");
} }
); );