|
58 | 58 | editors: {}, |
59 | 59 |
|
60 | 60 |
|
61 | | - init: function (element, mode, options, settings, callback) { |
| 61 | + init: function (element, mode, options, settings, callback) { // eslint-disable-line max-params |
62 | 62 | var container = $(element); |
63 | 63 |
|
64 | 64 | container.data('ckeditor-initialized', true); |
|
86 | 86 | '/ckeditor_plugins/cmsplugins/icons/cmsplugins.svg'); |
87 | 87 |
|
88 | 88 | var editor; |
| 89 | + |
89 | 90 | if (mode === 'admin') { |
90 | 91 | // render ckeditor |
91 | 92 | editor = CKEDITOR.replace(container[0], this.options); |
|
110 | 111 | return; |
111 | 112 | } |
112 | 113 |
|
113 | | - CMS.CKEditor.observer = CMS.CKEditor.observer || new IntersectionObserver(function (entries, opts) { |
| 114 | + CMS.CKEditor.observer = CMS.CKEditor.observer || new IntersectionObserver(function (entries) { |
114 | 115 | entries.forEach(function (entry) { |
115 | 116 | if (entry.isIntersecting) { |
116 | 117 | var target = $(entry.target); |
117 | 118 | var plugin_id = target.data('cms_plugin_id'); |
118 | 119 | var url = target.data('cms_edit_url'); |
119 | 120 |
|
120 | 121 | CMS.CKEditor.startInlineEditor(plugin_id, url); |
| 122 | + CMS.CKEditor.observer.unobserve(entry.target); // initialized; no more events needed |
121 | 123 | } |
122 | 124 | }); |
123 | 125 | }, { |
124 | 126 | root: null, |
125 | 127 | threshold: 0.05 |
126 | 128 | }); |
127 | 129 |
|
| 130 | + // disconnect first -- each visible element needs to trigger an event |
| 131 | + CMS.CKEditor.observer.disconnect(); |
| 132 | + |
128 | 133 | CMS._plugins.forEach(function (plugin) { |
129 | 134 | if (plugin[1].plugin_type === 'TextPlugin') { |
130 | 135 | var url = plugin[1].urls.edit_plugin; |
|
142 | 147 | elements |
143 | 148 | .removeClass('cms-plugin') |
144 | 149 | .removeClass('cms-plugin-' + id); |
145 | | - wrapper.addClass('cms-plugin').addClass('cms-plugin-' + id); |
| 150 | + wrapper.addClass('cms-plugin').addClass('cms-plugin-' + id) |
| 151 | + .addClass('cms-plugin-start').addClass('cms-plugin-end'); |
146 | 152 | } |
147 | 153 | wrapper.data('cms_edit_url', url); |
148 | 154 | wrapper.data('cms_plugin_id', id); |
|
176 | 182 | var settings = JSON.parse(document.getElementById('ck-cfg-' + plugin_id).textContent); |
177 | 183 | var wrapper = $('.cms-plugin.cms-plugin-' + plugin_id); |
178 | 184 |
|
179 | | - if (wrapper.data('ckeditor-initialized')) { |
180 | | - return; |
181 | | - } |
182 | | - |
183 | 185 | settings.plugin_id = plugin_id; |
184 | 186 | settings.url = url; |
185 | 187 | options = settings.options; |
|
465 | 467 | }); |
466 | 468 | setTimeout(function () { |
467 | 469 | CMS.Plugin._highlightPluginStructure(draggable.find('.cms-dragitem:first'), |
468 | | - {successTimeout: 200, delay: 2000, seeThrough: true}); |
| 470 | + { successTimeout: 200, delay: 2000, seeThrough: true }); |
469 | 471 | }, HIGHLIGHT_TIMEOUT); |
470 | 472 | } |
471 | 473 | }, |
472 | 474 |
|
473 | 475 | _initAll: function () { |
474 | 476 | CMS.CKEditor.touchdevice = 'ontouchstart' in window || navigator.msMaxTouchPoints; // on touch device? |
475 | | - if (!CMS.CKEditor.touchdevice) { // no inline editing on touch devices to not interfere with scrolling |
| 477 | + if (CMS.CKEditor.touchdevice) { // no inline editing on touch devices to not interfere with scrolling |
| 478 | + $('div.cms a.cms-btn.cms-edit-toggle').hide(); |
| 479 | + } else { |
476 | 480 | CMS.CKEditor.initInlineEditors(); |
477 | 481 | $('div.cms a.cms-btn.cms-edit-toggle').show(); |
478 | | - } else { |
479 | | - $('div.cms a.cms-btn.cms-edit-toggle').hide(); |
480 | 482 | } |
481 | 483 | CMS.CKEditor.initAdminEditors(); |
482 | 484 | }, |
|
0 commit comments