From 6c6e76afdaf16b78d895d350a036c950dc636a48 Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Sat, 27 Sep 2014 16:47:04 -0700 Subject: [PATCH] Persist inline links --- client/js/shout.js | 2 +- client/js/shout.templates.js | 33 +++++++++++++++++++++++---------- client/templates/msg.tpl | 11 +++++++---- client/templates/toggle.tpl | 2 ++ package.json | 2 +- src/plugins/irc-events/link.js | 33 ++++++++++++++++----------------- 6 files changed, 50 insertions(+), 33 deletions(-) diff --git a/client/js/shout.js b/client/js/shout.js index f2a6e070..a99a416d 100644 --- a/client/js/shout.js +++ b/client/js/shout.js @@ -278,7 +278,7 @@ $(function() { socket.on("toggle", function(data) { var toggle = $("#toggle-" + data.id); - toggle.parent().after(render("toggle", data)); + toggle.parent().after(render("toggle", {toggle: data})); switch (data.type) { case "link": if (options.links) { diff --git a/client/js/shout.templates.js b/client/js/shout.templates.js index 30efdcfa..ee963e6c 100644 --- a/client/js/shout.templates.js +++ b/client/js/shout.templates.js @@ -84,7 +84,7 @@ templates['msg'] = template({"1":function(depth0,helpers,partials,data) { buffer += " \n \n " + escapeExpression(((helper = (helper = helpers.type || (depth0 != null ? depth0.type : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"type","hash":{},"data":data}) : helper))) + "\n"; - stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "toggle", {"name":"equal","hash":{},"fn":this.program(6, data),"inverse":this.program(8, data),"data":data})); + stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "toggle", {"name":"equal","hash":{},"fn":this.program(6, data),"inverse":this.program(9, data),"data":data})); if (stack1 != null) { buffer += stack1; } return buffer + " \n\n"; },"2":function(depth0,helpers,partials,data) { @@ -95,12 +95,19 @@ templates['msg'] = template({"1":function(depth0,helpers,partials,data) { + escapeExpression(((helper = (helper = helpers.from || (depth0 != null ? depth0.from : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"from","hash":{},"data":data}) : helper))) + "\n"; },"6":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return "
\n \n
\n"; -},"8":function(depth0,helpers,partials,data) { - var stack1, helperMissing=helpers.helperMissing, buffer = " "; + + "\" class=\"toggle-button\">···\n \n"; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.toggle : depth0), {"name":"if","hash":{},"fn":this.program(7, data),"inverse":this.noop,"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"7":function(depth0,helpers,partials,data) { + var helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " " + + escapeExpression(((helpers.partial || (depth0 && depth0.partial) || helperMissing).call(depth0, "toggle", {"name":"partial","hash":{},"data":data}))) + + "\n"; +},"9":function(depth0,helpers,partials,data) { + var stack1, helperMissing=helpers.helperMissing, buffer = " "; stack1 = ((helpers.parse || (depth0 && depth0.parse) || helperMissing).call(depth0, (depth0 != null ? depth0.text : depth0), {"name":"parse","hash":{},"data":data})); if (stack1 != null) { buffer += stack1; } return buffer + "\n"; @@ -128,13 +135,18 @@ templates['network'] = template({"1":function(depth0,helpers,partials,data) { return buffer; },"useData":true}); templates['toggle'] = template({"1":function(depth0,helpers,partials,data) { + var stack1, helperMissing=helpers.helperMissing, buffer = "
\n"; + stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "image", {"name":"equal","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data})); + if (stack1 != null) { buffer += stack1; } + return buffer + "
\n\n"; +},"2":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; return " \n \n \n"; -},"3":function(depth0,helpers,partials,data) { +},"4":function(depth0,helpers,partials,data) { var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = " \n
"; @@ -144,10 +156,11 @@ templates['toggle'] = template({"1":function(depth0,helpers,partials,data) { + escapeExpression(((helper = (helper = helpers.body || (depth0 != null ? depth0.body : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"body","hash":{},"data":data}) : helper))) + "\n
\n
\n"; },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, helperMissing=helpers.helperMissing, buffer = "
\n"; - stack1 = ((helpers.equal || (depth0 && depth0.equal) || helperMissing).call(depth0, (depth0 != null ? depth0.type : depth0), "image", {"name":"equal","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data})); + var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, blockHelperMissing=helpers.blockHelperMissing, buffer = ""; + stack1 = ((helper = (helper = helpers.toggle || (depth0 != null ? depth0.toggle : depth0)) != null ? helper : helperMissing),(options={"name":"toggle","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); + if (!helpers.toggle) { stack1 = blockHelperMissing.call(depth0, stack1, options); } if (stack1 != null) { buffer += stack1; } - return buffer + "
\n\n"; + return buffer; },"useData":true}); templates['user'] = template({"1":function(depth0,helpers,partials,data) { var stack1, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; diff --git a/client/templates/msg.tpl b/client/templates/msg.tpl index 1c87a510..c7f6418f 100644 --- a/client/templates/msg.tpl +++ b/client/templates/msg.tpl @@ -11,11 +11,14 @@ {{type}} {{#equal type "toggle"}} -
- -
+
+ +
+ {{#if toggle}} + {{partial "toggle"}} + {{/if}} {{else}} - {{{parse text}}} + {{{parse text}}} {{/equal}}
diff --git a/client/templates/toggle.tpl b/client/templates/toggle.tpl index e68eb501..bdcf2e55 100644 --- a/client/templates/toggle.tpl +++ b/client/templates/toggle.tpl @@ -1,3 +1,4 @@ +{{#toggle}}
{{#equal type "image"}} @@ -13,3 +14,4 @@ {{/equal}}
+{{/toggle}} diff --git a/package.json b/package.json index 046a585a..688fdd89 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "shout", "description": "The self-hosted web IRC client", - "version": "0.38.1", + "version": "0.38.2", "author": "Mattias Erming", "preferGlobal": true, "bin": { diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 2bf1b3be..282c128e 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -37,42 +37,41 @@ module.exports = function(irc, network) { _.each(links, function(url) { fetch(url, function(res) { - parse(msg.id, url, res, client); + parse(msg, url, res, client); }); }); }); }; -function parse(id, url, res, client) { - var type = ""; - var head = ""; - var body = ""; - var link = url; +function parse(msg, url, res, client) { + var toggle = msg.toggle = { + id: msg.id, + type: "", + head: "", + body: "", + link: url + }; + switch (res.type) { case "text/html": var $ = cheerio.load(res.res.text); - type = "link"; - head = $("title").text(); - body = "No description found."; + toggle.type = "link"; + toggle.head = $("title").text(); + toggle.body = "No description found."; break; case "image/png": case "image/gif": case "image/jpg": case "image/jpeg": - type = "image"; + toggle.type = "image"; break; default: return; } - client.emit("toggle", { - id: id, - type: type, - head: head, - body: body, - link: link, - }); + + client.emit("toggle", toggle); } function fetch(url, cb) {