diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index 497393f..5161a4a 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -3,7 +3,7 @@ * CKEditor implementation of {@link Drupal.editors} API. */ -(function (Drupal, debounce, CKEDITOR, $) { +(function (Drupal, debounce, CKEDITOR, $, displace) { 'use strict'; @@ -85,6 +85,22 @@ editor.on('change', debounce(function () { callback(editor.getData()); }, 400)); + + // A temporary workaround to control scrollbar appearance when using + // autoGrow event to control editor's height. + // @see https://www.drupal.org/node/2239419#comment-10857626 + // @todo Remove at CKEditor version 4.6.0. + editor.on('autoGrow', function( evt ) { + var doc = evt.editor.document, + scrollable = CKEDITOR.env.quirks ? doc.getBody() : doc.getDocumentElement(); + + if ( scrollable.$.scrollHeight < scrollable.$.clientHeight ) { + scrollable.setStyle( 'overflow-y', 'hidden' ); + } + else { + scrollable.removeStyle( 'overflow-y' ); + } + }, null, null, 10000 ); } return !!editor; }, @@ -273,7 +289,13 @@ } }); + // Formulate a default formula for the maximum autoGrow height. + $(window).on('load', function () { + displace(); + CKEDITOR.config.autoGrow_maxHeight = 0.7 * (window.innerHeight - displace.offsets.top - displace.offsets.bottom); + }); + // Set the CKEditor cache-busting string to the same value as Drupal. CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp; -})(Drupal, Drupal.debounce, CKEDITOR, jQuery); +})(Drupal, Drupal.debounce, CKEDITOR, jQuery, Drupal.displace);