[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/system/js/fields/ -> joomla-field-module-order-es5.js (source)

   1  (function () {
   2    'use strict';
   3  
   4    function _inheritsLoose(subClass, superClass) {
   5      subClass.prototype = Object.create(superClass.prototype);
   6      subClass.prototype.constructor = subClass;
   7  
   8      _setPrototypeOf(subClass, superClass);
   9    }
  10  
  11    function _getPrototypeOf(o) {
  12      _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  13        return o.__proto__ || Object.getPrototypeOf(o);
  14      };
  15      return _getPrototypeOf(o);
  16    }
  17  
  18    function _setPrototypeOf(o, p) {
  19      _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  20        o.__proto__ = p;
  21        return o;
  22      };
  23  
  24      return _setPrototypeOf(o, p);
  25    }
  26  
  27    function _isNativeReflectConstruct() {
  28      if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  29      if (Reflect.construct.sham) return false;
  30      if (typeof Proxy === "function") return true;
  31  
  32      try {
  33        Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  34        return true;
  35      } catch (e) {
  36        return false;
  37      }
  38    }
  39  
  40    function _construct(Parent, args, Class) {
  41      if (_isNativeReflectConstruct()) {
  42        _construct = Reflect.construct;
  43      } else {
  44        _construct = function _construct(Parent, args, Class) {
  45          var a = [null];
  46          a.push.apply(a, args);
  47          var Constructor = Function.bind.apply(Parent, a);
  48          var instance = new Constructor();
  49          if (Class) _setPrototypeOf(instance, Class.prototype);
  50          return instance;
  51        };
  52      }
  53  
  54      return _construct.apply(null, arguments);
  55    }
  56  
  57    function _isNativeFunction(fn) {
  58      return Function.toString.call(fn).indexOf("[native code]") !== -1;
  59    }
  60  
  61    function _wrapNativeSuper(Class) {
  62      var _cache = typeof Map === "function" ? new Map() : undefined;
  63  
  64      _wrapNativeSuper = function _wrapNativeSuper(Class) {
  65        if (Class === null || !_isNativeFunction(Class)) return Class;
  66  
  67        if (typeof Class !== "function") {
  68          throw new TypeError("Super expression must either be null or a function");
  69        }
  70  
  71        if (typeof _cache !== "undefined") {
  72          if (_cache.has(Class)) return _cache.get(Class);
  73  
  74          _cache.set(Class, Wrapper);
  75        }
  76  
  77        function Wrapper() {
  78          return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  79        }
  80  
  81        Wrapper.prototype = Object.create(Class.prototype, {
  82          constructor: {
  83            value: Wrapper,
  84            enumerable: false,
  85            writable: true,
  86            configurable: true
  87          }
  88        });
  89        return _setPrototypeOf(Wrapper, Class);
  90      };
  91  
  92      return _wrapNativeSuper(Class);
  93    }
  94  
  95    function _assertThisInitialized(self) {
  96      if (self === void 0) {
  97        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  98      }
  99  
 100      return self;
 101    }
 102  
 103    /**
 104     * @package         Joomla.JavaScript
 105     * @copyright       (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 106     * @license         GNU General Public License version 2 or later; see LICENSE.txt
 107     */
 108    customElements.define('joomla-field-module-order', /*#__PURE__*/function (_HTMLElement) {
 109      _inheritsLoose(_class, _HTMLElement);
 110  
 111      function _class() {
 112        var _this;
 113  
 114        _this = _HTMLElement.call(this) || this;
 115        _this.linkedFieldSelector = '';
 116        _this.linkedFieldElement = '';
 117        _this.originalPosition = '';
 118  
 119        _this.writeDynaList.bind(_assertThisInitialized(_this));
 120  
 121        _this.getNewOrder.bind(_assertThisInitialized(_this));
 122  
 123        return _this;
 124      }
 125  
 126      var _proto = _class.prototype;
 127  
 128      _proto.connectedCallback = function connectedCallback() {
 129        this.linkedFieldSelector = this.getAttribute('data-linked-field') || 'jform_position';
 130  
 131        if (!this.linkedFieldSelector) {
 132          throw new Error('No linked field defined!');
 133        }
 134  
 135        this.linkedFieldElement = document.getElementById(this.linkedFieldSelector);
 136  
 137        if (!this.linkedFieldElement) {
 138          throw new Error('No linked field defined!');
 139        }
 140  
 141        var that = this;
 142        this.originalPosition = this.linkedFieldElement.value;
 143        /** Initialize the field * */
 144  
 145        this.getNewOrder(this.originalPosition);
 146        /** Watch for changes on the linked field * */
 147  
 148        this.linkedFieldElement.addEventListener('change', function () {
 149          that.originalPosition = that.linkedFieldElement.value;
 150          that.getNewOrder(that.linkedFieldElement.value);
 151        });
 152      };
 153  
 154      _proto.writeDynaList = function writeDynaList(selectProperties, source, originalPositionName, originalPositionValue) {
 155        var i = 0;
 156        var selectNode = document.createElement('select');
 157  
 158        if (this.hasAttribute('disabled')) {
 159          selectNode.setAttribute('disabled', '');
 160        }
 161  
 162        if (this.getAttribute('onchange')) {
 163          selectNode.setAttribute('onchange', this.getAttribute('onchange'));
 164        }
 165  
 166        if (this.getAttribute('size')) {
 167          selectNode.setAttribute('size', this.getAttribute('size'));
 168        }
 169  
 170        selectNode.classList.add(selectProperties.itemClass);
 171        selectNode.setAttribute('name', selectProperties.name);
 172        selectNode.id = selectProperties.id; // eslint-disable-next-line no-restricted-syntax
 173  
 174        for (var x in source) {
 175          // eslint-disable-next-line no-prototype-builtins
 176          if (!source.hasOwnProperty(x)) {
 177            // eslint-disable-next-line no-continue
 178            continue;
 179          }
 180  
 181          var node = document.createElement('option');
 182          var item = source[x]; // eslint-disable-next-line prefer-destructuring
 183  
 184          node.value = item[1]; // eslint-disable-next-line prefer-destructuring
 185  
 186          node.innerHTML = Joomla.sanitizeHtml(item[2]);
 187  
 188          if (originalPositionName && originalPositionValue === item[1] || !originalPositionName && i === 0) {
 189            node.setAttribute('selected', 'selected');
 190          }
 191  
 192          selectNode.appendChild(node);
 193          i += 1;
 194        }
 195  
 196        this.innerHTML = '';
 197        this.appendChild(selectNode);
 198      };
 199  
 200      _proto.getNewOrder = function getNewOrder(originalPosition) {
 201        var url = this.getAttribute('data-url');
 202        var clientId = this.getAttribute('data-client-id');
 203        var originalOrder = this.getAttribute('data-ordering');
 204        var name = this.getAttribute('data-name');
 205        var attr = this.getAttribute('data-client-attr') ? this.getAttribute('data-client-attr') : 'form-select';
 206        var id = "" + this.getAttribute('data-id');
 207        var moduleId = "" + this.getAttribute('data-module-id');
 208        var orders = [];
 209        var that = this;
 210        Joomla.request({
 211          url: url + "&client_id=" + clientId + "&position=" + originalPosition + "&module_id=" + moduleId,
 212          method: 'GET',
 213          perform: true,
 214          headers: {
 215            'Content-Type': 'application/x-www-form-urlencoded'
 216          },
 217          onSuccess: function onSuccess(resp) {
 218            if (resp) {
 219              var response;
 220  
 221              try {
 222                response = JSON.parse(resp);
 223              } catch (e) {
 224                // eslint-disable-next-line no-console
 225                console.error(e);
 226              }
 227              /** Check if everything is OK * */
 228  
 229  
 230              if (response.data.length > 0) {
 231                for (var i = 0; i < response.data.length; i += 1) {
 232                  orders[i] = response.data[i].split(',');
 233                }
 234  
 235                that.writeDynaList({
 236                  name: name,
 237                  id: id,
 238                  itemClass: attr
 239                }, orders, that.originalPosition, originalOrder);
 240              }
 241            }
 242            /** Render messages, if any. There are only message in case of errors. * */
 243  
 244  
 245            if (typeof resp.messages === 'object' && resp.messages !== null) {
 246              Joomla.renderMessages(resp.messages);
 247            }
 248          }
 249        });
 250      };
 251  
 252      return _class;
 253    }( /*#__PURE__*/_wrapNativeSuper(HTMLElement)));
 254  
 255  })();


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