Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / ckeditor / js / ckeditor.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function (Drupal, debounce, CKEDITOR, $, displace, AjaxCommands) {
9   Drupal.editors.ckeditor = {
10     attach: function attach(element, format) {
11       this._loadExternalPlugins(format);
12
13       format.editorSettings.drupal = {
14         format: format.format
15       };
16
17       var label = $('label[for=' + element.getAttribute('id') + ']').html();
18       format.editorSettings.title = Drupal.t('Rich Text Editor, !label field', {
19         '!label': label
20       });
21
22       return !!CKEDITOR.replace(element, format.editorSettings);
23     },
24     detach: function detach(element, format, trigger) {
25       var editor = CKEDITOR.dom.element.get(element).getEditor();
26       if (editor) {
27         if (trigger === 'serialize') {
28           editor.updateElement();
29         } else {
30           editor.destroy();
31           element.removeAttribute('contentEditable');
32         }
33       }
34       return !!editor;
35     },
36     onChange: function onChange(element, callback) {
37       var editor = CKEDITOR.dom.element.get(element).getEditor();
38       if (editor) {
39         editor.on('change', debounce(function () {
40           callback(editor.getData());
41         }, 400));
42
43         editor.on('mode', function () {
44           var editable = editor.editable();
45           if (!editable.isInline()) {
46             editor.on('autoGrow', function (evt) {
47               var doc = evt.editor.document;
48               var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
49
50               if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
51                 scrollable.setStyle('overflow-y', 'hidden');
52               } else {
53                 scrollable.removeStyle('overflow-y');
54               }
55             }, null, null, 10000);
56           }
57         });
58       }
59       return !!editor;
60     },
61     attachInlineEditor: function attachInlineEditor(element, format, mainToolbarId, floatedToolbarId) {
62       this._loadExternalPlugins(format);
63
64       format.editorSettings.drupal = {
65         format: format.format
66       };
67
68       var settings = $.extend(true, {}, format.editorSettings);
69
70       if (mainToolbarId) {
71         var settingsOverride = {
72           extraPlugins: 'sharedspace',
73           removePlugins: 'floatingspace,elementspath',
74           sharedSpaces: {
75             top: mainToolbarId
76           }
77         };
78
79         var sourceButtonFound = false;
80         for (var i = 0; !sourceButtonFound && i < settings.toolbar.length; i++) {
81           if (settings.toolbar[i] !== '/') {
82             for (var j = 0; !sourceButtonFound && j < settings.toolbar[i].items.length; j++) {
83               if (settings.toolbar[i].items[j] === 'Source') {
84                 sourceButtonFound = true;
85
86                 settings.toolbar[i].items[j] = 'Sourcedialog';
87                 settingsOverride.extraPlugins += ',sourcedialog';
88                 settingsOverride.removePlugins += ',sourcearea';
89               }
90             }
91           }
92         }
93
94         settings.extraPlugins += ',' + settingsOverride.extraPlugins;
95         settings.removePlugins += ',' + settingsOverride.removePlugins;
96         settings.sharedSpaces = settingsOverride.sharedSpaces;
97       }
98
99       element.setAttribute('contentEditable', 'true');
100
101       return !!CKEDITOR.inline(element, settings);
102     },
103     _loadExternalPlugins: function _loadExternalPlugins(format) {
104       var externalPlugins = format.editorSettings.drupalExternalPlugins;
105
106       if (externalPlugins) {
107         Object.keys(externalPlugins || {}).forEach(function (pluginName) {
108           CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], '');
109         });
110         delete format.editorSettings.drupalExternalPlugins;
111       }
112     }
113   };
114
115   Drupal.ckeditor = {
116     saveCallback: null,
117
118     openDialog: function openDialog(editor, url, existingValues, saveCallback, dialogSettings) {
119       var $target = $(editor.container.$);
120       if (editor.elementMode === CKEDITOR.ELEMENT_MODE_REPLACE) {
121         $target = $target.find('.cke_contents');
122       }
123
124       $target.css('position', 'relative').find('.ckeditor-dialog-loading').remove();
125
126       var classes = dialogSettings.dialogClass ? dialogSettings.dialogClass.split(' ') : [];
127       classes.push('ui-dialog--narrow');
128       dialogSettings.dialogClass = classes.join(' ');
129       dialogSettings.autoResize = window.matchMedia('(min-width: 600px)').matches;
130       dialogSettings.width = 'auto';
131
132       var $content = $('<div class="ckeditor-dialog-loading"><span style="top: -40px;" class="ckeditor-dialog-loading-link">' + Drupal.t('Loading...') + '</span></div>');
133       $content.appendTo($target);
134
135       var ckeditorAjaxDialog = Drupal.ajax({
136         dialog: dialogSettings,
137         dialogType: 'modal',
138         selector: '.ckeditor-dialog-loading-link',
139         url: url,
140         progress: { type: 'throbber' },
141         submit: {
142           editor_object: existingValues
143         }
144       });
145       ckeditorAjaxDialog.execute();
146
147       window.setTimeout(function () {
148         $content.find('span').animate({ top: '0px' });
149       }, 1000);
150
151       Drupal.ckeditor.saveCallback = saveCallback;
152     }
153   };
154
155   $(window).on('dialogcreate', function (e, dialog, $element, settings) {
156     $('.ui-dialog--narrow').css('zIndex', CKEDITOR.config.baseFloatZIndex + 1);
157   });
158
159   $(window).on('dialog:beforecreate', function (e, dialog, $element, settings) {
160     $('.ckeditor-dialog-loading').animate({ top: '-40px' }, function () {
161       $(this).remove();
162     });
163   });
164
165   $(window).on('editor:dialogsave', function (e, values) {
166     if (Drupal.ckeditor.saveCallback) {
167       Drupal.ckeditor.saveCallback(values);
168     }
169   });
170
171   $(window).on('dialog:afterclose', function (e, dialog, $element) {
172     if (Drupal.ckeditor.saveCallback) {
173       Drupal.ckeditor.saveCallback = null;
174     }
175   });
176
177   $(document).on('drupalViewportOffsetChange', function () {
178     CKEDITOR.config.autoGrow_maxHeight = 0.7 * (window.innerHeight - displace.offsets.top - displace.offsets.bottom);
179   });
180
181   function redirectTextareaFragmentToCKEditorInstance() {
182     var hash = window.location.hash.substr(1);
183     var element = document.getElementById(hash);
184     if (element) {
185       var editor = CKEDITOR.dom.element.get(element).getEditor();
186       if (editor) {
187         var id = editor.container.getAttribute('id');
188         window.location.replace('#' + id);
189       }
190     }
191   }
192   $(window).on('hashchange.ckeditor', redirectTextareaFragmentToCKEditorInstance);
193
194   CKEDITOR.config.autoGrow_onStartup = true;
195
196   CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp;
197
198   if (AjaxCommands) {
199     AjaxCommands.prototype.ckeditor_add_stylesheet = function (ajax, response, status) {
200       var editor = CKEDITOR.instances[response.editor_id];
201
202       if (editor) {
203         response.stylesheets.forEach(function (url) {
204           editor.document.appendStyleSheet(url);
205         });
206       }
207     };
208   }
209 })(Drupal, Drupal.debounce, CKEDITOR, jQuery, Drupal.displace, Drupal.AjaxCommands);