lib/assets/javascripts/scrivito_sdk.js in scrivito_sdk-0.40.0.rc1 vs lib/assets/javascripts/scrivito_sdk.js in scrivito_sdk-0.40.0.rc2
- old
+ new
@@ -1,31 +1,47 @@
(function() {
if (window.parent !== window) {
var scrivito_ui = window.parent.scrivito;
if (scrivito_ui) {
+ // In an iframe and parent window contains the UI: in UI mode.
var cms_document = scrivito_ui.cms_element.from_dom_element($(document));
cms_document.install_public_api();
+
$(function() {
- if (!scrivito_ui.is_inited()) {
- var config = scrivito_ui.dom_config.read($('body'));
- if (!config) {
- $.error('Scrivito config missing. Did you forget to include scrivito_body_tags in layout?');
+ var dom_config = scrivito_ui.dom_config.read($('body'));
+ if (scrivito_ui.is_inited()) {
+ if (!dom_config) {
+ // UI is already running, but editing is not allowed: reload UI to make it disappear.
+ window.parent.location.reload();
}
- scrivito_ui.init(config);
+ } else {
+ if (!dom_config) {
+ // UI is not yet running and config is missing.
+ $.error('Missing Scrivito config. Did you forget to include scrivito_body_tags in layout?');
+ }
+ scrivito_ui.init(dom_config);
scrivito_ui.gui.start();
+ if (window.parent.location.hash.length) {
+ location.hash = window.parent.location.hash;
+ }
}
cms_document.connect();
});
}
} else {
$(function() {
- if ($('*[data-scrivito-private-config]').length) {
+ // Not in UI mode, but editing is allowed: redirect to the UI mode.
+ if ($('[data-scrivito-private-config]').length) {
console.log('Scrivito config found: redirecting to the UI...');
- window.location = '/scrivito'+window.location.pathname;
+ window.location = '/scrivito' +
+ window.location.pathname +
+ window.location.search +
+ window.location.hash;
}
});
}
+ // If the SDK is completely missing, the custom callbacks should nevertheless run.
if (!window.scrivito) {
window.scrivito = {
on: function(event_name, callback) {
if (event_name === 'content') {
$(function() {