lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.18.0 vs lib/assets/javascripts/scrivito_editing.js in scrivito_sdk-0.18.1
- old
+ new
@@ -14429,10 +14429,33 @@
// See http://underscorejs.org/#throttle
throttle: function(fn, ms) {
return scrivito.bypass_throttle ? fn : _.throttle(fn, ms);
},
+ // window.atob does not handle encoded UTF8 strings. See http://mzl.la/1p1zI9k.
+ base64_to_utf8: function(base64_string) {
+ return decodeURIComponent(window.escape(atob(base64_string)));
+ },
+
+ // window.btoa does not handle encoded UTF8 strings. See http://mzl.la/1p1zI9k.
+ utf8_to_base64: function(utf8_string) {
+ return btoa(window.unescape(encodeURIComponent(utf8_string)));
+ },
+
+ json_parse_base64: function(base64_string) {
+ var utf8_string = scrivito.base64_to_utf8(base64_string);
+ // The server escapes non-unicode characters (e.g. '<') when encoding JSON.
+ utf8_string = utf8_string.replace(/\\u([\d\w]{4})/gi, function(match, grp) {
+ return String.fromCharCode(parseInt(grp, 16));
+ });
+ return JSON.parse(utf8_string);
+ },
+
+ json_stringify_base64: function(object) {
+ return scrivito.utf8_to_base64(JSON.stringify(object));
+ },
+
init: function(config) {
scrivito.config = config;
scrivito.editing_context.init(config.editing_context);
scrivito.i18n.init(config.i18n);
@@ -15819,22 +15842,20 @@
original_content: function() {
assert_valid_workspace_id();
if (has_original_content(that.field_type())) {
- var encoded_content = that.dom_element()
- .attr('data-scrivito-private-field-original-content');
- return JSON.parse(atob(encoded_content));
+ return scrivito.json_parse_base64(
+ that.dom_element().attr('data-scrivito-private-field-original-content'));
} else {
$.error('Fields of type ' + that.field_type() + ' do not support original content');
}
},
set_original_content: function(content) {
if (has_original_content(that.field_type())) {
- var encoded_content = btoa(JSON.stringify(content));
- that.dom_element()
- .attr('data-scrivito-private-field-original-content', encoded_content);
+ that.dom_element().attr('data-scrivito-private-field-original-content',
+ scrivito.json_stringify_base64(content));
}
}
});
var assert_valid_workspace_id = function() {