Skip to content

Commit

Permalink
isso: js: embed.js: Preserve default config values
Browse files Browse the repository at this point in the history
This way, Isso is not confusing users when a server config
value overwrites a client default one, i.e. if the user
has not actually attempted to overwrite it.
  • Loading branch information
ix5 committed Mar 20, 2022
1 parent f947eae commit 16d7766
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
28 changes: 7 additions & 21 deletions isso/js/app/config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
const utils = require("app/utils");
const default_config = require("app/default_config");

"use strict";

var config = {
"css": true,
"css-url": null,
"lang": "",
"default-lang": "en",
"reply-to-self": false,
"require-email": false,
"require-author": false,
"reply-notifications": false,
"max-comments-top": "inf",
"max-comments-nested": 5,
"reveal-on-click": 5,
"gravatar": false,
"avatar": true,
"avatar-bg": "#f0f0f0",
"avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6",
"#be5168", "#f19670", "#e4bf80", "#447c69"].join(" "),
"vote": true,
"vote-levels": null,
"feed": false
};
// Preserve default values to filter out when comparing
// with values fetched from server
var config = {};
for (let key in default_config) {
config[key] = default_config[key];
}

var js = document.getElementsByTagName("script");

Expand Down
20 changes: 20 additions & 0 deletions isso/js/app/default_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

var default_config = {
"css": true,
"css-url": null,
"lang": "",
"default-lang": "en",
"max-comments-top": "inf",
"max-comments-nested": 5,
"reveal-on-click": 5,
"avatar": true,
"avatar-bg": "#f0f0f0",
"avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6",
"#be5168", "#f19670", "#e4bf80", "#447c69"].join(" "),
"vote": true,
"vote-levels": null,
"feed": false
};

module.exports = default_config;
7 changes: 5 additions & 2 deletions isso/js/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

const domready = require("app/lib/ready");
const config = require("app/config");
const default_config = require("app/default_config");
const i18n = require("app/i18n");
const api = require("app/api");
const isso = require("app/isso");
Expand Down Expand Up @@ -67,8 +68,10 @@ function fetchComments() {
config["max-comments-top"],
config["max-comments-nested"]).then(
function (rv) {
for (var setting in rv.config) {
if (setting in config && config[setting] != rv.config[setting]) {
for (let setting in rv.config) {
if (setting in config
&& config[setting] != default_config[setting]
&& config[setting] != rv.config[setting]) {
console.log("Isso: Client value '%s' for setting '%s' overridden by server value '%s'.\n" +
"Since Isso version 0.12.6, 'data-isso-%s' is only configured via the server " +
"to keep client and server in sync",
Expand Down

0 comments on commit 16d7766

Please sign in to comment.