From 4f98bca20267b6f70db26c1c78a6fc3dde5557fe Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 21 May 2014 20:38:29 +0200 Subject: [PATCH] hide avatars with data-isso-avatar="false", part of #49 --- docs/docs/configuration/client.rst | 6 +++ isso/js/app/config.js | 1 + isso/js/app/isso.js | 60 ++++++++++++++++-------------- isso/js/app/markup.js | 3 +- isso/js/app/text/comment.html | 4 +- isso/js/app/text/postbox.html | 2 + 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/docs/docs/configuration/client.rst b/docs/docs/configuration/client.rst index fec0c36..fcbac1c 100644 --- a/docs/docs/configuration/client.rst +++ b/docs/docs/configuration/client.rst @@ -13,6 +13,7 @@ preferably in the script tag which embeds the JS: data-isso-max-comments-top="10" data-isso-max-comments-nested="5" data-isso-reveal-on-click="5" + data-isso-avatar="true" data-avatar-bg="#f0f0f0" data-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..." src="/prefix/js/embed.js"> @@ -69,6 +70,11 @@ data-isso-reveal-on-click Number of comments to reveal on clicking the "X Hidden" link. +data-isso-avatar +---------------- + +Enable or disable avatar generation. + data-isso-avatar-bg ------------------- diff --git a/isso/js/app/config.js b/isso/js/app/config.js index aa092ed..94f36dd 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -8,6 +8,7 @@ define(function() { "max-comments-top": 10, "max-comments-nested": 5, "reveal-on-click": 5, + "avatar": true, "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index da78ea0..69e8f8d 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -11,35 +11,37 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m var el = $.htmlify(Mark.up(templates["postbox"])); - // add a default identicon to not waste CPU cycles - $(".avatar > svg", el).replace(lib.identicons.blank(4, 48)); - - // on text area focus, generate identicon from IP address - $(".textarea-wrapper > .textarea", el).on("focus", function() { - if ($(".avatar svg", el).getAttribute("className") === "blank") { - $(".avatar svg", el).replace( - lib.identicons.generate(lib.pbkdf2(api.remote_addr(), api.salt, 1000, 6), 4, 48)); - } - }); + if (config["avatar"]) { + // add a default identicon to not waste CPU cycles + $(".avatar > svg", el).replace(lib.identicons.blank(4, 48)); + + // on text area focus, generate identicon from IP address + $(".textarea-wrapper > .textarea", el).on("focus", function() { + if ($(".avatar svg", el).getAttribute("className") === "blank") { + $(".avatar svg", el).replace( + lib.identicons.generate(lib.pbkdf2(api.remote_addr(), api.salt, 1000, 6), 4, 48)); + } + }); - // update identicon on email input. Listens on keyup, after 200ms the - // new identicon is generated. - var active; - $(".input-wrapper > [type=email]", el).on("keyup", function() { - if (active) { - clearTimeout(active); - } - active = setTimeout(function() { - lib.pbkdf2($(".input-wrapper > [type=email]", el).value || api.remote_addr(), api.salt, 1000, 6) - .then(function(rv) { - $(".avatar svg", el).replace(lib.identicons.generate(rv, 4, 48)); - }); - }, 200); - }, false); + // update identicon on email input. Listens on keyup, after 200ms the + // new identicon is generated. + var active; + $(".input-wrapper > [type=email]", el).on("keyup", function() { + if (active) { + clearTimeout(active); + } + active = setTimeout(function() { + lib.pbkdf2($(".input-wrapper > [type=email]", el).value || api.remote_addr(), api.salt, 1000, 6) + .then(function(rv) { + $(".avatar svg", el).replace(lib.identicons.generate(rv, 4, 48)); + }); + }, 200); + }, false); - $(".input-wrapper > [type=email]", el).on("keydown", function() { - clearTimeout(active); - }, false); + $(".input-wrapper > [type=email]", el).on("keydown", function() { + clearTimeout(active); + }, false); + } // callback on success (e.g. to toggle the reply button) el.onsuccess = function() {}; @@ -144,7 +146,9 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m // run once to activate refresh(); - $("div.avatar > svg", el).replace(lib.identicons.generate(comment.hash, 4, 48)); + if (config["avatar"]) { + $("div.avatar > svg", el).replace(lib.identicons.generate(comment.hash, 4, 48)); + } var entrypoint; if (comment.parent === null) { diff --git a/isso/js/app/markup.js b/isso/js/app/markup.js index 89db8c4..37890d3 100644 --- a/isso/js/app/markup.js +++ b/isso/js/app/markup.js @@ -1,4 +1,4 @@ -define(["vendor/markup", "app/i18n", "app/text/svg"], function(Mark, i18n, svg) { +define(["vendor/markup", "app/config", "app/i18n", "app/text/svg"], function(Mark, config, i18n, svg) { "use strict"; @@ -21,6 +21,7 @@ define(["vendor/markup", "app/i18n", "app/text/svg"], function(Mark, i18n, svg) Mark.delimiter = ":"; Mark.includes = merge({ + conf: config, i18n: i18n[i18n.lang], svg: svg }); diff --git a/isso/js/app/text/comment.html b/isso/js/app/text/comment.html index e9cc1e1..18623c9 100644 --- a/isso/js/app/text/comment.html +++ b/isso/js/app/text/comment.html @@ -1,10 +1,12 @@
+ {{ if conf-avatar | bool }}
+ {{ /if }}
- {{ if bool(website) }} + {{ if website | bool }} {{ author | blank : `i18n-comment-anonymous` }} diff --git a/isso/js/app/text/postbox.html b/isso/js/app/text/postbox.html index 229a879..d1bc5e7 100644 --- a/isso/js/app/text/postbox.html +++ b/isso/js/app/text/postbox.html @@ -1,7 +1,9 @@
+ {{ if conf-avatar | bool }}
+ {{ /if }}
{{ i18n-postbox-text }}