Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using .innerHTML makes JSON reappear (closes #478) #490

Merged
merged 2 commits into from
Sep 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions js/core/base-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
, embedded = (top !== self)
;
if (!("respecConfig" in window)) window.respecConfig = {};
// clone the initial user configuration.
try{
if(Object.assign){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the convention us but iirc ReSpec has ws all over the place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to fix all that in #493.

respecConfig.initialUserConfig = Object.assign({}, respecConfig);
} else {
respecConfig.initialUserConfig = JSON.parse(JSON.stringify(respecConfig));
}
}catch(err){
respecConfig.initialUserConfig = {};
}
GLOBAL.respecEvents = {
pub: function (topic) {
var args = Array.prototype.slice.call(arguments);
Expand Down
4 changes: 2 additions & 2 deletions js/core/include-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(
run: function(conf, doc, cb, msg) {
msg.pub("start", "core/include-config");
var script = doc.createElement("script");
script.id = "respecFinalConfig";
script.id = "initialUserConfig";
var confFilter = function(key, val) {
// DefinitionMap contains array of DOM elements that aren't serializable
// we replace them by their id
Expand All @@ -21,7 +21,7 @@ define(
}
return val;
}
script.innerText = JSON.stringify(conf, confFilter, 2);
script.innerHTML = JSON.stringify(conf.initialUserConfig, confFilter, 2);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, innerText doesn't work... it doesn't output when respec calls .innerHTML on the root node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this wouldn't work, but frontend dev is full of mysteries.

script.type = "application/json";
doc.head.appendChild(script);
msg.pub("end", "core/include-config");
Expand Down
24 changes: 12 additions & 12 deletions tests/spec/core/include-config-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
describe("Core — Include config as JSON", function() {
var MAXOUT = 5000,
basicConfig = {
editors: [{
name: "Robin Berjon"
}],
specStatus: "WD"
};
var MAXOUT = 5000;
var basicConfig = {
editors: [{
name: "Robin Berjon"
}],
specStatus: "WD"
};
it("should have a script tag with the correct attributes", function() {
var doc;
runs(function() {
Expand All @@ -21,9 +21,9 @@ describe("Core — Include config as JSON", function() {
return doc;
}, MAXOUT);
runs(function() {
var $script = $("#respecConfig", doc);
var $script = $("#initialUserConfig", doc);
expect($script[0].tagName).toEqual("SCRIPT");
expect($script.attr("id")).toEqual("respecFinalConfig");
expect($script.attr("id")).toEqual("initialUserConfig");
expect($script.attr("type")).toEqual("application/json");
flushIframes();
});
Expand All @@ -43,9 +43,9 @@ describe("Core — Include config as JSON", function() {
return doc;
}, MAXOUT);
runs(function() {
var $script = $("#respecConfig", doc);
var jsonConfig = JSON.stringify(doc.defaultView.respecConfig, null, 2);
expect($script.text()).toEqual(jsonConfig);
var $script = $("#initialUserConfig", doc);
var jsonConfig = JSON.stringify(doc.defaultView.respecConfig.initialUserConfig, null, 2);
expect($script[0].innerHTML).toEqual(jsonConfig);
flushIframes();
});
});
Expand Down