Security update for Core, with self-updated composer
[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', { '!label': label });
19
20       return !!CKEDITOR.replace(element, format.editorSettings);
21     },
22     detach: function detach(element, format, trigger) {
23       var editor = CKEDITOR.dom.element.get(element).getEditor();
24       if (editor) {
25         if (trigger === 'serialize') {
26           editor.updateElement();
27         } else {
28           editor.destroy();
29           element.removeAttribute('contentEditable');
30         }
31       }
32       return !!editor;
33     },
34     onChange: function onChange(element, callback) {
35       var editor = CKEDITOR.dom.element.get(element).getEditor();
36       if (editor) {
37         editor.on('change', debounce(function () {
38           callback(editor.getData());
39         }, 400));
40
41         editor.on('mode', function () {
42           var editable = editor.editable();
43           if (!editable.isInline()) {
44             editor.on('autoGrow', function (evt) {
45               var doc = evt.editor.document;
46               var scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement();
47
48               if (scrollable.$.scrollHeight < scrollable.$.clientHeight) {
49                 scrollable.setStyle('overflow-y', 'hidden');
50               } else {
51                 scrollable.removeStyle('overflow-y');
52               }
53             }, null, null, 10000);
54           }
55         });
56       }
57       return !!editor;
58     },
59     attachInlineEditor: function attachInlineEditor(element, format, mainToolbarId, floatedToolbarId) {
60       this._loadExternalPlugins(format);
61
62       format.editorSettings.drupal = {
63         format: format.format
64       };
65
66       var settings = $.extend(true, {}, format.editorSettings);
67
68       if (mainToolbarId) {
69         var settingsOverride = {
70           extraPlugins: 'sharedspace',
71           removePlugins: 'floatingspace,elementspath',
72           sharedSpaces: {
73             top: mainToolbarId
74           }
75         };
76
77         var sourceButtonFound = false;
78         for (var i = 0; !sourceButtonFound && i < settings.toolbar.length; i++) {
79           if (settings.toolbar[i] !== '/') {
80             for (var j = 0; !sourceButtonFound && j < settings.toolbar[i].items.length; j++) {
81               if (settings.toolbar[i].items[j] === 'Source') {
82                 sourceButtonFound = true;
83
84                 settings.toolbar[i].items[j] = 'Sourcedialog';
85                 settingsOverride.extraPlugins += ',sourcedialog';
86                 settingsOverride.removePlugins += ',sourcearea';
87               }
88             }
89           }
90         }
91
92         settings.extraPlugins += ',' + settingsOverride.extraPlugins;
93         settings.removePlugins += ',' + settingsOverride.removePlugins;
94         settings.sharedSpaces = settingsOverride.sharedSpaces;
95       }
96
97       element.setAttribute('contentEditable', 'true');
98
99       return !!CKEDITOR.inline(element, settings);
100     },
101     _loadExternalPlugins: function _loadExternalPlugins(format) {
102       var externalPlugins = format.editorSettings.drupalExternalPlugins;
103
104       if (externalPlugins) {
105         for (var pluginName in externalPlugins) {
106           if (externalPlugins.hasOwnProperty(pluginName)) {
107             CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], '');
108           }
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 = 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         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);