Skip to content

Commit 2515a7b

Browse files
committed
encode and decode URL parameters
1 parent baac7b6 commit 2515a7b

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/embed/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136

137137
for (var i = 0; i < param_str.length; i++) {
138138
var uv = param_str[i].split('=');
139-
url_vars[uv[0]] = uv[1];
139+
url_vars[uv[0]] = decodeURIComponent(uv[1]);
140140
}
141141

142142
return url_vars;

website/static/js/main.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,40 +94,45 @@ function getLinkAndIframe() {
9494
urlBase = "https://cdn.knightlab.com/libs/timeline3/latest/";
9595
}
9696

97-
vars = urlBase + "embed/index.html?source=" + source_key;
98-
99-
vars += "&font=" + e_font.getAttribute("data-value");
100-
vars += "&lang=" + e_language.value;
97+
let params = {
98+
source: source_key,
99+
font: e_font.getAttribute("data-value"),
100+
lang: e_language ? e_language.value : "en"
101+
}
101102

102103
if (start_at_end) {
103-
vars += "&start_at_end=" + start_at_end;
104+
params.start_at_end = start_at_end;
104105
}
105106

106107
if (timenav_position == "top") {
107-
vars += "&timenav_position=" + timenav_position;
108+
params.timenav_position = timenav_position;
108109
}
109110
if (is_debug) {
110-
vars += "&debug=" + is_debug;
111+
params.debug = is_debug;
111112
}
112113
if (hash_bookmark) {
113-
vars += "&hash_bookmark=" + hash_bookmark;
114+
params.hash_bookmark = hash_bookmark;
114115
}
115116
if (initial_zoom) {
116-
vars += "&initial_zoom=" + initial_zoom.value;
117+
params.initial_zoom = initial_zoom.value;
117118
}
118119
// TODO: Make this start at end if startatslide > # of slides
119120
if (parseInt(e_startatslide.value, 10) > 0) {
120-
vars += "&start_at_slide=" + parseInt(e_startatslide.value, 10);
121+
params.start_at_slide = parseInt(e_startatslide.value, 10);
121122
}
122123

123124
if (e_width.value > 0) {
124-
vars += "&width=" + e_width.value;
125+
params.width = e_width.value;
125126
}
126127
if (e_height.value > 0) {
127-
vars += "&height=" + e_height.value;
128+
params.height = e_height.value;
128129
}
129130

130-
iframe = "<iframe src='" + vars + "'";
131+
let source_url = urlBase + "embed/index.html";
132+
source_url += "?" + Object.keys(params).map(function(key) {
133+
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
134+
}).join('&');
135+
iframe = "<iframe src='" + source_url + "'";
131136

132137
if (e_width.value > 0 || e_width.value.match("%")) {
133138
iframe += " width='" + e_width.value + "'";

0 commit comments

Comments
 (0)