PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.0-dev4
Elementor Website Builder – more than just a page builder v3.35.0-dev4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / assets / js / gutenberg.js

gutenberg.js in Elementor Website Builder – more than just a page builder 3.35.0-dev4, at assets/js/gutenberg.js

197 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ var __webpack_modules__ = ({
4
5 /***/ "@wordpress/i18n":
6 /*!**************************!*\
7 !*** external "wp.i18n" ***!
8 \**************************/
9 /***/ ((module) => {
10
11 module.exports = wp.i18n;
12
13 /***/ })
14
15 /******/ });
16 /************************************************************************/
17 /******/ // The module cache
18 /******/ var __webpack_module_cache__ = {};
19 /******/
20 /******/ // The require function
21 /******/ function __webpack_require__(moduleId) {
22 /******/ // Check if module is in cache
23 /******/ var cachedModule = __webpack_module_cache__[moduleId];
24 /******/ if (cachedModule !== undefined) {
25 /******/ return cachedModule.exports;
26 /******/ }
27 /******/ // Create a new module (and put it into the cache)
28 /******/ var module = __webpack_module_cache__[moduleId] = {
29 /******/ // no module.id needed
30 /******/ // no module.loaded needed
31 /******/ exports: {}
32 /******/ };
33 /******/
34 /******/ // Execute the module function
35 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
36 /******/
37 /******/ // Return the exports of the module
38 /******/ return module.exports;
39 /******/ }
40 /******/
41 /************************************************************************/
42 // This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
43 (() => {
44 /*!*******************************************!*\
45 !*** ../assets/dev/js/admin/gutenberg.js ***!
46 \*******************************************/
47 /* provided dependency */ var __ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n")["__"];
48
49
50 /* global ElementorGutenbergSettings */
51 (function ($) {
52 'use strict';
53
54 var ElementorGutenbergApp = {
55 cacheElements: function cacheElements() {
56 var self = this;
57 self.isElementorMode = ElementorGutenbergSettings.isElementorMode;
58 self.cache = {};
59 self.cache.$gutenberg = $('#editor');
60 self.cache.$switchMode = $($('#elementor-gutenberg-button-switch-mode').html());
61 self.cache.$switchModeButton = self.cache.$switchMode.find('#elementor-switch-mode-button');
62 self.bindEvents();
63 self.toggleStatus();
64 wp.data.subscribe(function () {
65 setTimeout(function () {
66 self.buildPanel();
67 }, 1);
68 });
69 },
70 buildPanel: function buildPanel() {
71 var self = this;
72 if (!self.cache.$gutenberg.find('#elementor-switch-mode').length) {
73 self.cache.$gutenberg.find('.edit-post-header-toolbar').append(self.cache.$switchMode);
74 }
75 if (this.hasIframe()) {
76 this.handleIframe();
77 }
78 if (!$('#elementor-editor').length) {
79 self.cache.$editorPanel = $($('#elementor-gutenberg-panel').html());
80 var editorButtonParent = self.cache.$gutenberg.find('.block-editor-writing-flow');
81 if (!editorButtonParent.length) {
82 editorButtonParent = self.cache.$gutenberg.find('.is-desktop-preview');
83 }
84 self.cache.$gurenbergBlockList = editorButtonParent;
85 self.cache.$gurenbergBlockList.append(self.cache.$editorPanel);
86 self.cache.$editorPanelButton = self.cache.$editorPanel.find('#elementor-go-to-edit-page-link');
87 self.cache.$editorPanelButton.on('click', function (event) {
88 event.preventDefault();
89 self.handleEditButtonClick();
90 });
91 }
92 },
93 handleIframe: function handleIframe() {
94 this.hideIframeContent();
95 this.buildPanelTopBar();
96 },
97 // Sometimes Gutenberg uses iframe instead of div.
98 hasIframe: function hasIframe() {
99 return !!this.cache.$gutenberg.find('iframe[name="editor-canvas"]').length;
100 },
101 hideIframeContent: function hideIframeContent() {
102 if (!this.isElementorMode) {
103 return;
104 }
105 var style = "<style>\n\t\t\t\t.editor-post-text-editor,\n\t\t\t\t.block-editor-block-list__layout {\n\t\t\t\t\tdisplay: none;\n\t\t\t\t}\n\n\t\t\t\tbody {\n\t\t\t\t\tpadding: 0 !important;\n\t\t\t\t}\n\t\t\t</style>";
106 this.cache.$gutenberg.find('iframe[name="editor-canvas"]').contents().find('body').append(style);
107 },
108 buildPanelTopBar: function buildPanelTopBar() {
109 var self = this;
110 if (!$('#elementor-edit-mode-button').length && this.isElementorMode) {
111 self.cache.$editorBtnTop = $($('#elementor-gutenberg-button-tmpl').html());
112 self.cache.$gutenberg.find('.edit-post-header-toolbar').append(self.cache.$editorBtnTop);
113 $('#elementor-edit-mode-button').on('click', function (event) {
114 event.preventDefault();
115 self.handleEditButtonClick(false);
116 });
117 }
118 },
119 handleEditButtonClick: function handleEditButtonClick() {
120 var withAnimation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
121 var self = this;
122 if (withAnimation) {
123 self.animateLoader();
124 }
125
126 // A new post is initialized as an 'auto-draft'.
127 // if the post is not a new post it should not save it to avoid some saving conflict between elementor and gutenberg.
128 var isNewPost = 'auto-draft' === wp.data.select('core/editor').getCurrentPost().status;
129 if (isNewPost) {
130 var documentTitle = wp.data.select('core/editor').getEditedPostAttribute('title');
131 if (!documentTitle) {
132 wp.data.dispatch('core/editor').editPost({
133 title: 'Elementor #' + $('#post_ID').val()
134 });
135 }
136 wp.data.dispatch('core/editor').savePost();
137 }
138 self.redirectWhenSave();
139 },
140 bindEvents: function bindEvents() {
141 var self = this;
142 self.cache.$switchModeButton.on('click', function () {
143 if (self.isElementorMode) {
144 elementorCommon.dialogsManager.createWidget('confirm', {
145 message: __('Please note that you are switching to WordPress default editor. Your current layout, design and content might break.', 'elementor'),
146 headerMessage: __('Back to WordPress Editor', 'elementor'),
147 strings: {
148 confirm: __('Continue', 'elementor'),
149 cancel: __('Cancel', 'elementor')
150 },
151 defaultOption: 'confirm',
152 onConfirm: function onConfirm() {
153 var wpEditor = wp.data.dispatch('core/editor');
154 wpEditor.editPost({
155 gutenberg_elementor_mode: false
156 });
157 wpEditor.savePost();
158 self.isElementorMode = !self.isElementorMode;
159 self.toggleStatus();
160 }
161 }).show();
162 } else {
163 self.isElementorMode = !self.isElementorMode;
164 self.toggleStatus();
165 self.cache.$editorPanelButton.trigger('click');
166 }
167 });
168 },
169 redirectWhenSave: function redirectWhenSave() {
170 var self = this;
171 setTimeout(function () {
172 if (wp.data.select('core/editor').isSavingPost()) {
173 self.redirectWhenSave();
174 } else {
175 location.href = ElementorGutenbergSettings.editLink;
176 }
177 }, 300);
178 },
179 animateLoader: function animateLoader() {
180 this.cache.$editorPanelButton.addClass('elementor-animate');
181 },
182 toggleStatus: function toggleStatus() {
183 jQuery('body').toggleClass('elementor-editor-active', this.isElementorMode).toggleClass('elementor-editor-inactive', !this.isElementorMode);
184 },
185 init: function init() {
186 this.cacheElements();
187 }
188 };
189 $(function () {
190 ElementorGutenbergApp.init();
191 });
192 })(jQuery);
193 })();
194
195 /******/ })()
196 ;
197 //# sourceMappingURL=gutenberg.js.map