From c06c11aeca22d8303e0744213dad1090aa7b027c Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 6 Nov 2013 17:39:14 +0100 Subject: [PATCH 1/2] api.js parses custom data attributes for client configuration, part of #29 All data-attributes beginning with `data-isso-` are stored in `api.config` (without leading data-isso-). Isso tries to parse the values with JSON (e.g. `-isso-foo="false"` returns false) and falls back for a simple string value. --- isso/js/app/api.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 157d36f..2328929 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -6,6 +6,7 @@ define(["q"], function(Q) { Q.longStackSupport = true; var salt = "Eech7co8Ohloopo9Ol6baimi", + config = {}, location = window.location.pathname; var rules = { @@ -45,6 +46,16 @@ define(["q"], function(Q) { } else if (js[i].src.match("require\\.js$")) { endpoint = js[i].dataset.main.replace(/\/js\/(embed|count)$/, ""); } + + [].forEach.call(js[i].attributes, function(attr) { + if (/^data-isso-/.test(attr.name)) { + try { + config[attr.name.substring(10)] = JSON.parse(attr.value); + } catch (ex) { + config[attr.name.substring(10)] = attr.value; + } + } + }); } if (! endpoint) { @@ -181,6 +192,7 @@ define(["q"], function(Q) { return { endpoint: endpoint, salt: salt, + config: config, remote_addr: remote_addr, From 6f3a2d8072fc44114a2d487f6931d5640dce63a6 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Wed, 6 Nov 2013 17:46:04 +0100 Subject: [PATCH 2/2] add an option to prevent Isso from appending the default CSS, closes #29 --- README.md | 9 +++++++++ isso/js/app/api.js | 4 +++- isso/js/embed.js | 11 +++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2b09369..a350060 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,15 @@ You can configure the client (the JS part) via `data-` attributes: ``` +* data-isso-css + + Set to `false` prevents Isso from automatically appending the stylesheet. + Defaults to `true`. + + ```html + + ``` + ### Webserver configuration * nginx configuration to run Isso on `/isso`: diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 2328929..80be93d 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -6,7 +6,9 @@ define(["q"], function(Q) { Q.longStackSupport = true; var salt = "Eech7co8Ohloopo9Ol6baimi", - config = {}, + config = { + "css": true + }, location = window.location.pathname; var rules = { diff --git a/isso/js/embed.js b/isso/js/embed.js index fde0140..89d9855 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -8,10 +8,13 @@ require(["ready", "app/api", "app/isso", "app/count", "app/dom", "app/markup", " "use strict"; domready(function() { - var style = $.new("style"); - style.type = "text/css"; - style.textContent = css.inline; - $("head").append(style); + + if (api.config["css"]) { + var style = $.new("style"); + style.type = "text/css"; + style.textContent = css.inline; + $("head").append(style); + } count();