hide avatars with data-isso-avatar="false", part of #49

pull/92/head
Martin Zimmermann 10 years ago
parent 29b4643c5e
commit 4f98bca202

@ -13,6 +13,7 @@ preferably in the script tag which embeds the JS:
data-isso-max-comments-top="10" data-isso-max-comments-top="10"
data-isso-max-comments-nested="5" data-isso-max-comments-nested="5"
data-isso-reveal-on-click="5" data-isso-reveal-on-click="5"
data-isso-avatar="true"
data-avatar-bg="#f0f0f0" data-avatar-bg="#f0f0f0"
data-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..." data-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..."
src="/prefix/js/embed.js"></script> src="/prefix/js/embed.js"></script>
@ -69,6 +70,11 @@ data-isso-reveal-on-click
Number of comments to reveal on clicking the "X Hidden" link. Number of comments to reveal on clicking the "X Hidden" link.
data-isso-avatar
----------------
Enable or disable avatar generation.
data-isso-avatar-bg data-isso-avatar-bg
------------------- -------------------

@ -8,6 +8,7 @@ define(function() {
"max-comments-top": 10, "max-comments-top": 10,
"max-comments-nested": 5, "max-comments-nested": 5,
"reveal-on-click": 5, "reveal-on-click": 5,
"avatar": true,
"avatar-bg": "#f0f0f0", "avatar-bg": "#f0f0f0",
"avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6",
"#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ")

@ -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"])); var el = $.htmlify(Mark.up(templates["postbox"]));
// add a default identicon to not waste CPU cycles if (config["avatar"]) {
$(".avatar > svg", el).replace(lib.identicons.blank(4, 48)); // 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() { // on text area focus, generate identicon from IP address
if ($(".avatar svg", el).getAttribute("className") === "blank") { $(".textarea-wrapper > .textarea", el).on("focus", function() {
$(".avatar svg", el).replace( if ($(".avatar svg", el).getAttribute("className") === "blank") {
lib.identicons.generate(lib.pbkdf2(api.remote_addr(), api.salt, 1000, 6), 4, 48)); $(".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 // update identicon on email input. Listens on keyup, after 200ms the
// new identicon is generated. // new identicon is generated.
var active; var active;
$(".input-wrapper > [type=email]", el).on("keyup", function() { $(".input-wrapper > [type=email]", el).on("keyup", function() {
if (active) { if (active) {
clearTimeout(active); clearTimeout(active);
} }
active = setTimeout(function() { active = setTimeout(function() {
lib.pbkdf2($(".input-wrapper > [type=email]", el).value || api.remote_addr(), api.salt, 1000, 6) lib.pbkdf2($(".input-wrapper > [type=email]", el).value || api.remote_addr(), api.salt, 1000, 6)
.then(function(rv) { .then(function(rv) {
$(".avatar svg", el).replace(lib.identicons.generate(rv, 4, 48)); $(".avatar svg", el).replace(lib.identicons.generate(rv, 4, 48));
}); });
}, 200); }, 200);
}, false); }, false);
$(".input-wrapper > [type=email]", el).on("keydown", function() { $(".input-wrapper > [type=email]", el).on("keydown", function() {
clearTimeout(active); clearTimeout(active);
}, false); }, false);
}
// callback on success (e.g. to toggle the reply button) // callback on success (e.g. to toggle the reply button)
el.onsuccess = function() {}; 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 // run once to activate
refresh(); 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; var entrypoint;
if (comment.parent === null) { if (comment.parent === null) {

@ -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"; "use strict";
@ -21,6 +21,7 @@ define(["vendor/markup", "app/i18n", "app/text/svg"], function(Mark, i18n, svg)
Mark.delimiter = ":"; Mark.delimiter = ":";
Mark.includes = merge({ Mark.includes = merge({
conf: config,
i18n: i18n[i18n.lang], i18n: i18n[i18n.lang],
svg: svg svg: svg
}); });

@ -1,10 +1,12 @@
<div class="isso-comment" id="isso-{{ id | blank }}"> <div class="isso-comment" id="isso-{{ id | blank }}">
{{ if conf-avatar | bool }}
<div class="avatar"> <div class="avatar">
<svg data-hash="{{ hash }}"></svg> <svg data-hash="{{ hash }}"></svg>
</div> </div>
{{ /if }}
<div class="text-wrapper"> <div class="text-wrapper">
<div class="isso-comment-header" role="meta"> <div class="isso-comment-header" role="meta">
{{ if bool(website) }} {{ if website | bool }}
<a class="author" href="{{ website }}" rel="nofollow"> <a class="author" href="{{ website }}" rel="nofollow">
{{ author | blank : `i18n-comment-anonymous` }} {{ author | blank : `i18n-comment-anonymous` }}
</a> </a>

@ -1,7 +1,9 @@
<div class="postbox"> <div class="postbox">
{{ if conf-avatar | bool }}
<div class="avatar"> <div class="avatar">
<svg class="blank" data-hash="{{ hash }}"></svg> <svg class="blank" data-hash="{{ hash }}"></svg>
</div> </div>
{{ /if }}
<div class="form-wrapper"> <div class="form-wrapper">
<div class="textarea-wrapper"> <div class="textarea-wrapper">
<div class="textarea placeholder" contenteditable="true">{{ i18n-postbox-text }}</div> <div class="textarea placeholder" contenteditable="true">{{ i18n-postbox-text }}</div>

Loading…
Cancel
Save