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.
This commit is contained in:
parent
4bb6e91f61
commit
c06c11aeca
@ -6,6 +6,7 @@ define(["q"], function(Q) {
|
|||||||
Q.longStackSupport = true;
|
Q.longStackSupport = true;
|
||||||
|
|
||||||
var salt = "Eech7co8Ohloopo9Ol6baimi",
|
var salt = "Eech7co8Ohloopo9Ol6baimi",
|
||||||
|
config = {},
|
||||||
location = window.location.pathname;
|
location = window.location.pathname;
|
||||||
|
|
||||||
var rules = {
|
var rules = {
|
||||||
@ -45,6 +46,16 @@ define(["q"], function(Q) {
|
|||||||
} else if (js[i].src.match("require\\.js$")) {
|
} else if (js[i].src.match("require\\.js$")) {
|
||||||
endpoint = js[i].dataset.main.replace(/\/js\/(embed|count)$/, "");
|
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) {
|
if (! endpoint) {
|
||||||
@ -181,6 +192,7 @@ define(["q"], function(Q) {
|
|||||||
return {
|
return {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
salt: salt,
|
salt: salt,
|
||||||
|
config: config,
|
||||||
|
|
||||||
remote_addr: remote_addr,
|
remote_addr: remote_addr,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user