[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/plg_editors_codemirror/js/ -> joomla-editor-codemirror-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
   5      try {
   6        var info = gen[key](arg);
   7        var value = info.value;
   8      } catch (error) {
   9        reject(error);
  10        return;
  11      }
  12  
  13      if (info.done) {
  14        resolve(value);
  15      } else {
  16        Promise.resolve(value).then(_next, _throw);
  17      }
  18    }
  19  
  20    function _asyncToGenerator(fn) {
  21      return function () {
  22        var self = this,
  23            args = arguments;
  24        return new Promise(function (resolve, reject) {
  25          var gen = fn.apply(self, args);
  26  
  27          function _next(value) {
  28            asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  29          }
  30  
  31          function _throw(err) {
  32            asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  33          }
  34  
  35          _next(undefined);
  36        });
  37      };
  38    }
  39  
  40    function _defineProperties(target, props) {
  41      for (var i = 0; i < props.length; i++) {
  42        var descriptor = props[i];
  43        descriptor.enumerable = descriptor.enumerable || false;
  44        descriptor.configurable = true;
  45        if ("value" in descriptor) descriptor.writable = true;
  46        Object.defineProperty(target, descriptor.key, descriptor);
  47      }
  48    }
  49  
  50    function _createClass(Constructor, protoProps, staticProps) {
  51      if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  52      if (staticProps) _defineProperties(Constructor, staticProps);
  53      Object.defineProperty(Constructor, "prototype", {
  54        writable: false
  55      });
  56      return Constructor;
  57    }
  58  
  59    function _inheritsLoose(subClass, superClass) {
  60      subClass.prototype = Object.create(superClass.prototype);
  61      subClass.prototype.constructor = subClass;
  62  
  63      _setPrototypeOf(subClass, superClass);
  64    }
  65  
  66    function _getPrototypeOf(o) {
  67      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  68        return o.__proto__ || Object.getPrototypeOf(o);
  69      };
  70      return _getPrototypeOf(o);
  71    }
  72  
  73    function _setPrototypeOf(o, p) {
  74      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  75        o.__proto__ = p;
  76        return o;
  77      };
  78  
  79      return _setPrototypeOf(o, p);
  80    }
  81  
  82    function _isNativeReflectConstruct() {
  83      if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  84      if (Reflect.construct.sham) return false;
  85      if (typeof Proxy === "function") return true;
  86  
  87      try {
  88        Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  89        return true;
  90      } catch (e) {
  91        return false;
  92      }
  93    }
  94  
  95    function _construct(Parent, args, Class) {
  96      if (_isNativeReflectConstruct()) {
  97        _construct = Reflect.construct;
  98      } else {
  99        _construct = function _construct(Parent, args, Class) {
 100          var a = [null];
 101          a.push.apply(a, args);
 102          var Constructor = Function.bind.apply(Parent, a);
 103          var instance = new Constructor();
 104          if (Class) _setPrototypeOf(instance, Class.prototype);
 105          return instance;
 106        };
 107      }
 108  
 109      return _construct.apply(null, arguments);
 110    }
 111  
 112    function _isNativeFunction(fn) {
 113      return Function.toString.call(fn).indexOf("[native code]") !== -1;
 114    }
 115  
 116    function _wrapNativeSuper(Class) {
 117      var _cache = typeof Map === "function" ? new Map() : undefined;
 118  
 119      _wrapNativeSuper = function _wrapNativeSuper(Class) {
 120        if (Class === null || !_isNativeFunction(Class)) return Class;
 121  
 122        if (typeof Class !== "function") {
 123          throw new TypeError("Super expression must either be null or a function");
 124        }
 125  
 126        if (typeof _cache !== "undefined") {
 127          if (_cache.has(Class)) return _cache.get(Class);
 128  
 129          _cache.set(Class, Wrapper);
 130        }
 131  
 132        function Wrapper() {
 133          return _construct(Class, arguments, _getPrototypeOf(this).constructor);
 134        }
 135  
 136        Wrapper.prototype = Object.create(Class.prototype, {
 137          constructor: {
 138            value: Wrapper,
 139            enumerable: false,
 140            writable: true,
 141            configurable: true
 142          }
 143        });
 144        return _setPrototypeOf(Wrapper, Class);
 145      };
 146  
 147      return _wrapNativeSuper(Class);
 148    }
 149  
 150    function _assertThisInitialized(self) {
 151      if (self === void 0) {
 152        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
 153      }
 154  
 155      return self;
 156    }
 157  
 158    var CodemirrorEditor = /*#__PURE__*/function (_HTMLElement) {
 159      _inheritsLoose(CodemirrorEditor, _HTMLElement);
 160  
 161      function CodemirrorEditor() {
 162        var _this;
 163  
 164        _this = _HTMLElement.call(this) || this;
 165        _this.instance = '';
 166        _this.host = window.location.origin;
 167        _this.element = _this.querySelector('textarea');
 168        _this.refresh = _this.refresh.bind(_assertThisInitialized(_this)); // Observer instance to refresh the Editor when it become visible, eg after Tab switching
 169  
 170        _this.intersectionObserver = new IntersectionObserver(function (entries) {
 171          if (entries[0].isIntersecting && _this.instance) {
 172            _this.instance.refresh();
 173          }
 174        }, {
 175          threshold: 0
 176        });
 177        return _this;
 178      }
 179  
 180      var _proto = CodemirrorEditor.prototype;
 181  
 182      _proto.attributeChangedCallback = function attributeChangedCallback(attr, oldValue, newValue) {
 183        switch (attr) {
 184          case 'options':
 185            if (oldValue && newValue !== oldValue) {
 186              this.refresh(this.element);
 187            }
 188  
 189            break;
 190        }
 191      };
 192  
 193      _proto.connectedCallback = /*#__PURE__*/function () {
 194        var _connectedCallback = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
 195          var _this2 = this;
 196  
 197          var cmPath, addonsPath, that;
 198          return regeneratorRuntime.wrap(function _callee$(_context) {
 199            while (1) {
 200              switch (_context.prev = _context.next) {
 201                case 0:
 202                  cmPath = this.getAttribute('editor');
 203                  addonsPath = this.getAttribute('addons');
 204                  _context.next = 4;
 205                  return import(this.host + "/" + cmPath);
 206  
 207                case 4:
 208                  if (!this.options.keyMapUrl) {
 209                    _context.next = 7;
 210                    break;
 211                  }
 212  
 213                  _context.next = 7;
 214                  return import(this.host + "/" + this.options.keyMapUrl);
 215  
 216                case 7:
 217                  _context.next = 9;
 218                  return import(this.host + "/" + addonsPath);
 219  
 220                case 9:
 221                  that = this; // For mode autoloading.
 222  
 223                  window.CodeMirror.modeURL = this.getAttribute('mod-path'); // Fire this function any time an editor is created.
 224  
 225                  window.CodeMirror.defineInitHook(function (editor) {
 226                    var _map;
 227  
 228                    // Try to set up the mode
 229                    var mode = window.CodeMirror.findModeByName(editor.options.mode || '') || window.CodeMirror.findModeByExtension(editor.options.mode || '');
 230                    window.CodeMirror.autoLoadMode(editor, typeof mode === 'object' ? mode.mode : editor.options.mode);
 231  
 232                    if (mode && mode.mime) {
 233                      // Fix the x-php error
 234                      if (['text/x-php', 'application/x-httpd-php', 'application/x-httpd-php-open'].includes(mode.mime)) {
 235                        editor.setOption('mode', 'php');
 236                      } else {
 237                        editor.setOption('mode', mode.mime);
 238                      }
 239                    }
 240  
 241                    var toggleFullScreen = function toggleFullScreen() {
 242                      that.instance.setOption('fullScreen', !that.instance.getOption('fullScreen'));
 243                      var header = document.getElementById('subhead');
 244  
 245                      if (header) {
 246                        var header1 = document.getElementById('header');
 247                        header1.classList.toggle('hidden');
 248                        header.classList.toggle('hidden');
 249                        that.instance.display.wrapper.style.top = header.getBoundingClientRect().height + "px";
 250                      }
 251                    };
 252  
 253                    var closeFullScreen = function closeFullScreen() {
 254                      that.instance.getOption('fullScreen');
 255                      that.instance.setOption('fullScreen', false);
 256  
 257                      if (!that.instance.getOption('fullScreen')) {
 258                        var header = document.getElementById('subhead');
 259  
 260                        if (header) {
 261                          var header1 = document.getElementById('header');
 262                          header.classList.toggle('hidden');
 263                          header1.classList.toggle('hidden');
 264                          that.instance.display.wrapper.style.top = header.getBoundingClientRect().height + "px";
 265                        }
 266                      }
 267                    };
 268  
 269                    var map = (_map = {
 270                      'Ctrl-Q': toggleFullScreen
 271                    }, _map[that.getAttribute('fs-combo')] = toggleFullScreen, _map.Esc = closeFullScreen, _map);
 272                    editor.addKeyMap(map);
 273  
 274                    var makeMarker = function makeMarker() {
 275                      var marker = document.createElement('div');
 276                      marker.className = 'CodeMirror-markergutter-mark';
 277                      return marker;
 278                    }; // Handle gutter clicks (place or remove a marker).
 279  
 280  
 281                    editor.on('gutterClick', function (ed, n, gutter) {
 282                      if (gutter !== 'CodeMirror-markergutter') {
 283                        return;
 284                      }
 285  
 286                      var info = ed.lineInfo(n);
 287                      var hasMarker = !!info.gutterMarkers && !!info.gutterMarkers['CodeMirror-markergutter'];
 288                      ed.setGutterMarker(n, 'CodeMirror-markergutter', hasMarker ? null : makeMarker());
 289                    });
 290                    /* Some browsers do something weird with the fieldset which doesn't
 291                      work well with CodeMirror. Fix it. */
 292  
 293                    if (that.parentNode.tagName.toLowerCase() === 'fieldset') {
 294                      that.parentNode.style.minWidth = 0;
 295                    }
 296                  }); // Register Editor
 297  
 298                  this.instance = window.CodeMirror.fromTextArea(this.element, this.options);
 299  
 300                  this.instance.disable = function (disabled) {
 301                    return _this2.setOption('readOnly', disabled ? 'nocursor' : false);
 302                  };
 303  
 304                  Joomla.editors.instances[this.element.id] = this.instance; // Watch when the element in viewport, and refresh the editor
 305  
 306                  this.intersectionObserver.observe(this);
 307  
 308                case 16:
 309                case "end":
 310                  return _context.stop();
 311              }
 312            }
 313          }, _callee, this);
 314        }));
 315  
 316        function connectedCallback() {
 317          return _connectedCallback.apply(this, arguments);
 318        }
 319  
 320        return connectedCallback;
 321      }();
 322  
 323      _proto.disconnectedCallback = function disconnectedCallback() {
 324        // Remove from the Joomla API
 325        delete Joomla.editors.instances[this.element.id]; // Remove from observer
 326  
 327        this.intersectionObserver.unobserve(this);
 328      };
 329  
 330      _proto.refresh = function refresh(element) {
 331        this.instance.fromTextArea(element, this.options);
 332      };
 333  
 334      _createClass(CodemirrorEditor, [{
 335        key: "options",
 336        get: function get() {
 337          return JSON.parse(this.getAttribute('options'));
 338        },
 339        set: function set(value) {
 340          this.setAttribute('options', value);
 341        }
 342      }], [{
 343        key: "observedAttributes",
 344        get: function get() {
 345          return ['options'];
 346        }
 347      }]);
 348  
 349      return CodemirrorEditor;
 350    }( /*#__PURE__*/_wrapNativeSuper(HTMLElement));
 351  
 352    customElements.define('joomla-editor-codemirror', CodemirrorEditor);
 353  
 354  })();


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer