plus-8.x-4.x-dev/plus_enhancements/js/Drupal.Enhancements.js
plus_enhancements/js/Drupal.Enhancements.js
/**
* DO NOT EDIT THIS FILE.
* THIS FILE IS COMPILED AUTOMATICALLY FROM ITS ES6 SOURCE.
* @preserve
**/'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
(function ($, Drupal) {
'use strict';
if ($ && $.fn && !$.fn.on && $.fn.delegate) {
Drupal.require('@plus/jquery.on.off.shim');
}
var Enhancements = function (_Map) {
_inherits(Enhancements, _Map);
function Enhancements() {
_classCallCheck(this, Enhancements);
return _possibleConstructorReturn(this, (Enhancements.__proto__ || Object.getPrototypeOf(Enhancements)).apply(this, arguments));
}
_createClass(Enhancements, [{
key: 'attach',
value: function attach() {
var _arguments = arguments;
this.forEach(function (enhancement) {
for (var s in enhancement.attachments) {
if (enhancement.attachments.hasOwnProperty(s)) {
enhancement.attachments[s].apply(enhancement, _arguments);
}
}
});
}
}, {
key: 'create',
value: function create(id, enhancement) {
if (typeof id !== 'string') {
return Drupal.fatal(Drupal.t('The first argument in Drupal.Enhancements.create() must be a string indicating the machine identifier of the user enhancement to create.'));
}
if (this.has(id)) {
Drupal.warning(Drupal.t('An instance for the "@id" user enhancement already exists and cannot be recreated, returning existing instance. Use the Drupal.Enhancements.get() method to retrieve or use the Drupal.Enhancements.extend() methods to extend an existing instance.'), {
'@id': id
});
return this.get(id);
}
if (!Drupal.isClass(enhancement)) {
return Drupal.fatal(Drupal.t('You must provide an ES6 Class to create the user enhancement "@id": @ctor'), {
'@id': id,
'@ctor': enhancement
});
}
var namespaces = id.split('.');
var parent = void 0;
while (namespaces.length) {
parent = this.get(namespaces.join('.'), true);
if (parent) {
break;
}
namespaces.pop();
}
var instance = new enhancement(id, Drupal.settings && Drupal.settings.Enhancements && Drupal.settings.Enhancements[id] || {}, parent);
instance.debug = this.debug;
instance.init();
this.set(id, instance);
return instance;
}
}, {
key: 'detach',
value: function detach() {
var _arguments2 = arguments;
this.forEach(function (enhancement) {
for (var s in enhancement.detachments) {
if (enhancement.detachments.hasOwnProperty(s)) {
enhancement.detachments[s].apply(enhancement, _arguments2);
}
}
});
}
}, {
key: 'get',
value: function get(id, suppressError) {
var enhancement = _get(Enhancements.prototype.__proto__ || Object.getPrototypeOf(Enhancements.prototype), 'get', this).call(this, id) || undefined;
if (!enhancement && !suppressError) {
Drupal.error('The user enhancement "@id" does not exist. You must first create the user enhancement before you can retrieve it.', {
'@id': id
});
}
return enhancement;
}
}, {
key: 'debug',
get: function get() {
return !!Drupal.Storage.create('Drupal.Enhancements').get('debug');
},
set: function set(value) {
if (value) {
Drupal.Storage.create('Drupal.Enhancements').set('debug', true);
} else {
Drupal.Storage.create('Drupal.Enhancements').remove('debug');
}
this.forEach(function (enhancement) {
enhancement.debug = value;
});
return this;
}
}]);
return Enhancements;
}(Map);
Drupal.Enhancements = Drupal.behaviors.Enhancements = new Enhancements();
})(jQuery, Drupal);