diff --git a/static-assets/components/cstudio-contextual-nav/ice_tools.js b/static-assets/components/cstudio-contextual-nav/ice_tools.js
deleted file mode 100644
index 38e6177834..0000000000
--- a/static-assets/components/cstudio-contextual-nav/ice_tools.js
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/**
- * WCM Search Plugin
- */
-CStudioAuthoring.ContextualNav.IceToolsMod = CStudioAuthoring.ContextualNav.IceToolsMod || {
- initialized: false,
-
- /**
- * initialize module
- */
- initialize: function (config) {
- this.definePlugin();
- CStudioAuthoring.ContextualNav.EditorsToolsNav.init();
- },
-
- definePlugin: function () {
- var YDom = YAHOO.util.Dom,
- YEvent = YAHOO.util.Event;
- /**
- * WCM editor tools Contextual Nav Widget
- */
- CStudioAuthoring.register({
- 'ContextualNav.EditorsToolsNav': {
- init: function () {
- var _self = this;
- var callback = function (isRev) {
- if (CStudioAuthoringContext.isPreview == true && !isRev) {
- _self.render();
- if (CStudioAuthoring.IceTools) {
- //CStudioAuthoring.IceTools) {
- CStudioAuthoring.IceTools.IceToolsOffEvent.subscribe(function () {
- var el = YDom.get('acn-ice-tools-container');
- YDom.removeClass(el.children[0], 'icon-yellow');
- YDom.addClass(el.children[0], 'icon-default');
- });
-
- CStudioAuthoring.IceTools.IceToolsOnEvent.subscribe(function () {
- var el = YDom.get('acn-ice-tools-container');
- YDom.removeClass(el.children[0], 'icon-default');
- YDom.addClass(el.children[0], 'icon-yellow');
- });
-
- // }
- // else {
- cb = {
- moduleLoaded: function (moduleName, moduleClass, moduleConfig) {
- try {
- CStudioAuthoring.IceTools.initialize(moduleConfig);
- if (this.self.initialized == false) {
- this.self.render();
- }
-
- this.self.initialized = true;
-
- CStudioAuthoring.IceTools.IceToolsOffEvent.subscribe(function () {
- var el = YDom.get('acn-ice-tools-container');
- YDom.removeClass(el.children[0], 'icon-yellow');
- YDom.addClass(el.children[0], 'icon-default');
- });
-
- CStudioAuthoring.IceTools.IceToolsOnEvent.subscribe(function () {
- var el = YDom.get('acn-ice-tools-container');
- YDom.removeClass(el.children[0], 'icon-default');
- YDom.addClass(el.children[0], 'icon-yellow');
- });
-
- CStudioAuthoring.Module.requireModule(
- 'preview-tools-controller',
- '/static-assets/components/cstudio-preview-tools/preview-tools.js',
- 0,
- {
- moduleLoaded: function (moduleName, moduleClass, moduleConfig) {
- CStudioAuthoring.PreviewTools.PreviewToolsOffEvent.subscribe(function () {
- CStudioAuthoring.IceTools.turnEditOff();
- });
- }
- }
- );
- } catch (e) {}
- },
-
- self: this
- };
-
- CStudioAuthoring.Module.requireModule(
- 'ice-tools-controller',
- '/static-assets/components/cstudio-preview-tools/ice-tools.js',
- 0,
- cb
- );
- }
- }
- };
- CStudioAuthoring.Utils.isReviewer(callback);
- },
-
- render: function () {
- var el, containerEl, pencilIcon, iceOn;
-
- var CMgs = CStudioAuthoring.Messages;
- var previewLangBundle = CMgs.getBundle('forms', CStudioAuthoringContext.lang);
-
- el = YDom.get('acn-ice-tools');
- containerEl = document.createElement('div');
- containerEl.id = 'acn-ice-tools-container';
- YDom.addClass(containerEl, 'nav-link nav-container');
-
- pencilIcon = document.createElement('span');
- pencilIcon.id = 'acn-ice-tools-image';
-
- iceOn = !!sessionStorage.getItem('ice-on'); // cast string value to a boolean
-
- YDom.addClass(pencilIcon, 'nav-icon fa fa-pencil f18');
- $(pencilIcon).attr('data-title', 'inContextEdit');
-
- if (iceOn) {
- YDom.addClass(pencilIcon, 'icon-yellow');
- } else {
- YDom.addClass(pencilIcon, 'icon-default');
- }
-
- containerEl.appendChild(pencilIcon);
- el.appendChild(containerEl);
-
- el.onclick = function () {
- var iceOn = !!sessionStorage.getItem('ice-on'); // cast string value to a boolean
-
- if (!iceOn) {
- CStudioAuthoring.IceTools.turnEditOn();
- } else {
- CStudioAuthoring.IceTools.turnEditOff();
- }
- };
- }
- }
- });
- }
-};
-
-CStudioAuthoring.Module.moduleLoaded('ice_tools', CStudioAuthoring.ContextualNav.IceToolsMod);
diff --git a/static-assets/components/cstudio-contextual-nav/preview_tools.js b/static-assets/components/cstudio-contextual-nav/preview_tools.js
deleted file mode 100644
index 783c91be77..0000000000
--- a/static-assets/components/cstudio-contextual-nav/preview_tools.js
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-/**
- * Preview Tools
- */
-CStudioAuthoring.ContextualNav.PreviewToolsMod = CStudioAuthoring.ContextualNav.PreviewToolsMod || {
- initialized: false,
-
- /**
- * initialize module
- */
- initialize: function (config) {
- this.definePlugin();
- CStudioAuthoring.ContextualNav.PreviewToolsNav.init();
- },
-
- definePlugin: function () {
- var YDom = YAHOO.util.Dom,
- YEvent = YAHOO.util.Event;
- /**
- * WCM preview tools Contextual Nav Widget
- */
- CStudioAuthoring.register({
- 'ContextualNav.PreviewToolsNav': {
- init: function () {
- if (CStudioAuthoringContext.isPreview == true) {
- if (CStudioAuthoring.PreviewTools) {
- this.render();
- } else {
- cb = {
- moduleLoaded: function (moduleName, moduleClass, moduleConfig) {
- try {
- if (!this.initialized) {
- CStudioAuthoring.PreviewTools.PreviewToolsOffEvent.subscribe(function () {
- var el = YDom.get('acn-preview-tools-container');
- YDom.removeClass(el.children[0], 'icon-light-blue');
- YDom.addClass(el.children[0], 'icon-default');
- });
-
- CStudioAuthoring.PreviewTools.PreviewToolsOnEvent.subscribe(function () {
- var el = YDom.get('acn-preview-tools-container');
- YDom.removeClass(el.children[0], 'icon-default');
- YDom.addClass(el.children[0], 'icon-light-blue');
- });
-
- CStudioAuthoring.PreviewTools.initialize(moduleConfig);
- this.self.render();
- this.self.initialized = true;
- }
- } catch (e) {}
- },
-
- self: this
- };
-
- CStudioAuthoring.Module.requireModule(
- 'preview-tools-controller',
- '/static-assets/components/cstudio-preview-tools/preview-tools.js',
- 0,
- cb
- );
- }
- }
- },
-
- render: function () {
- var el, containerEl, iconEl, ptoOn;
-
- var CMgs = CStudioAuthoring.Messages;
- var previewLangBundle = CMgs.getBundle('forms', CStudioAuthoringContext.lang);
-
- el = YDom.get('acn-preview-tools');
- containerEl = document.createElement('div');
- containerEl.id = 'acn-preview-tools-container';
- YDom.addClass(containerEl, 'nav-link nav-container');
-
- iconEl = document.createElement('span');
- iconEl.id = 'acn-preview-tools-image';
-
- YDom.addClass(iconEl, 'nav-icon fa fa-wrench f18');
- $(iconEl).attr('data-title', 'previewToolsTitle');
- ptoOn = !!sessionStorage.getItem('pto-on'); // cast string value to a boolean
-
- if (ptoOn) {
- YDom.addClass(iconEl, 'icon-light-blue');
- } else {
- YDom.addClass(iconEl, 'icon-default');
- }
-
- containerEl.appendChild(iconEl);
- el.appendChild(containerEl);
-
- var cstopic = crafter.studio.preview.cstopic;
-
- el.onclick = function () {
- var ptoOn = !!sessionStorage.getItem('pto-on'),
- componentsOn = !!sessionStorage.getItem('components-on');
-
- if (!ptoOn) {
- if (componentsOn) {
- CStudioAuthoring.Service.lookupConfigurtion(
- CStudioAuthoringContext.site,
- '/preview-tools/components-config.xml',
- {
- failure: CStudioAuthoring.Utils.noop,
- success: function (config) {
- amplify.publish(cstopic('DND_COMPONENTS_PANEL_ON'), {
- components: config
- });
- }
- }
- );
- } else {
- CStudioAuthoring.PreviewTools.turnToolsOn();
- }
- } else {
- if (componentsOn) {
- amplify.publish(cstopic('DND_COMPONENTS_PANEL_OFF'));
- } else {
- CStudioAuthoring.PreviewTools.turnToolsOff();
- }
- }
- };
- }
- }
- });
- }
-};
-
-CStudioAuthoring.Module.moduleLoaded('preview_tools', CStudioAuthoring.ContextualNav.PreviewToolsMod);
diff --git a/static-assets/components/cstudio-preview-tools/ice-tools.js b/static-assets/components/cstudio-preview-tools/ice-tools.js
deleted file mode 100644
index 0348d7ab64..0000000000
--- a/static-assets/components/cstudio-preview-tools/ice-tools.js
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-CStudioAuthoring.Utils.addJavascript('/static-assets/modules/editors/tinymce/v2/tiny_mce/tiny_mce.js');
-CStudioAuthoring.Utils.addJavascript('/static-assets/components/cstudio-forms/forms-engine.js');
-/**
- * In-Context Editing (ICE)
- */
-CStudioAuthoring.IceTools = CStudioAuthoring.IceTools || {
- IceToolsOffEvent: new YAHOO.util.CustomEvent('cstudio-ice-tools-off', CStudioAuthoring),
- IceToolsOnEvent: new YAHOO.util.CustomEvent('cstudio-ice-tools-on', CStudioAuthoring),
-
- initialized: false,
-
- /**
- * initialize module
- */
- initialize: function (config) {
- var iceOn;
-
- if (this.initialized == false) {
- iceOn = !!sessionStorage.getItem('ice-on'); // cast string value to a boolean
-
- if (iceOn) {
- this.IceToolsOnEvent.fire();
- }
-
- this.initialized = true;
- }
- },
-
- turnEditOn: function () {
- /*if(!!(sessionStorage.getItem('pto-on') == false)) { // cast string value to a boolean
- CStudioAuthoring.PreviewTools.turnToolsOn();
- }*/
- sessionStorage.setItem('ice-on', 'on');
- this.IceToolsOnEvent.fire();
- },
-
- turnEditOff: function () {
- sessionStorage.setItem('ice-on', '');
- this.IceToolsOffEvent.fire();
- }
-};
-
-CStudioAuthoring.Module.moduleLoaded('ice-tools', CStudioAuthoring.IceTools);
-CStudioAuthoring.Module.moduleLoaded('ice-tools-controller', CStudioAuthoring.IceTools);
diff --git a/static-assets/components/cstudio-preview-tools/mods/ice-tools-panel.js b/static-assets/components/cstudio-preview-tools/mods/ice-tools-panel.js
deleted file mode 100644
index b2bbfddaa9..0000000000
--- a/static-assets/components/cstudio-preview-tools/mods/ice-tools-panel.js
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-CStudioAuthoring.Utils.addJavascript('/static-assets/modules/editors/tinymce/v2/tiny_mce/tiny_mce.js');
-CStudioAuthoring.Utils.addJavascript('/static-assets/components/cstudio-forms/forms-engine.js');
-
-var initRegCookie;
-/**
- * editor tools
- */
-CStudioAuthoring.IceToolsPanel = CStudioAuthoring.IceToolsPanel || {
- initialized: false,
-
- /**
- * initialize module
- */
- initialize: function (config) {
- if (this.initialized == false) {
- this.initialized = true;
- }
- },
-
- render: function (containerEl, config) {
- var container = document.createElement('div'),
- wrapper;
-
- containerEl.appendChild(container);
- container.className = 'studio-view';
-
- var buttonEl, pencilIcon, labelEl, iceOn;
-
- var callback = function (isRev) {
- if (!isRev) {
- wrapper = document.createElement('div');
- buttonEl = document.createElement('button');
- pencilIcon = document.createElement('span');
- labelEl = document.createElement('span');
- YDom.addClass(wrapper, 'form-group ice-toogle');
- YDom.addClass(buttonEl, 'btn btn-default btn-block');
- YDom.addClass(labelEl, 'acn-ptools-ice-label');
-
- iceOn = !!sessionStorage.getItem('ice-on'); // cast string value to a boolean
-
- YDom.addClass(pencilIcon, 'fa fa-pencil f18');
-
- if (iceOn) {
- YDom.addClass(pencilIcon, 'icon-yellow');
- labelEl.innerHTML = CMgs.format(previewLangBundle, 'inContextEditOff');
- } else {
- YDom.addClass(pencilIcon, 'icon-default');
- labelEl.innerHTML = CMgs.format(previewLangBundle, 'inContextEditOn');
- }
-
- buttonEl.appendChild(pencilIcon);
- buttonEl.appendChild(labelEl);
- wrapper.appendChild(buttonEl);
- container.appendChild(wrapper);
-
- buttonEl.onclick = function () {
- var iceOn = !!sessionStorage.getItem('ice-on'); // cast string value to a boolean
- if (!iceOn) {
- CStudioAuthoring.IceTools.turnEditOn();
- } else {
- CStudioAuthoring.IceTools.turnEditOff();
- }
- };
-
- wrapper = document.createElement('div');
- var regionSelectEl = document.createElement('select');
-
- YDom.addClass(wrapper, 'form-group');
- YDom.addClass(regionSelectEl, 'form-control');
-
- wrapper.appendChild(regionSelectEl);
- container.appendChild(wrapper);
-
- initRegCookie = function () {
- try {
- var regions = JSON.parse(sessionStorage.getItem('ice-tools-content')) || [];
-
- for (i = 0; i < regionSelectEl.length; i++) {
- regionSelectEl.options[i] = null;
- }
-
- if (regions.length > 0) {
- regionSelectEl.options[0] = new Option(CMgs.format(previewLangBundle, 'jumpToRegion'), '0', true, false);
- for (var i = 0; i < regions.length; i++) {
- var label = regions[i].label ? regions[i].label.replace(/__/g, ' ') : regions[i].id.replace(/__/g, ' ');
- regionSelectEl.options[i + 1] = new Option(label, '' + (i + 1), false, false);
- }
-
- regionSelectEl.onchange = function () {
- var selectedIndex = this.selectedIndex;
- if (selectedIndex != 0) {
- var region = regions[selectedIndex - 1];
- if (region.label) {
- amplify.publish(cstopic('ICE_TOOLS_REGIONS'), {
- label: '-label',
- region: region.label
- });
- } else {
- amplify.publish(cstopic('ICE_TOOLS_REGIONS'), { label: '', region: region.id });
- }
- }
- };
- } else {
- regionSelectEl.options[0] = new Option('No Regions', '0', true, false);
- }
- } catch (err) {
- if (window.console && window.console.log) {
- console.log(err);
- }
- }
- };
- }
-
- var checkRenderingTemplates = function (renderingTemplates) {
- var noTemplate = true;
- for (var x = 0; x < renderingTemplates.length; x++) {
- if (renderingTemplates[x].uri != '') {
- noTemplate = false;
- }
- }
- return noTemplate;
- };
-
- wrapper = document.createElement('div');
- YDom.addClass(wrapper, 'edit-code template');
- var templateButtonEl = document.createElement('button');
- var templateIconEl = document.createElement('i');
- var templateLabelEl = document.createElement('span');
-
- YDom.addClass(templateIconEl, 'fa fa-code f14');
- templateLabelEl.innerHTML = CMgs.format(previewLangBundle, 'editTemplate');
-
- // YDom.addClass(wrapper, 'form-group');
- YDom.addClass(templateButtonEl, 'btn btn-default btn-block');
- YDom.addClass(templateLabelEl, 'acn-ptools-ice-label');
-
- templateButtonEl.appendChild(templateIconEl);
- templateButtonEl.appendChild(templateLabelEl);
- wrapper.style.marginleft = '4px';
- wrapper.appendChild(templateButtonEl);
-
- container.appendChild(wrapper);
-
- wrapper = document.createElement('div');
- YDom.addClass(wrapper, 'edit-code');
- var controllerButtonEl = document.createElement('button');
- var controllerIconEl = document.createElement('i');
- var controllerLabelEl = document.createElement('span');
-
- YDom.addClass(controllerIconEl, 'fa fa-code f14');
- controllerLabelEl.innerHTML = CMgs.format(previewLangBundle, 'editController');
-
- // YDom.addClass(wrapper, 'form-group');
- YDom.addClass(controllerButtonEl, 'btn btn-default btn-block');
- YDom.addClass(controllerLabelEl, 'acn-ptools-ice-label');
-
- controllerButtonEl.appendChild(controllerIconEl);
- controllerButtonEl.appendChild(controllerLabelEl);
- wrapper.appendChild(controllerButtonEl);
-
- container.appendChild(wrapper);
-
- templateButtonEl.onclick = function () {
- if (!checkRenderingTemplates(CStudioAuthoring.SelectedContent.getSelectedContent()[0].renderingTemplates)) {
- var selectedContent = CStudioAuthoring.SelectedContent.getSelectedContent()[0],
- renderingTemplate = selectedContent.renderingTemplates[0].uri,
- contentType = selectedContent.contentType;
-
- CStudioAuthoring.Operations.openCodeEditor({
- path: renderingTemplate,
- contentType,
- mode: 'ftl',
- onSuccess: () => {
- CStudioAuthoring.Operations.refreshPreview();
- }
- });
- } else {
- var dialogEl = document.getElementById('errNoTemplAssoc');
- if (!dialogEl) {
- var dialog = new YAHOO.widget.SimpleDialog('errNoTemplAssoc', {
- width: '400px',
- fixedcenter: true,
- visible: false,
- draggable: false,
- close: false,
- modal: true,
- text:
- CMgs.format(formsLangBundle, 'noTemplatesAssoc') +
- ' ' +
- CStudioAuthoring.SelectedContent.getSelectedContent()[0].internalName,
- icon: YAHOO.widget.SimpleDialog.ICON_BLOCK,
- constraintoviewport: true,
- buttons: [
- {
- text: CMgs.format(formsLangBundle, 'ok'),
- handler: function () {
- this.hide();
- },
- isDefault: false
- }
- ]
- });
- dialog.setHeader(CMgs.format(formsLangBundle, 'cancelDialogHeader'));
- dialog.render(document.body);
- dialogEl = document.getElementById('errNoTemplAssoc');
- dialogEl.dialog = dialog;
- }
- dialogEl.className += ' studioDialog';
- dialogEl.dialog.show();
- }
- };
-
- controllerButtonEl.onclick = function () {
- if (CStudioAuthoring.SelectedContent.getSelectedContent()[0].contentType) {
- var contentType = CStudioAuthoring.SelectedContent.getSelectedContent()[0].contentType.split('/');
- var path = '/scripts/pages/' + contentType[contentType.length - 1] + '.groovy';
-
- (function (controllerName) {
- var getContentItemCb = {
- success: function (contentTO) {
- var flag = true;
- for (var i = 0; i < contentTO.item.children.length; i++) {
- if (contentTO.item.children[i].name == controllerName) {
- flag = false;
- }
- }
-
- (function (flag) {
- CStudioAuthoring.Operations.openCodeEditor(path, contentType, 'groovy', () => {
- if (CStudioAuthoringContext.isPreview) {
- CStudioAuthoring.Operations.refreshPreview();
- }
- if (flag) {
- var callback = {
- success: function (contentTOItem) {
- eventYS.parent = false;
- eventYS.data = contentTOItem.item;
- eventYS.typeAction = '';
- document.dispatchEvent(eventYS);
- },
- failure: function () {}
- };
-
- CStudioAuthoring.Service.lookupContentItem(
- CStudioAuthoringContext.site,
- '/scripts/pages/',
- callback,
- false,
- false
- );
- }
- });
- })(flag);
- },
- failure: function () {}
- };
-
- CStudioAuthoring.Service.lookupSiteContent(
- CStudioAuthoringContext.site,
- '/scripts/pages/',
- 1,
- 'default',
- getContentItemCb
- );
- })(contentType[contentType.length - 1] + '.groovy');
- } else {
- var CMgs = CStudioAuthoring.Messages;
- var langBundle = CMgs.getBundle('forms', CStudioAuthoringContext.lang);
- CStudioAuthoring.Operations.showSimpleDialog(
- 'loadModelError-dialog',
- CStudioAuthoring.Operations.simpleDialogTypeINFO,
- CMgs.format(langBundle, 'notification'),
- CMgs.format(langBundle, 'controllerError'),
- null,
- YAHOO.widget.SimpleDialog.ICON_BLOCK,
- 'studioDialog'
- );
- }
- };
- var contextNavImg = YDom.get('acn-ice-tools-image');
- var cstopic = crafter.studio.preview.cstopic;
-
- CStudioAuthoring.Module.requireModule(
- 'ice-tools',
- '/static-assets/components/cstudio-preview-tools/ice-tools.js',
- {},
- {
- moduleLoaded: function () {
- CStudioAuthoring.IceTools.IceToolsOffEvent.subscribe(function onIceToolsOffEvent() {
- YDom.removeClass(pencilIcon, 'icon-yellow');
- YDom.addClass(pencilIcon, 'icon-default');
- YDom.removeClass(contextNavImg, 'icon-yellow');
- YDom.addClass(contextNavImg, 'icon-default');
- labelEl.innerHTML = CMgs.format(previewLangBundle, 'inContextEditOn');
-
- amplify.publish(cstopic('ICE_TOOLS_OFF'));
- });
-
- CStudioAuthoring.IceTools.IceToolsOnEvent.subscribe(function onIceToolsOnEvent() {
- YDom.removeClass(pencilIcon, 'icon-default');
- YDom.addClass(pencilIcon, 'icon-yellow');
- YDom.removeClass(contextNavImg, 'icon-default');
- YDom.addClass(contextNavImg, 'icon-yellow');
- YDom.replaceClass(containerEl.parentNode, 'contracted', 'expanded');
- labelEl.innerHTML = CMgs.format(previewLangBundle, 'inContextEditOff');
-
- amplify.publish(cstopic('ICE_TOOLS_ON'));
- });
- }
- }
- );
-
- if (iceOn) {
- CStudioAuthoring.IceTools.turnEditOn();
- }
-
- // Create the event
- var event = new CustomEvent('name-of-event', { detail: 'Example of an event' });
-
- // Dispatch/Trigger/Fire the event
- document.dispatchEvent(event);
- };
-
- CStudioAuthoring.Utils.isReviewer(callback);
- }
-};
-
-CStudioAuthoring.Module.moduleLoaded('ice-tools-panel', CStudioAuthoring.IceToolsPanel);
diff --git a/static-assets/components/cstudio-preview-tools/preview-tools.js b/static-assets/components/cstudio-preview-tools/preview-tools.js
deleted file mode 100644
index 4cc7f1045b..0000000000
--- a/static-assets/components/cstudio-preview-tools/preview-tools.js
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-(function () {
- var STUDIO_BAR_HEIGHT = 50;
-
- /**
- * editor tools
- */
- CStudioAuthoring.PreviewTools = CStudioAuthoring.PreviewTools || {
- initialized: false,
- panel: null,
- firstRender: true,
- PreviewToolsOffEvent: new YAHOO.util.CustomEvent('cstudio-preview-tools-off', CStudioAuthoring),
- PreviewToolsOnEvent: new YAHOO.util.CustomEvent('cstudio-preview-tools-on', CStudioAuthoring),
-
- /**
- * initialize module
- */
- initialize: function (config) {
- var panelEl, that, ptoOn, ptoLeft, ptoTop;
-
- if (!this.initialized) {
- that = this;
- panelEl = document.createElement('div');
- panelEl.id = 'preview-tools-panel-container';
- ptoOn = !!sessionStorage.getItem('pto-on'); // cast string value to a boolean
-
- if (!ptoOn) {
- // There are no preferences set yet. Store default values.
- ptoLeft = window.innerWidth - 300;
- ptoTop = 100;
- sessionStorage.setItem('pto-on', ''); // empty string value so that when we cast it to boolean we get false
- sessionStorage.setItem('pto-left', ptoLeft);
- sessionStorage.setItem('pto-top', ptoTop);
- } else {
- ptoLeft = +sessionStorage.getItem('pto-left'); // cast string value to a number
- ptoTop = +sessionStorage.getItem('pto-top'); // cast string value to a number
- }
-
- if (ptoTop < STUDIO_BAR_HEIGHT) ptoTop = STUDIO_BAR_HEIGHT;
-
- document.body.appendChild(panelEl);
-
- var panel = new YAHOO.widget.Panel('preview-tools-panel-container', {
- width: '265px',
- close: false,
- constraintoviewport: false,
- draggable: false,
- modal: false,
- visible: false,
- autofillheight: null
- });
-
- panel.moveEvent.subscribe(function (e, args) {
- that.updateLocationPrefs.call(that);
- if (args[0][1] < STUDIO_BAR_HEIGHT) {
- setTimeout(function () {
- panel.moveTo(args[0][0], STUDIO_BAR_HEIGHT);
- });
- }
- });
-
- YAHOO.widget.Overlay.windowResizeEvent.subscribe(function () {
- CStudioAuthoring.PreviewTools.panelCheckBounds.call(CStudioAuthoring.PreviewTools);
- });
-
- panel.setHeader('Preview Tools');
- panel.render();
-
- CStudioAuthoring.Service.lookupConfigurtion(CStudioAuthoringContext.site, '/preview-tools/panel.xml', {
- success: function (config) {
- this.context.buildModules(config);
-
- if (ptoOn) {
- this.context.turnToolsOn();
- } else {
- this.context.turnToolsOff();
- }
- },
- failure: CStudioAuthoring.Utils.noop,
- context: this
- });
-
- this.panel = panel;
- this.initialized = true;
- }
- },
-
- turnToolsOn: function () {
- this.panelCheckBounds();
- this.panel.show();
- sessionStorage.setItem('pto-on', 'on');
-
- var container = document.getElementById('container');
- if (container) {
- container.style.display = 'block';
- }
-
- this.PreviewToolsOnEvent.fire();
-
- $('.studio-preview').css('right', 265);
- },
-
- turnToolsOff: function () {
- this.panel.hide();
- sessionStorage.setItem('pto-on', ''); // empty string value so that when we cast it to boolean we get false+
-
- var container = document.getElementById('container');
- if (container) {
- container.style.display = 'none';
- }
-
- this.PreviewToolsOffEvent.fire();
-
- $('.studio-preview').css('right', 0);
- },
-
- /*
- * Update the panel's location preferences based on the panel's current coordinates.
- */
- updateLocationPrefs: function () {
- var panelXYvalues = this.panel.cfg.config.xy.value;
- sessionStorage.setItem('pto-left', panelXYvalues[0]);
- sessionStorage.setItem('pto-top', panelXYvalues[1] < STUDIO_BAR_HEIGHT ? STUDIO_BAR_HEIGHT : panelXYvalues[1]);
- },
-
- /*
- * Keep the panel within the horizontal limits of the window.
- * This method will be called, for example, when the window is resized.
- */
- panelCheckBounds: function () {
- var offsetX, panelWidth, rightPadding, panelX, panel, ptoTop, winWidth;
-
- panel = this.panel;
- offsetX = panel.cfg.config.x.value > 50 ? 50 : panel.cfg.config.x.value;
- panelWidth = +panel.cfg.config.width.value.split('px')[0];
- rightPadding = 20;
- winWidth = window.innerWidth;
-
- panelX = offsetX + panelWidth + rightPadding;
-
- // Update the panel's position since it's starting to be outside the window
- if (panelX > winWidth) {
- ptoTop = +sessionStorage.getItem('pto-top');
- offsetX = winWidth - panelWidth - rightPadding;
- panel.moveTo(offsetX, ptoTop);
- }
- },
-
- /**
- * given a dropdown configuration, build the nav
- */
- buildModules: function (navConfig) {
- var containerEl = document.getElementById('preview-tools-panel-container');
- containerEl.style.height = 'auto';
-
- if (navConfig.modules.module) {
- navConfig.modules = [navConfig.modules.module];
- }
-
- if (navConfig.modules.length) {
- var containersEls = [];
-
- for (var j = 0; j < navConfig.modules[0].length; j++) {
- var moduleContainerEl = document.createElement('div');
- containerEl.appendChild(moduleContainerEl);
- containersEls[j] = moduleContainerEl;
- }
-
- CStudioAuthoring.Module.requireModule(
- 'ice-tools',
- '/static-assets/components/cstudio-preview-tools/ice-tools.js'
- );
-
- for (var i = 0; i < navConfig.modules[0].length; i++) {
- var module = navConfig.modules[0][i];
- CStudioAuthoring.Module.requireModule(
- module.moduleName,
- '/static-assets/components/cstudio-preview-tools/mods/' + module.moduleName + '.js',
- { config: module },
- {
- context: this,
- containerEl: containersEls[i],
- moduleLoaded: function (moduleName, moduleClass, moduleConfig) {
- this.context.buildModule(this.containerEl, moduleClass, moduleConfig);
- moduleClass.initialize(moduleConfig);
- }
- }
- );
- }
- }
- },
-
- buildModule: function (containerEl, moduleClass, moduleConfig) {
- var moduleEl = document.createElement('div'),
- headerEl = document.createElement('div'),
- toggleEl = document.createElement('a'),
- panelEl = document.createElement('div'),
- previewLangBundle = CMgs.getBundle('previewTools', CStudioAuthoringContext.lang);
-
- var toggleFn = function (e) {
- YEvent.preventDefault(e);
-
- if (YDom.hasClass(moduleEl, 'contracted')) {
- YDom.replaceClass(moduleEl, 'contracted', 'expanded');
-
- if (!panelEl._csExpanded) {
- // only call this once
- panelEl._csExpanded = true;
- if (moduleClass.firstExpand) {
- moduleClass.firstExpand(panelEl, moduleConfig.config);
- }
- }
-
- if (moduleClass.expand) {
- moduleClass.expand(panelEl, moduleConfig.config);
- }
- } else {
- YDom.replaceClass(moduleEl, 'expanded', 'contracted');
- if (moduleClass.collapse) {
- moduleClass.collapse(panelEl, moduleConfig.config);
- }
- }
- };
-
- moduleClass.toggleFn = toggleFn;
-
- // create the header for a module
- YDom.addClass(moduleEl, 'contracted');
- YDom.addClass(headerEl, 'acn-accordion-header');
- YDom.addClass(toggleEl, 'acn-accordion-toggle');
- YDom.addClass(panelEl, 'acn-accordion-panel');
-
- const span = document.createElement('span');
- span.textContent = CMgs.format(previewLangBundle, moduleConfig.config.title);
-
- toggleEl.href = '#';
- toggleEl.appendChild(span);
- moduleEl.id = moduleConfig.config.moduleName + '-elem';
- headerEl.appendChild(toggleEl);
-
- containerEl.appendChild(moduleEl);
- moduleEl.appendChild(headerEl);
- moduleEl.appendChild(panelEl);
-
- toggleEl.onclick = toggleFn;
- moduleClass.render(panelEl, moduleConfig.config);
- }
- };
-
- CStudioAuthoring.Module.moduleLoaded('preview-tools-controller', CStudioAuthoring.PreviewTools);
-})();
diff --git a/static-assets/scripts/communicator.js b/static-assets/scripts/communicator.js
deleted file mode 100644
index ad2b69a21b..0000000000
--- a/static-assets/scripts/communicator.js
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-(function (window) {
- var define =
- typeof window.crafterDefine === 'function' && window.crafterDefine.amd
- ? window.crafterDefine
- : function (a, b, f) {
- f(window.crafter, window.amplify);
- };
-
- define('communicator', ['crafter', 'amplify'], function (crafter, amplify) {
- 'use strict';
-
- if (typeof amplify === 'undefined') {
- amplify = window.amplify;
- }
-
- var studio = crafter.studio,
- undefined;
-
- var SCOPE_LOCAL = 'SCOPE_LOCAL',
- SCOPE_BROADCAST = 'SCOPE_BROADCAST',
- SCOPE_EXTERNAL = 'SCOPE_EXTERNAL',
- SCOPE_REMOTE = 'SCOPE_REMOTE',
- ALL_TOPICS = '*';
-
- function Communicator(remotes, targetWindows, allowedOrigins) {
- if (arguments.length === 1) {
- allowedOrigins = remotes;
- targetWindows = [];
- remotes = [];
- } else if (arguments.length === 2) {
- allowedOrigins = targetWindows;
- targetWindows = remotes;
- remotes = [];
- }
-
- if (!remotes) {
- remotes = [];
- }
-
- if (!targetWindows) {
- remotes = [];
- }
-
- if (!allowedOrigins) {
- allowedOrigins = [];
- }
-
- if (typeof remotes === 'string' || !('splice' in remotes)) {
- remotes = [remotes];
- }
-
- if (typeof targetWindows === 'string' || !('splice' in targetWindows)) {
- targetWindows = [targetWindows];
- }
-
- if (typeof allowedOrigins === 'string' || !('splice' in allowedOrigins)) {
- allowedOrigins = [allowedOrigins];
- }
-
- var me = this;
- var privates = {
- remotes: remotes,
-
- targetWindows: targetWindows,
-
- defaultScope: SCOPE_BROADCAST,
-
- allowedOrigins: allowedOrigins
- };
-
- this.setAllowedOrigins = function (origins) {
- privates.allowedOrigins = origins;
- };
-
- this.getAllowedOrigins = function () {
- return privates.allowedOrigins;
- };
-
- this.getDefaultScope = function () {
- return privates.defaultScope;
- };
-
- this.setDefaultScope = function (defaultScope) {
- privates.defaultScope = defaultScope;
- };
-
- this.getTargetWindows = function () {
- return privates.targetWindows;
- };
-
- this.setTargetWindows = function (targetWindows) {
- privates.targetWindows = targetWindows;
- };
-
- window.addEventListener(
- 'message',
- function (event) {
- receiveMessage.call(me, event);
- },
- false
- );
-
- return this;
- }
-
- Communicator.prototype = {
- addOrigin,
- addTargetWindow,
- removeTargetWindow,
- isAllowedOrigin: isAllowedOrigin,
- publish,
- pub: publish,
- subscribe,
- on: subscribe,
- unsubscribe,
- dispatch
- };
-
- /*public*/
- function subscribe(topic, callback, scope) {
- return amplify.subscribe(getScopeSpecificTopic(topic, scope), callback);
- }
-
- /*public*/
- function unsubscribe(topic, callback, scope) {
- return amplify.unsubscribe(getScopeSpecificTopic(topic, scope), callback);
- }
-
- /*public*/
- function addOrigin(origin) {
- this.getAllowedOrigins().push(origin);
- }
-
- /*public*/
- function isAllowedOrigin(origin) {
- var origins = this.getAllowedOrigins(),
- i,
- l;
-
- for (i = 0, l = origins.length; i < l; ++i) {
- if (origins[i] === origin) {
- return true;
- }
- }
-
- return false;
- }
-
- /*public*/
- function addTargetWindow(targetWindow) {
- var hasWindow = false,
- targetWindows = this.getTargetWindows();
-
- for (var i = 0; !hasWindow && i < targetWindows.length; ++i)
- hasWindow = targetWindow.window === targetWindows[i].window;
-
- if (!hasWindow) targetWindows.push(targetWindow);
-
- return !hasWindow;
- }
-
- /*public*/
- function removeTargetWindow(targetWindow) {
- var i,
- hasWindow = false,
- targetWindows = this.getTargetWindows();
-
- for (i = 0; !hasWindow && i < targetWindows.length; ++i) hasWindow = targetWindow === targetWindows[i];
-
- if (!hasWindow) targetWindows.push(targetWindow);
-
- return !hasWindow;
- }
-
- /*public*/
- function publish(topic, message, scope) {
- switch (message) {
- case SCOPE_LOCAL:
- case SCOPE_REMOTE:
- case SCOPE_EXTERNAL:
- case SCOPE_BROADCAST:
- scope = message;
- message = undefined;
- break;
- }
-
- switch (scope) {
- case SCOPE_LOCAL:
- case SCOPE_REMOTE:
- case SCOPE_EXTERNAL:
- case SCOPE_BROADCAST:
- break;
- default:
- scope = this.getDefaultScope();
- }
-
- // Publish event locally.
- if (scope === SCOPE_LOCAL || scope === SCOPE_BROADCAST) {
- doLocalPublish(topic, scope, message);
- }
-
- // Publish data externally.
- if (scope === SCOPE_BROADCAST || scope === SCOPE_EXTERNAL) {
- sendMessage.call(this, { topic: topic, message: message, scope: scope });
- }
- }
-
- /*private*/
- function sendMessage(message, targetWindows) {
- !targetWindows && (targetWindows = this.getTargetWindows());
-
- message.meta = { craftercms: true, source: 'legacy' };
-
- for (var i = 0, l = targetWindows.length; i < l; ++i) {
- targetWindows[i].window.postMessage(message, targetWindows[i].origin);
- }
- }
-
- function dispatch(action) {
- var targetWindows = this.getTargetWindows();
- for (var i = 0, l = targetWindows.length; i < l; ++i) {
- targetWindows[i].window.postMessage(action, targetWindows[i].origin);
- }
- }
-
- /*private*/
- function receiveMessage(event) {
- if (this.isAllowedOrigin(event.origin)) {
- var data = event.data;
- if (data != null && typeof data === 'object') {
- if ('topic' in data) {
- doLocalPublish(data.topic, data.scope, data.message);
- } else if (
- // This is the signature of ui4 messages
- 'type' in data &&
- 'meta' in data
- ) {
- doLocalPublish(data.type, null, data.payload);
- }
- }
- }
- }
-
- /* private */
- function getScopeSpecificTopic(topic, scope) {
- return topic + (scope ? ':' + scope : '');
- }
-
- /* private */
- function doLocalPublish(topic, scope, message) {
- amplify.publish(ALL_TOPICS, topic, message, scope);
- amplify.publish(topic, message, scope);
- if (scope) {
- const scoped = getScopeSpecificTopic(topic, scope);
- amplify.publish(scoped, message, scope);
- }
- }
-
- Communicator.SCOPE_LOCAL = SCOPE_LOCAL;
- Communicator.SCOPE_BROADCAST = SCOPE_BROADCAST;
- Communicator.SCOPE_EXTERNAL = SCOPE_EXTERNAL;
- Communicator.SCOPE_REMOTE = SCOPE_REMOTE;
-
- studio.define('Communicator', Communicator);
-
- return Communicator;
- });
-})(window);
diff --git a/static-assets/scripts/dnd-controller.js b/static-assets/scripts/dnd-controller.js
deleted file mode 100644
index 0af5fe2be4..0000000000
--- a/static-assets/scripts/dnd-controller.js
+++ /dev/null
@@ -1,850 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-crafterDefine(
- 'dnd-controller',
- ['crafter', 'jquery', 'jquery-ui', 'animator', 'communicator'],
- function (crafter, $, $ui, Animator, Communicator) {
- 'use strict';
-
- var Topics = crafter.studio.preview.Topics,
- string = crafter.String;
-
- var OVERLAY_TPL = '';
- var PALETTE_TPL = [
- '',
- 'Done',
- 'Components',
- '',
- '',
- ''
- ].join('');
- var COMPONENT_TPL =
- '%@';
- var BROWSE_TPL =
- 'Browse %@';
- var DRAGGABLE_SELECTION = '.studio-components-container .studio-component-drag-target';
- var DROPPABLE_SELECTION = '[data-studio-components-target]';
- var PANEL_ON_BD_CLASS = 'studio-dnd-enabled';
- var DROPPABLE_SELECTION_SIZE = '[data-studio-components-size]';
-
- var $body = $('body:first');
- var $document = $(document);
- var $window = $(window);
- var found = {};
- var pathSearched = [];
- var currentModel = {};
-
- function DnDController(config) {
- var $overlay = $(OVERLAY_TPL),
- $palette = $(PALETTE_TPL),
- animator = new Animator(),
- config = config || {},
- communicator = config.communicator,
- active = false,
- me = this,
- timeout;
-
- $palette.on('click', '[data-action]', function (e) {
- e.stopPropagation();
- me[$(this).data('action')]();
- });
-
- this.active = function (value) {
- if (arguments.length) {
- active = !!value;
- }
- return active;
- };
-
- this.cfg = function (property, value) {
- if (arguments.length > 1) config[property] = value;
- return config[property];
- };
-
- this.getAnimator = function ($el) {
- $el && animator.$el($el);
- return animator;
- };
-
- this.getOverlay = function () {
- return $overlay;
- };
-
- this.getPalette = function () {
- return $palette;
- };
-
- $palette.on('click', '.studio-category-name-collapse', function () {
- $(this).parent().toggleClass('studio-collapse');
- });
-
- // TODO currently not in use.
- // component-panel.js loads from page load rather than when enabling dnd
- // hence the page model loads from page load too.
- if (communicator) {
- communicator.on(Topics.DND_COMPONENT_MODEL_LOAD, function (data) {
- componentModelLoad.call(me, data.trackingNumber, data.model);
- });
- communicator.on(Topics.DND_COMPONENTS_MODEL_LOAD, function (data) {
- componentsModelLoad.call(me, data);
- });
- communicator.on(Topics.DND_PANEL_OFF, function () {
- me.done();
- });
- }
- }
-
- DnDController.prototype = {
- start: enableDnD,
- stop: disableDnD,
- done: done
- };
-
- return DnDController;
-
- function findZIndex() {
- var highest = -999;
- $('*').each(function () {
- var current = parseInt($(this).css('z-index'), 10);
- if (current && highest < current) highest = current;
- });
- return highest;
- }
-
- function disableDnD() {
- var callback,
- key = 'pto-on',
- communicator = this.cfg('communicator');
-
- callback = function (message) {
- if (message.key === key) {
- communicator.unsubscribe(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, callback);
-
- if (!!message.value) {
- communicator.publish(Topics.SET_SESSION_STORAGE_ITEM, {
- key: 'components-on',
- value: ''
- });
- }
-
- if (!this.active()) {
- return;
- }
-
- this.active(false);
-
- $(DRAGGABLE_SELECTION).draggable('destroy');
- $(DROPPABLE_SELECTION).sortable('destroy');
- $body.removeClass(PANEL_ON_BD_CLASS);
-
- var $p = this.getPalette(),
- $o = this.getOverlay();
-
- this.getAnimator($o).fadeOut();
- this.getAnimator($p).slideOutRight(function () {
- $o.detach();
- $p.detach();
- communicator.publish('DRAG_AND_DROP_COMPONENTS_PANEL_CLOSED');
- });
-
- $('.removeComp').remove();
- }
- };
-
- communicator.on(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, callback.bind(this));
- publish.call(this, Topics.REQUEST_SESSION_STORAGE_ITEM, key);
- }
-
- function done() {
- var me = this,
- callback,
- communicator = this.cfg('communicator');
- callback = function (message) {
- if (typeof message === 'object' && 'ice-on' in message) {
- communicator.unsubscribe(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, callback);
-
- amplify.publish(Topics.ICE_TOOLS_OFF);
- me.stop();
-
- var iceOn = !!message['ice-on'],
- ptoOn = !!message['pto-on'];
-
- if (ptoOn) {
- publish.call(me, Topics.STOP_DRAG_AND_DROP);
- }
- if (iceOn) {
- publish.call(me, Topics.ICE_CHANGE_PENCIL_ON);
- }
- }
- };
-
- communicator.on(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, callback);
- publish.call(this, Topics.REQUEST_SESSION_STORAGE_ITEM, ['ice-on', 'pto-on']);
- }
-
- function enableDnD(components, initialComponentModel, browse) {
- amplify.publish(Topics.ICE_TOOLS_OFF);
- var communicator = this.cfg('communicator');
-
- publish.call(this, Topics.SET_SESSION_STORAGE_ITEM, {
- key: 'components-on',
- value: 'true'
- });
-
- publish.call(this, Topics.ICE_CHANGE_PENCIL_OFF);
- currentModel = initialComponentModel;
-
- if (this.active()) return;
- this.active(true);
-
- var $p = this.getPalette(),
- $o = this.getOverlay(),
- me = this;
-
- $body.addClass(PANEL_ON_BD_CLASS);
-
- $o.appendTo($body);
- $p.appendTo($body);
-
- renderPalette.call(this, components, browse);
-
- this.getAnimator($o).fadeIn();
- this.getAnimator($p).slideInRight();
-
- $("[data-studio-components-size='small']").each(function (index) {
- $(this).width($(this).width() / 2);
- });
-
- $(DRAGGABLE_SELECTION).draggable({
- revert: 'invalid',
- helper: 'clone',
- appendTo: 'body',
- cursor: 'move',
- connectToSortable: DROPPABLE_SELECTION,
- zIndex: 1030
- });
-
- let dndInProgress = null;
- let validationInProgress = null;
- var cacheValidation = {};
-
- function restrictions($dropZone, $component, isNew) {
- if (dndInProgress !== null) {
- let temp = dndInProgress;
- dndInProgress = null;
- return temp;
- }
- var valid = true;
- var isDestZoneEmbedded =
- $component.parents('[data-studio-embedded-item-id]').attr('data-studio-embedded-item-id') || false;
- var isCurrentZoneEmbedded =
- $dropZone.parents('[data-studio-embedded-item-id]').attr('data-studio-embedded-item-id') || false;
- var DestContentType =
- $component.parents('[data-studio-zone-content-type]').attr('data-studio-zone-content-type') || null;
- var currentContentType = $dropZone.attr('data-studio-zone-content-type') || null;
- var isItemEmbedded;
- var currentTrackingNumber;
- var destTrackingNumber;
-
- // We are moving a component
- if (!isNew) {
- currentTrackingNumber = $dropZone.attr('data-studio-zone-tracking');
- destTrackingNumber = $component.parents('[data-studio-zone-tracking]').attr('data-studio-zone-tracking');
- isItemEmbedded = $component.attr('data-studio-embedded-item-id') || false;
- } else {
- let path = $component.attr('data-studio-component-path');
- isItemEmbedded = path ? false : true;
- }
-
- var sameDropZone = currentTrackingNumber === destTrackingNumber;
-
- // checking if both have contentType
- if (!DestContentType || !currentContentType) {
- valid = false;
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'contentTypeNotFound',
- link: 'https://craftercms.com/docs/current/by-role/developer/common/experience-builder.html',
- height: 'auto'
- });
- }
-
- if (isDestZoneEmbedded) {
- valid = false;
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'embeddedComponentsDndNotSupported',
- height: 'auto'
- });
- } else if (isItemEmbedded && !sameDropZone) {
- valid = false;
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'embeddedComponentsDragWithinParentOnly',
- height: 'auto'
- });
- } else if (isCurrentZoneEmbedded) {
- valid = false;
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'moveOutEmbeddedComponentsNotSupported',
- height: 'auto'
- });
- }
-
- if (!valid) {
- if (isNew) {
- $component.remove();
- window.location.reload();
- } else {
- $(DROPPABLE_SELECTION).sortable('cancel');
- }
- }
-
- // if it is a move it is doing 2 calls
- if (!isNew) {
- dndInProgress = valid;
- }
- // if it is a move within the same dropzone is doing 1 call
- if (sameDropZone) {
- dndInProgress = null;
- }
- return valid;
- }
-
- function validation($dropZone, $component, contentType, zone, componentType, response) {
- var childContent = componentType === 'shared-content' ? 'child-content' : null;
- var key = `${zone}-${componentType}`;
-
- return new Promise((resolve, reject) => {
- if (cacheValidation[key]) {
- resolve(cacheValidation[key]);
- } else {
- cacheValidation[key] = { supported: false, ds: null };
- }
- var selector;
- response.sections.forEach((section) => {
- var _selector = section.fields.find((item) => item.id === zone);
- if (_selector) selector = _selector;
- });
- var selectorDS = selector.properties.find((item) => item.name === 'itemManager');
- selectorDS.value.split(',').forEach((ds) => {
- var type = response.datasources.find((formDS) => formDS.id === ds).type;
- if (type === componentType || type === childContent)
- cacheValidation[key] = {
- supported: true,
- ds: ds
- };
- return true;
- });
- resolve(cacheValidation[key]);
- });
- }
-
- function updateDop(self, me, ui) {
- var $dropZone = $(self),
- $component = ui.item,
- compPath = $component.attr('data-studio-component-path'),
- zonePath = $dropZone
- .parents('[data-studio-component-path="' + compPath + '"]')
- .attr('data-studio-component-path'),
- orgZoneComp = ui.item.parents('[data-studio-components-target]').parents('[data-studio-component-path]'),
- destZoneComp = $dropZone.parents('[data-studio-component-path]');
-
- var isNew = $component.hasClass('studio-component-drag-target');
- var destContentType =
- $component.parents('[data-studio-zone-content-type]').attr('data-studio-zone-content-type') || null;
- var componentType;
- var zone = $component.parents('[data-studio-components-target]').attr('data-studio-components-target') || null;
- if (!isNew) {
- componentType = $component.attr('data-studio-embedded-item-id') ? 'embedded-content' : 'shared-content';
- } else {
- let path = $component.attr('data-studio-component-path');
- componentType = path ? 'shared-content' : 'embedded-content';
- }
-
- if (
- orgZoneComp.attr('data-studio-component-path') != destZoneComp.attr('data-studio-component-path') ||
- (orgZoneComp.attr('data-studio-component-path') == destZoneComp.attr('data-studio-component-path') &&
- $dropZone.attr('data-studio-components-objectid') !=
- ui.item.parents('[data-studio-components-target]').attr('data-studio-components-objectid')) ||
- (orgZoneComp.attr('data-studio-component-path') == destZoneComp.attr('data-studio-component-path') &&
- orgZoneComp.attr('data-studio-tracking-number') == destZoneComp.attr('data-studio-tracking-number') &&
- $dropZone.attr('data-studio-components-objectid') ==
- ui.item.parents('[data-studio-components-target]').attr('data-studio-components-objectid'))
- ) {
- if (restrictions($dropZone, $component, isNew)) {
- var callback = function (response) {
- validation($dropZone, $component, destContentType, zone, componentType, response).then((response) => {
- validationInProgress = null;
- if (response.supported) {
- componentDropped.call(me, $dropZone, $component, response.ds);
- } else {
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'componentNotWelcomeWithinDropZone',
- height: 'auto'
- });
- if (isNew) {
- $component.remove();
- window.location.reload();
- } else {
- $(DROPPABLE_SELECTION).sortable('cancel');
- }
- }
- });
- communicator.unsubscribe(Topics.REQUEST_FORM_DEFINITION_RESPONSE, callback);
- };
- communicator.on(Topics.REQUEST_FORM_DEFINITION_RESPONSE, callback);
-
- // Validation with cache avoiding doble validation...
- let key = `${zone}-${componentType}`;
- if (cacheValidation[key] && cacheValidation[key].supported) {
- communicator.unsubscribe(Topics.REQUEST_FORM_DEFINITION_RESPONSE, callback);
- componentDropped.call(me, $dropZone, $component, cacheValidation[key].ds, Boolean(ui.sender));
- } else if (validationInProgress === null) {
- validationInProgress = true;
- publish.call(me, Topics.REQUEST_FORM_DEFINITION, { contentType: destContentType });
- }
- }
- } else {
- $(DROPPABLE_SELECTION).sortable('cancel');
- }
- }
-
- $(DROPPABLE_SELECTION).sortable({
- me: this,
- items: '[data-studio-component]',
- cursor: 'move',
- forceHelperSize: true,
- forcePlaceholderSize: true,
- greedy: true,
- connectWith: DROPPABLE_SELECTION,
- hoverClass: 'studio-draggable-over',
- over: function (event, ui) {
- $(this).addClass('studio-draggable-over');
- },
- out: function (event, ui) {
- $(this).removeClass('studio-draggable-over');
- },
- start: function (event, ui) {
- ui.item.addClass('studio-component-over');
- },
- stop: function (event, ui) {
- ui.item.removeClass('studio-component-over');
- },
- update: function (e, ui) {
- var self = this;
- if (!ui.sender) {
- // from where
- updateDop(self, me, ui);
- } else {
- setTimeout(function () {
- // to where
- updateDop(self, me, ui);
- }, 300);
- }
- }
- });
-
- $('[data-studio-component]').each(function () {
- $(this).attr('data-studio-tracking-number', crafter.guid());
- });
-
- $('[data-studio-components-target]').each(function (i) {
- var $me = $(this);
- $me.attr('data-studio-zone-tracking', crafter.guid());
- });
-
- componentsModelLoad.call(me, initialComponentModel);
-
- $('.ui-sortable-handle').each(function (index) {
- var delControl = createDeleteControl('removeComp fa fa-times-circle');
- delControl.onclick = function () {
- var compPath = $(this).parent().parents('[data-studio-component-path]').attr('data-studio-component-path');
- var objectId = $(this)
- .parent()
- .parents('[data-studio-components-target]')
- .attr('data-studio-components-objectid');
- var compTracking = $(this)
- .parent()
- .parents('[data-studio-component-path]')
- .attr('data-studio-tracking-number');
- var dropName = $($(this).parent().parents('[data-studio-components-target]')[0]).attr(
- 'data-studio-components-target'
- );
- var trackingZone = $($(this).parent().parents('[data-studio-components-target]')[0]).attr(
- 'data-studio-zone-tracking'
- );
- var index = 0,
- currentTag = '',
- zone;
- var isCurrentZoneEmbedded =
- $(this).parent().parents('[data-studio-embedded-item-id]').attr('data-studio-embedded-item-id') || false;
- if (isCurrentZoneEmbedded) {
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'embeddedComponentsDeleteChildNotSupported',
- height: 'auto'
- });
- return false;
- }
- removeComponent(this, function () {
- var zones = {};
- var conRepeat = 0;
- var indexStructure = 0;
- setTimeout(function () {
- $('[data-studio-components-target]').each(function () {
- zone = $(this).attr('data-studio-components-target');
- if (currentTag !== zone) {
- index = 0;
- currentTag = zone;
- }
- if (
- objectId == $(this).attr('data-studio-components-objectid') &&
- trackingZone == $(this).attr('data-studio-zone-tracking')
- ) {
- if (dropName == $(this).attr('data-studio-components-target')) {
- conRepeat++;
- }
- if (
- compTracking == $(this).parents('[data-studio-component-path]').attr('data-studio-tracking-number')
- ) {
- var $el = $(this),
- zoneName = $el.attr('data-studio-components-target');
- zones[zoneName] = [];
- $el.find('> [data-studio-component]').each(function (i, el) {
- var $comp = $(this);
- zones[zoneName].push($comp.data('model') || tracking);
- });
- }
- if (zone.indexOf('.') > 0) {
- if (currentTag !== zone) {
- index = 0;
- currentTag = zone;
- }
- var structure1 = zone.split('.')[0],
- structure2 = zone.split('.')[1];
- currentModel[structure1][index][structure2] = zones[zone];
- zones[structure1] = currentModel[structure1];
- }
- }
- index++;
- });
-
- publish.call(me, Topics.SAVE_DRAG_AND_DROP, {
- isNew: false,
- zones: zones,
- compPath: compPath,
- conComp: conRepeat > 1 ? true : false
- });
- });
- });
- };
- $(this).append(delControl);
- });
- }
-
- function componentDropped($dropZone, $component, datasource, isInsert) {
- var compPath = $dropZone.parents('[data-studio-component-path]').attr('data-studio-component-path');
- var compTracking = $dropZone.parents('[data-studio-component-path]').attr('data-studio-tracking-number');
- var objectId = $dropZone.attr('data-studio-components-objectid');
- var trackingZone = $dropZone.attr('data-studio-zone-tracking');
- var dropName = $dropZone.attr('data-studio-components-target');
- var index = 0,
- currentTag = '',
- zone;
-
- var me = this,
- isNew = $component.hasClass('studio-component-drag-target'),
- tracking,
- path,
- type,
- name,
- zones = {},
- indexStructure = 0;
-
- if (isNew) {
- path = $component.attr('data-studio-component-path');
- type = $component.attr('data-studio-component-type');
- name = $component.text();
- tracking = crafter.guid();
- $component.before(
- string(
- '
%@
'
- ).fmt(type, path, tracking, name)
- );
- $component.remove();
- } else {
- tracking = $component.attr('data-studio-tracking-number');
- path = $component.attr('data-studio-component-path');
- type = $component.attr('data-studio-component');
- }
-
- // DOM Reorganization hasn't happened at this point,
- // need a timeout to grab out the updated DOM structure
- var conRepeat = 0;
- setTimeout(function () {
- $('[data-studio-components-target]').each(function () {
- zone = $(this).attr('data-studio-components-target');
- if (currentTag !== zone) {
- index = 0;
- currentTag = zone;
- }
- if (
- objectId == $(this).attr('data-studio-components-objectid') &&
- trackingZone == $(this).attr('data-studio-zone-tracking')
- ) {
- if (dropName == $(this).attr('data-studio-components-target')) {
- conRepeat++;
- }
- if (compTracking == $(this).parents('[data-studio-component-path]').attr('data-studio-tracking-number')) {
- var $el = $(this),
- zoneName = $el.attr('data-studio-components-target');
- zones[zoneName] = [];
- $el.find('> [data-studio-component]').each(function (i, el) {
- var $comp = $(this);
- zones[zoneName].push($comp.data('model') || tracking);
- });
- }
- if (zone.indexOf('.') > 0) {
- var structure1 = zone.split('.')[0],
- structure2 = zone.split('.')[1];
- currentModel[structure1][index][structure2] = zones[zone];
- zones[structure1] = currentModel[structure1];
- }
- }
- index++;
- });
-
- publish.call(me, Topics.COMPONENT_DROPPED, {
- path: path,
- type: type,
- isNew: isNew,
- zones: zones,
- trackingNumber: tracking,
- compPath: compPath,
- conComp: conRepeat > 1 ? true : false,
- datasource: datasource,
- isInsert
- });
- });
- }
-
- function componentModelLoad(tracking, data) {
- $('[data-studio-tracking-number="' + tracking + '"]').data('model', data);
- }
-
- var contentTypeValidationInProgress = null;
- function componentsModelLoad(data) {
- var aNotFound = [],
- me = this,
- noObjectid = 0,
- structure1,
- structure2,
- index = 0,
- currentTag = '',
- noContentType = 0;
-
- $('[data-studio-components-target]').each(function () {
- var $el = $(this),
- objectId = $el.attr('data-studio-components-objectid'),
- tracking = $el.attr('data-studio-zone-tracking'),
- name = $el.attr('data-studio-components-target'),
- path = $el.parents('[data-studio-component-path]').attr('data-studio-component-path'),
- id = objectId + '-' + name;
- if (!$el.attr('data-studio-zone-content-type')) {
- noContentType++;
- }
- // avoid searching if the item is embedded;
- if (!$el.parents('[data-studio-embedded-item-id]').attr('data-studio-embedded-item-id')) {
- if (name.indexOf('.') < 0) {
- if (objectId) {
- if (!found[id] || objectId == data['objectId']) {
- if ((data[name] || data[name] == '') && objectId == data['objectId']) {
- // objid?
- found[id] = true;
- $el.find('> [data-studio-component]').each(function (i, el) {
- $(this).data('model', data[name][i]);
- });
- } else {
- var repeated = false;
- for (var j = 0; j < aNotFound.length; j++) {
- if (aNotFound[j].path == path && aNotFound[j].name == name) {
- repeated = true;
- }
- }
- if (!repeated) {
- aNotFound.push({ path: path, name: name });
- }
- }
- }
- } else {
- noObjectid++;
- }
- } else {
- if (currentTag !== name) {
- index = 0;
- currentTag = name;
- }
- structure1 = name.split('.')[0];
- structure2 = name.split('.')[1];
- if (objectId) {
- if (!found[id] || objectId == data['objectId']) {
- if (
- (data[structure1][index][structure2] || data[structure1][index][structure2] == '') &&
- objectId == data['objectId']
- ) {
- // /objid?
- found[id] = true;
- $el.find('> [data-studio-component]').each(function (i, el) {
- $(this).data('model', data[structure1][index][structure2][i]);
- });
- } else {
- var repeated = false;
- for (var j = 0; j < aNotFound.length; j++) {
- if (aNotFound[j].path == path && aNotFound[j].name == name) {
- repeated = true;
- }
- }
- if (!repeated) {
- aNotFound.push({ path: path, name: name });
- }
- }
- index++;
- }
- } else {
- noObjectid++;
- }
- }
- }
- });
-
- var isSearched = false;
- if (aNotFound.length && aNotFound.length > 0) {
- if (aNotFound[0].path) {
- for (var i = 0; i < pathSearched.length; i++) {
- if (aNotFound[0].path === pathSearched[i]) {
- isSearched = true;
- }
- }
- if (!isSearched) {
- pathSearched.push(aNotFound[0].path);
- publish.call(this, Topics.LOAD_MODEL_REQUEST, {
- aNotFound: aNotFound[0]
- });
- }
- } else {
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'pathNotFound',
- link: 'https://craftercms.com/docs/current/by-role/developer/common/experience-builder.html',
- height: 'auto'
- });
- }
- }
- if (noObjectid > 0) {
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'objectIdNotFound',
- link: 'https://craftercms.com/docs/current/by-role/developer/common/experience-builder.html',
- height: 'auto'
- });
- }
- if (noContentType > 0) {
- noContentType = 0;
- if (contentTypeValidationInProgress == null) {
- publish.call(me, Topics.START_DIALOG, {
- messageKey: 'contentTypeNotFound',
- link: 'https://craftercms.com/docs/current/by-role/developer/common/experience-builder.html',
- height: 'auto'
- });
- contentTypeValidationInProgress = true;
- }
- }
- }
-
- function publish(topic, message, com) {
- if ((com = this.cfg('communicator'))) {
- com.publish(topic, message);
- }
- }
-
- function resize() {
- this.getOverlay().css({
- width: $document.width(),
- height: $document.height()
- });
- }
-
- function renderPalette(components, browse) {
- var html = [],
- $c = this.getPalette().children('.studio-components-container'),
- me = this,
- browseId = '';
- $.each(components || [], function (i, category) {
- html.push('');
- html.push('' + category.label + '');
- html.push('');
- if (category.components) {
- var textArea = document.createElement('textarea');
- if (category.components.length) {
- $.each(category.components, function (j, component) {
- textArea.textContent = component.label;
- html.push(crafter.String(COMPONENT_TPL).fmt(component.path || '', component.type, textArea.innerHTML));
- });
- } else {
- textArea.textContent = category.components.label;
- html.push(
- crafter
- .String(COMPONENT_TPL)
- .fmt(category.components.path || '', category.components.type, textArea.innerHTML)
- );
- }
- }
- html.push('');
- html.push('');
- });
- $.each(browse || [], function (i, browse) {
- browseId = browse.label.replace(/\s|-|_|\/\./g, '').toLowerCase();
- html.push(crafter.String(BROWSE_TPL).fmt(browseId, browse.path, browse.label));
- });
- $c.html(html.join(''));
-
- $('.add-existing-component').on('click', function (e) {
- e.preventDefault();
- var path = $(this).attr('data-path');
-
- publish.call(me, Topics.OPEN_BROWSE, {
- path: path
- });
- });
- }
-
- function createDeleteControl(className) {
- var deleteEl = document.createElement('a'),
- btnEl = document.createElement('i');
-
- $(deleteEl).addClass(className);
-
- btnEl.style.width = '16px';
- btnEl.style.height = '16px';
-
- deleteEl.appendChild(btnEl);
- return deleteEl;
- }
-
- function removeComponent(srcEl, callback) {
- srcEl.parentNode.remove();
- if (typeof callback == 'function') {
- callback();
- }
- }
- }
-);
diff --git a/static-assets/scripts/guest.js b/static-assets/scripts/guest.js
deleted file mode 100644
index b901d8c9c6..0000000000
--- a/static-assets/scripts/guest.js
+++ /dev/null
@@ -1,460 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-crafterDefine(
- 'guest',
- ['crafter', 'jquery', 'communicator', 'ice-overlay'],
- function (crafter, $, Communicator, ICEOverlay) {
- 'use strict';
-
- if (window.location.search.includes('crafterCMSGuestDisabled=true')) {
- return;
- }
-
- $.noConflict(true);
-
- if (!window.location.origin) {
- window.location.origin =
- window.location.protocol +
- '//' +
- window.location.hostname +
- (window.location.port ? ':' + window.location.port : '');
- }
-
- var Topics = crafter.studio.preview.Topics,
- Constants = { TIME_RESIZE: 500, TIME_SCROLL: 250 },
- communicator,
- origin,
- timeout = null,
- count = 0,
- overlay = new ICEOverlay(),
- $document = $(document),
- $window = $(window),
- dndController,
- pointerControllerVar,
- iceToolsOn = false,
- dndOn = false;
-
- window.studioICERepaint = iceRepaint;
-
- return {
- init,
- iceRepaint,
- repaintPencils,
- reportNavigation,
- initICERegions,
- version: '4'
- };
-
- function reportNavigation(location, url) {
- communicator && communicator.publish(Topics.GUEST_SITE_URL_CHANGE, { location, url });
- }
-
- function init(config) {
- if (window.parent === window) {
- return (
- console &&
- console.warn &&
- console.warn(
- "[CrafterCMS] Host is not running inside of Studio as it's parent window. " +
- 'ICE mechanics will be disabled. Configure your authoring Environment to point to ' +
- `'${window.origin}' if you wish to enable In Context Editing.`
- )
- );
- }
-
- origin = config.hostOrigin;
-
- communicator = new Communicator(
- {
- window: window.parent,
- origin
- },
- origin
- );
-
- communicator.on(Topics.START_DRAG_AND_DROP, function (message) {
- dndOn = true;
- crafterRequire(['dnd-controller'], function (DnDController) {
- typeof dndController === 'undefined' &&
- (dndController = new DnDController({
- communicator: communicator
- }));
-
- dndController.start(message.components, message.contentModel, message.browse);
-
- var translation = message.translation;
- var elements = $('[data-translation]');
- elements.each(function () {
- var translationAttr = $(this).attr('data-translation');
- if (translationAttr == 'done') {
- $(this).html(translation.done);
- }
- if (translationAttr == 'components') {
- $(this).html(translation.components);
- }
- if (translationAttr == 'addComponent') {
- $(this).html(translation.addComponent);
- }
- });
- });
- });
-
- communicator.on(Topics.DND_COMPONENTS_PANEL_OFF, function (message) {
- crafterRequire(['dnd-controller'], function (DnDController) {
- typeof dndController === 'undefined' &&
- (dndController = new DnDController({
- communicator: communicator
- }));
-
- dndController.done();
- });
- });
-
- communicator.on(Topics.DND_CREATE_BROWSE_COMP, function (message) {
- crafterRequire(['pointer-controller'], function (pointerController) {
- typeof pointerControllerVar === 'undefined' &&
- (pointerControllerVar = new pointerController({
- communicator: communicator
- }));
-
- pointerControllerVar.start(message.component, message.initialContentModel);
- });
- });
-
- communicator.on(Topics.REFRESH_PREVIEW, function () {
- window.location.reload();
- });
-
- communicator.on('RELOAD_REQUEST', function () {
- window.location.reload();
- });
-
- window.addEventListener(
- 'beforeunload',
- () => {
- checkout(communicator);
- },
- false
- );
-
- function iceToolsToggle(on) {
- iceToolsOn = Boolean(on);
- if (on && !dndOn) {
- initICERegions();
- } else {
- removeICERegions();
- }
- }
-
- // Enable pencils, calls an event that renders the pencils (visual, no model in between)
- communicator.on('EDIT_MODE_CHANGED', (message) => iceToolsToggle(message.editMode));
- communicator.on(Topics.ICE_TOOLS_OFF, () => iceToolsToggle(false));
- communicator.on(Topics.ICE_TOOLS_ON, () => iceToolsToggle(true));
- communicator.on('DRAG_AND_DROP_COMPONENTS_PANEL_CLOSED', () => {
- dndOn = false;
- });
-
- communicator.on(Topics.REPAINT_PENCILS, repaintPencils);
-
- communicator.on(Topics.ICE_TOOLS_REGIONS, function (message) {
- var elt = document.querySelectorAll('[data-studio-ice' + message.label + '="' + message.region + '"]')[0];
- if (!elt) {
- elt = document.querySelectorAll(
- '[data-studio-ice' + message.label + '="' + message.region.replace(/ /g, '__') + '"]'
- )[0];
- }
- if (elt) {
- elt.scrollIntoView();
- window.scrollBy(0, -150);
- window.setTimeout(function () {
- initOverlay($(elt));
- window.setTimeout(function () {
- overlay.hide();
- }, 1000);
- }, 500);
- } else {
- alert('Region ' + message.region + ' could not be found');
- }
- });
-
- communicator.on(Topics.INIT_ICE_REGIONS, initIceRegions_resizeIceRegions_handler);
-
- communicator.on(Topics.RESIZE_ICE_REGIONS, initIceRegions_resizeIceRegions_handler);
-
- communicator.on(Topics.CHANGE_GUEST_REQUEST, (params) => {
- const locationOrigin = window.location.origin;
- if (window.location.href.replace(locationOrigin, '') !== params.url) {
- window.location.href = `${locationOrigin}${params.url}`;
- }
- });
-
- // When the page has successfully loaded, notify the host window of it's readiness
- communicator.publish(Topics.GUEST_SITE_LOAD, {
- location: {
- hash: window.location.hash,
- host: window.location.host,
- hostname: window.location.hostname,
- href: window.location.href,
- origin: window.location.origin,
- pathname: window.location.pathname,
- port: window.location.port,
- protocol: window.location.protocol,
- search: window.location.search
- },
- url: window.location.href.replace(window.location.origin, '')
- });
-
- communicator.publish(Topics.IS_REVIEWER);
-
- // ICE zone highlighting on hover
- $document
- .on('mouseover', '.studio-ice-indicator', function () {
- var $i = $(this),
- $e = $(crafter.String('[data-studio-ice-target="%@"]').fmt($i.data('studioIceTrigger')));
- initOverlay($e);
- })
- .on('mouseout', '.studio-ice-indicator', function () {
- overlay.hide();
- });
-
- // Event on pencil click, publishes ICE_ZONE_ON, which opens the form
- $document.on('click', '.studio-ice-indicator', function (e) {
- e.preventDefault();
- e.stopPropagation();
- let pencilClasses = 'fa-pencil icon-yellow';
- let spinnerClases = 'fa-spinner fa-spin icon-default';
-
- if ($(e.target).hasClass(spinnerClases)) return false;
-
- $(e.target).removeClass(pencilClasses);
- $(e.target).addClass(spinnerClases);
-
- setTimeout(function () {
- $(e.target).removeClass(spinnerClases);
- $(e.target).addClass(pencilClasses);
- }, 4000);
-
- var $i = $(this);
- var $e = $(crafter.String('[data-studio-ice-target="%@"]').fmt($i.data('studioIceTrigger')));
- var iceId = $e.data('studioIce');
- var icePath = $e.data('studioIcePath');
- var iceEmbeddedItemId = $e.data('studioEmbeddedItemId');
-
- var position = $e.offset(),
- props = {
- top: position.top,
- left: position.left,
- width: $e.width(),
- height: $e.height()
- };
-
- props.iceId = iceId;
- props.itemId = icePath;
- props.embeddedItemId = iceEmbeddedItemId;
- props.scrollTop = $window.scrollTop();
- props.scrollLeft = $window.scrollLeft();
-
- communicator.publish(Topics.ICE_ZONE_ON, props);
- });
-
- // Toggle edit mode on UI4
- $document.on('keypress', function (e) {
- if (e.key.toLowerCase() === 'e') {
- communicator.publish('EDIT_MODE_TOGGLE_HOTKEY');
- }
- });
-
- $(window).resize(function (e) {
- clearSetTimeout(Constants.TIME_RESIZE);
- });
-
- $('window, *').scroll(function (e) {
- clearSetTimeout(Constants.TIME_SCROLL);
- });
-
- $(window).on('beforeunload', function () {
- communicator.publish(Topics.GUEST_CHECKOUT);
- });
-
- loadCss(
- config.hostOrigin + crafter.join('/', config.studioContext, config.studioStaticAssets, 'styles', 'guest.css')
- );
-
- if (!$("link[href*='font-awesome']").length) {
- loadCss(
- config.hostOrigin +
- crafter.join(
- '/',
- config.studioContext,
- config.studioStaticAssets,
- 'themes',
- 'cstudioTheme',
- 'css',
- 'font-awesome.min.css'
- )
- );
- }
-
- setRegionsCookie();
- }
-
- function iceRepaint() {
- clearSetTimeout(Constants.TIME_RESIZE);
- }
-
- function initIceRegions_resizeIceRegions_handler(message) {
- if (!message) {
- iceToolsOn && !dndOn && initICERegions();
- } else {
- iceToolsOn = !!message.iceOn && !dndOn;
- if (
- // TODO: REFACTOR
- // !!(window.parent.sessionStorage.getItem('ice-on')) &&
- // window.parent.sessionStorage.getItem('components-on') != 'true'
- iceToolsOn
- ) {
- initICERegions();
- }
- }
- }
-
- function loadCss(url) {
- var link = document.createElement('link');
- link.type = 'text/css';
- link.rel = 'stylesheet';
- link.href = url;
- document.getElementsByTagName('head')[0].appendChild(link);
- }
-
- function setRegionsCookie() {
- var elts = document.querySelectorAll('[data-studio-ice]'),
- regions = [];
- if (elts.length > 0) {
- for (var i = 0; i <= elts.length - 1; i++) {
- regions.push({
- id: elts[i].getAttribute('data-studio-ice'),
- formId: elts[i].getAttribute('data-studio-ice'),
- label: elts[i].getAttribute('data-studio-ice-label')
- });
- }
- }
-
- communicator.publish(Topics.RESET_ICE_TOOLS_CONTENT, JSON.stringify(regions));
- }
-
- // Rendering of a single pencil based on an element
- function renderICESection(elem) {
- const $elem = $(elem),
- position = $elem.offset(),
- iceRef = $elem.data('studioIce') + '-' + count++;
-
- $elem.attr('data-studio-ice-target', iceRef);
-
- let flag = false;
- const compElement = $("[data-studio-ice-target='" + iceRef + "']");
- // if element exists -> set flag true to avoid re-rendering
- $('.studio-ice-indicator').each(function () {
- if ($(this).data('studioIceTrigger') == iceRef) {
- flag = true;
- }
- });
-
- if (!flag && compElement.is(':visible')) {
- const aux = $(
- crafter
- .String('')
- .fmt(iceRef)
- ).css({
- top: position.top,
- left: position.left
- });
- aux.appendTo('body');
- }
- }
-
- // Rendering of the pencils, no model involved at this moment
- function initICERegions() {
- removeICERegions();
- var elems = document.querySelectorAll('[data-studio-ice]');
-
- for (var i = 0; i < elems.length; ++i) {
- // Renders a single pencil based on the element's props.
- renderICESection(elems[i]);
-
- if (elems[i].getAttribute('data-studio-ice-label')) {
- elems[i].setAttribute(
- 'data-studio-ice-label',
- elems[i].getAttribute('data-studio-ice-label').replace(/ /g, '__')
- );
- }
- }
- }
-
- function removeICERegions() {
- if ($('.studio-ice-indicator').length > 0) {
- $('.studio-ice-indicator').remove();
- }
- }
-
- function repaintPencils() {
- if (iceToolsOn && !dndOn) {
- initICERegions();
- }
- }
-
- function initOverlay(elt) {
- var position = elt.offset(),
- width,
- height,
- boxSizing = window.getComputedStyle(elt[0], ':before').getPropertyValue('box-sizing');
-
- if (boxSizing == 'border-box') {
- width = elt.outerWidth();
- height = elt.outerHeight();
- } else {
- width = elt.width() - 4; // border-left-width + border-right-width = 4,
- height = elt.height() - 4; // border-top-width + border-bottom-width = 4
- }
-
- var props = {
- top: position.top,
- left: position.left,
- width: width,
- height: height
- };
-
- overlay.show(props);
- }
-
- function clearSetTimeout(time) {
- removeICERegions();
- clearTimeout(timeout);
- timeout = setTimeout(resizeProcess, time);
- }
-
- function resizeProcess() {
- // When window.top == window, communicator is not initialized
- communicator && communicator.publish(Topics.IS_REVIEWER, true);
- }
-
- function checkout(communicator) {
- communicator.publish('CHECK_OUT_GUEST', {
- url: window.location.href.replace(window.location.origin, '')
- });
- }
- }
-);
diff --git a/static-assets/scripts/host.js b/static-assets/scripts/host.js
deleted file mode 100644
index 0f8ecb749b..0000000000
--- a/static-assets/scripts/host.js
+++ /dev/null
@@ -1,758 +0,0 @@
-/*
- * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3 as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-(function ($, window, amplify, CStudioAuthoring) {
- 'use strict';
-
- if (!window.location.origin) {
- window.location.origin =
- window.location.protocol +
- '//' +
- window.location.hostname +
- (window.location.port ? ':' + window.location.port : '');
- }
-
- var cstopic = crafter.studio.preview.cstopic,
- Topics = crafter.studio.preview.Topics,
- previewAppBaseUri = CStudioAuthoringContext.previewAppBaseUri || window.location.origin,
- origin = previewAppBaseUri,
- communicator = new crafter.studio.Communicator(origin),
- previewWidth,
- hasCheckIn = false;
-
- communicator.subscribe(Topics.RESET_ICE_TOOLS_CONTENT, function (message) {
- sessionStorage.setItem('ice-tools-content', message);
- try {
- // For ICE tools panel syncing.
- window.initRegCookie();
- } catch (e) {}
- });
-
- communicator.subscribe(Topics.SET_SESSION_STORAGE_ITEM, function (message) {
- sessionStorage.setItem(message.key, message.value);
- });
-
- communicator.subscribe(Topics.REQUEST_SESSION_STORAGE_ITEM, function (key) {
- if (typeof key === 'string') {
- communicator.publish(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, {
- key: key,
- value: sessionStorage.getItem(key)
- });
- } else {
- // Expeting key to be an array here
- var values = {};
- for (var i = 0; i < key.length; i++) {
- values[i] = values[key[i]] = sessionStorage.getItem(key[i]);
- }
- communicator.publish(Topics.REQUEST_SESSION_STORAGE_ITEM_REPLY, values);
- }
- });
-
- communicator.subscribe(Topics.GUEST_CHECKIN, function (url) {
- var site = CStudioAuthoring.Utils.Cookies.readCookie('crafterSite');
- var params = { page: url, site };
- setHash(params);
- amplify.publish(cstopic('GUEST_CHECKIN'), params);
- });
-
- // Preview next check in message
- let previewNextCheckInNotification = false;
- let compatibilityQueryArg = CrafterCMSNext.util.path.getQueryVariable(window.location.search, 'compatibility');
- let compatibilityForceStay = compatibilityQueryArg === 'stay';
- let compatibilityAsk = compatibilityQueryArg === 'ask';
- communicator.subscribe(Topics.GUEST_CHECK_IN, function (data) {
- const doGo = () => {
- const state = CrafterCMSNext.system.store.getState();
- window.location.href = CrafterCMSNext.util.system.getSystemLink({
- authoringBase: state.env.authoringBase,
- systemLinkId: 'preview',
- page: data.location.pathname,
- site: state.sites.active
- });
- };
- const showCompatDialog = () => {
- let unmount;
- CrafterCMSNext.render(document.createElement('div'), 'PreviewCompatDialog', {
- isPreviewNext: true,
- onOk: doGo,
- onCancel() {
- unmount({ removeContainer: true });
- },
- onClosed() {
- unmount({ removeContainer: true });
- }
- }).then((args) => {
- unmount = args.unmount;
- });
- };
- if (!previewNextCheckInNotification && !compatibilityForceStay) {
- // Avoid recurrently showing the notification over and over as long as the page is not refreshed
- previewNextCheckInNotification = true;
- if (compatibilityAsk) {
- showCompatDialog();
- }
- }
- if (!compatibilityAsk && !compatibilityForceStay) {
- doGo();
- }
- communicator.addTargetWindow({
- origin: origin,
- window: getEngineWindow().contentWindow
- });
- communicator.dispatch({ type: Topics.LEGACY_CHECK_IN, payload: { editMode: false } });
- });
-
- communicator.subscribe(Topics.GUEST_CHECKOUT, function () {
- CStudioAuthoring.ContextualNav.WcmActiveContent?.disableNav(true);
- });
-
- // Opens studio form on pencil click
- communicator.subscribe(Topics.ICE_ZONE_ON, function (message, scope) {
- var isWrite = false;
- var par = [];
- var currentPath = message.itemId ? message.itemId : CStudioAuthoring.SelectedContent.getSelectedContent()[0].uri;
- var cachePermissionsKey = `${CStudioAuthoringContext.site}_${currentPath}_${CStudioAuthoringContext.user}_permissions`,
- isPermissionCached = cache.get(cachePermissionsKey),
- cacheContentKey =
- CStudioAuthoringContext.site + '_' + currentPath + '_' + CStudioAuthoringContext.user + '_content',
- isContentCached = cache.get(cacheContentKey);
-
- const openForm = function (path, readonly) {
- const site = CrafterCMSNext.system.store.getState().sites.active;
- const authoringBase = CrafterCMSNext.system.store.getState().env.authoringBase;
- const eventIdSuccess = 'editDialogSuccess';
- const eventIdDismissed = 'editDialogDismissed';
- let unsubscribe, cancelUnsubscribe;
-
- CrafterCMSNext.system.store.dispatch({
- type: 'SHOW_EDIT_DIALOG',
- payload: {
- site: site,
- path: path,
- type: 'form',
- authoringBase,
- readonly: readonly,
- isHidden: !!message.embeddedItemId,
- // TODO: ICE groups for embedded comments are not currently supported
- ...(message.embeddedItemId ? { modelId: message.embeddedItemId } : { iceGroupId: message.iceId }),
- onSaveSuccess: {
- type: 'BATCH_ACTIONS',
- payload: [
- {
- type: 'DISPATCH_DOM_EVENT',
- payload: { id: eventIdSuccess }
- },
- {
- type: 'SHOW_EDIT_ITEM_SUCCESS_NOTIFICATION'
- },
- {
- type: 'CLOSE_EDIT_DIALOG'
- }
- ]
- },
- onCancel: {
- type: 'BATCH_ACTIONS',
- payload: [
- {
- type: 'CLOSE_EDIT_DIALOG'
- },
- {
- type: 'DISPATCH_DOM_EVENT',
- payload: { id: eventIdDismissed }
- }
- ]
- }
- }
- });
-
- unsubscribe = CrafterCMSNext.createLegacyCallbackListener(eventIdSuccess, (response) => {
- const draft = response.action === 'save';
- if (CStudioAuthoringContext.isPreview || (!CStudioAuthoringContext.isPreview && !draft)) {
- eventNS.data = CStudioAuthoring.SelectedContent.getSelectedContent();
- eventNS.typeAction = '';
- document.dispatchEvent(eventNS);
- }
- cancelUnsubscribe();
- });
-
- cancelUnsubscribe = CrafterCMSNext.createLegacyCallbackListener(eventIdDismissed, () => {
- unsubscribe();
- });
- };
-
- var editPermsCallback = {
- success: function (response) {
- if (!isPermissionCached) {
- cache.set(cachePermissionsKey, response.permissions, CStudioAuthoring.Constants.CACHE_TIME_PERMISSION);
- }
- isWrite = CStudioAuthoring.Service.isWrite(response.permissions);
- if (!isWrite) {
- par.push({ name: 'readonly' });
- }
-
- if (!message.itemId) {
- // base page edit
- const readonly =
- isWrite === false ||
- (CStudioAuthoring.SelectedContent.getSelectedContent()[0].lockOwner !== '' &&
- CStudioAuthoring.SelectedContent.getSelectedContent()[0].lockOwner !== null &&
- CStudioAuthoringContext.user !== CStudioAuthoring.SelectedContent.getSelectedContent()[0].lockOwner);
-
- openForm(CStudioAuthoring.SelectedContent.getSelectedContent()[0].uri, readonly);
- } else {
- var getContentItemsCb = {
- success: function (contentTO) {
- if (!isContentCached) {
- cache.set(cacheContentKey, contentTO.item, CStudioAuthoring.Constants.CACHE_TIME_GET_CONTENT_ITEM);
- }
- const readonly =
- isWrite === false ||
- (contentTO.item.lockOwner !== '' &&
- contentTO.item.lockOwner !== null &&
- CStudioAuthoringContext.user !== contentTO.item.lockOwner);
-
- openForm(contentTO.item.uri, readonly);
- },
- failure: function () {
- callback.failure();
- }
- };
-
- if (isContentCached) {
- var contentTO = {};
- contentTO.item = isContentCached;
- getContentItemsCb.success(contentTO);
- } else {
- CStudioAuthoring.Service.lookupContentItem(
- CStudioAuthoringContext.site,
- message.itemId,
- getContentItemsCb,
- false,
- false
- );
- }
- }
- },
- failure: function () {}
- };
-
- if (isPermissionCached) {
- var response = {};
- response.permissions = isPermissionCached;
- editPermsCallback.success(response);
- } else {
- CStudioAuthoring.Service.getUserPermissions(CStudioAuthoringContext.site, currentPath, editPermsCallback);
- }
- });
-
- // Listen to the guest site load
- communicator.subscribe(Topics.GUEST_SITE_LOAD, function (message, scope) {
- hasCheckIn = true;
-
- if (message.url) {
- var params = {
- page: message.url,
- site: CStudioAuthoring.Utils.Cookies.readCookie('crafterSite')
- };
-
- var studioPath = CrafterCMSNext.util.path.getPathFromPreviewURL(message.url);
-
- setHash(params);
- amplify.publish(cstopic('GUEST_SITE_LOAD'), params);
-
- selectStudioContent(params.site, studioPath);
- }
-
- // Once the guest window notifies that the page as successfully loaded,
- // add the guest window as a target of messages sent by this window
- communicator.addTargetWindow({
- origin: origin,
- window: getEngineWindow().contentWindow
- });
- });
-
- communicator.subscribe(Topics.GUEST_SITE_URL_CHANGE, function (message, scope) {
- if (message.url) {
- var site = CStudioAuthoring.Utils.Cookies.readCookie('crafterSite'),
- studioPath = CStudioAuthoring.ComponentsPanel.getPreviewPagePath(message.url);
- selectStudioContent(site, studioPath);
-
- setHash({ page: message.url, site });
- CStudioAuthoring.ComponentsPanel.getPageModel(studioPath, 'init-components', true, false);
-
- communicator.publish(Topics.DND_PANEL_OFF);
- }
- });
-
- communicator.subscribe(Topics.STOP_DRAG_AND_DROP, function () {
- expandContractChannel();
- CStudioAuthoring.PreviewTools.panel.element.style.visibility = 'visible';
- $(CStudioAuthoring.PreviewTools.panel.element).show('slow', function () {
- if (!previewWidth || previewWidth == 0 || previewWidth == '0px') {
- previewWidth = 265;
- }
- $('.studio-preview').css('right', previewWidth);
- YDom.replaceClass('component-panel-elem', 'expanded', 'contracted');
- });
- });
-
- amplify.subscribe(cstopic('DND_COMPONENTS_PANEL_OFF'), function (config) {
- sessionStorage.setItem('pto-on', '');
- var el = YDom.get('acn-preview-tools-container');
- YDom.removeClass(el.children[0], 'icon-light-blue');
- YDom.addClass(el.children[0], 'icon-default');
- communicator.publish(Topics.DND_COMPONENTS_PANEL_OFF, {});
- });
-
- amplify.subscribe(cstopic('DND_COMPONENTS_PANEL_ON'), function (config) {
- sessionStorage.setItem('pto-on', 'on');
- var el = YDom.get('acn-preview-tools-container');
- YDom.removeClass(el.children[0], 'icon-default');
- YDom.addClass(el.children[0], 'icon-light-blue');
- amplify.publish(cstopic('START_DRAG_AND_DROP'), {
- components: config.components
- });
- });
-
- communicator.subscribe(Topics.COMPONENT_DROPPED, function (message) {
- message.model = initialContentModel;
- amplify.publish(
- cstopic('COMPONENT_DROPPED'),
- message.type,
- message.path,
- message.isNew,
- message.trackingNumber,
- message.zones,
- message.compPath,
- message.conComp,
- message.model,
- message.datasource
- );
- });
-
- communicator.subscribe(Topics.START_DIALOG, function (message) {
- var newdiv = document.createElement('div');
- var text;
- var link = '';
-
- if (message.messageKey) {
- text = CrafterCMSNext.i18n.intl.formatMessage(
- CrafterCMSNext.i18n.messages.dragAndDropMessages[message.messageKey]
- );
- } else {
- text = message.message;
- }
- if (message.link) {
- link = message.link;
- }
-
- newdiv.setAttribute('id', 'cstudio-wcm-popup-div');
- newdiv.className = 'yui-pe-content';
- newdiv.innerHTML =
- '