Commit bcc5f4d5 authored by Fathima Nazeeha Asmat's avatar Fathima Nazeeha Asmat Committed by Mike Decker
Browse files

Issue #3300734 by fathima.asmat: Drupal 10 compatibility

parent 756aa08b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -5,14 +5,13 @@ ace-editor:
    name: Ace Editor
    url: https://ace.c9.io
  js:
    //pagecdn.io/lib/ace/1.4.8/ace.js: { type: external, minified: true }
    //cdnjs.cloudflare.com/ajax/libs/ace/1.8.1/ace.min.js: { type: external, minified: true }
    js/asset_injector.ace_editor.js: {}
  css:
    base:
      css/asset_injector.css: {}
  dependencies:
      - core/jquery.ui.resizable
      - core/jquery.once
      - core/once

asset_injector:
  version: VERSION
+3 −13
Original line number Diff line number Diff line
body.ace-editor .resizable.ui-resizable {
  height: 200px;
  padding: 5px;
  position: relative;
  border: 1px solid #a9a9a9;
}

body.ace-editor .ace-editor {
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
body.ace-editor-added .ace-editor {
  min-height: calc(100vh - 200px);
  border: 2px solid #ccc;
}
+10 −12
Original line number Diff line number Diff line
@@ -3,15 +3,15 @@
 * Asset Injector applies Ace Editor to simplify work.
 */

(function ($, Drupal) {
(function ($, Drupal, once) {
  'use strict';
  Drupal.behaviors.assetInjector = {
    attach: function (context, settings) {
      if (typeof ace == 'undefined' || typeof ace.edit != 'function') {
        return;
      }
      $('body').addClass('ace-editor');
      $('.ace-editor').once('ace-editor-added').each(function () {
      $('body').addClass('ace-editor-added');
      $(once('ace-editor-added', '.ace-editor')).each(function () {
        var textarea = $(this).parent().siblings().find('textarea');
        var mode = $(textarea).attr('data-ace-mode');

@@ -22,30 +22,28 @@
            .css('opacity', 0)
            .attr('tabindex', -1);

          ace.config.set('basePath', '//cdnjs.cloudflare.com/ajax/libs/ace/1.8.1');
          ace.config.set('modePath', '//cdnjs.cloudflare.com/ajax/libs/ace/1.8.1');
          ace.config.set('themePath', '//cdnjs.cloudflare.com/ajax/libs/ace/1.8.1');

          var editor = ace.edit(this);
          editor.getSession().setMode('ace/mode/' + mode);
          editor.getSession().setTabSize(2);
          editor.getSession().setUseSoftTabs();

          editor.getSession().on('change', function () {
            textarea.val(editor.getSession().getValue());
          });

          $('.resizable').resizable({
            resize: function (event, ui) {
              editor.resize();
            }
          });

          editor.setValue(textarea.val());
          editor.resize();

          // When the form fails to validate because the text area is required,
          // shift the focus to the editor.
          textarea.on('focus', function () {
            editor.textInput.focus()
            editor.focus()
          })
        }
      });
    }
  };
})(jQuery, Drupal);
})(jQuery, Drupal, once);
+3 −4
Original line number Diff line number Diff line
@@ -105,10 +105,9 @@ abstract class AssetInjectorBase extends ConfigEntityBase implements AssetInject
   *   File path relative to drupal root, with leading slash.
   */
  protected function filePathRelativeToDrupalRoot() {
    // @todo See if we can simplify this via file_url_transform_relative().
    $path = parse_url(file_create_url($this->internalFileUri()), PHP_URL_PATH);
    $path = str_replace(base_path(), '/', $path);
    return $path;
    $path = \Drupal::service('file_url_generator')
      ->generateAbsoluteString($this->internalFileUri());
    return str_replace(base_path(), '/', parse_url($path, PHP_URL_PATH));
  }

  /**
+2 −1
Original line number Diff line number Diff line
@@ -82,7 +82,8 @@ class AssetInjectorCssTest extends BrowserTestBase {
    $this->getSession()->getPage()->hasContent('asset_injector/css/blocks');
    /** @var \Drupal\asset_injector\Entity\AssetInjectorCss $asset */
    foreach (asset_injector_get_assets(NULL, ['asset_injector_css']) as $asset) {
      $path = parse_url(file_create_url($asset->internalFileUri()), PHP_URL_PATH);
      $path = parse_url(\Drupal::service('file_url_generator')
        ->generateAbsoluteString($asset->internalFileUri()), PHP_URL_PATH);
      $path = str_replace(base_path(), '/', $path);

      $this->drupalGet($path);
Loading