- md5
- 82432d1e7342ec872e55ea5dcee6ab0c
- sha1
- 8673eb07a3064c4b3028e5260638e1e20334404b
- sha256
- 5c50ef11f73d2891aa4f107c51eef88a469a5a3b1f2748ca279b2e407eb4a7f0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'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; }; }();
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 (customElements) {
// Keycodes
var KEYCODE = {
ENTER: 13,
SPACE: 32
};
var JoomlaSwitcherElement = function (_HTMLElement) {
_inherits(JoomlaSwitcherElement, _HTMLElement);
_createClass(JoomlaSwitcherElement, [{
key: 'type',
get: function get() {
return this.getAttribute('type');
},
set: function set(value) {
return this.setAttribute('type', value);
}
}, {
key: 'offText',
get: function get() {
return this.getAttribute('off-text') || 'Off';
}
}, {
key: 'onText',
get: function get() {
return this.getAttribute('on-text') || 'On';
}
// attributeChangedCallback(attr, oldValue, newValue) {}
}], [{
key: 'observedAttributes',
/* Attributes to monitor */
get: function get() {
return ['type', 'off-text', 'on-text'];
}
}]);
function JoomlaSwitcherElement() {
_classCallCheck(this, JoomlaSwitcherElement);
var _this = _possibleConstructorReturn(this, (JoomlaSwitcherElement.__proto__ || Object.getPrototypeOf(JoomlaSwitcherElement)).call(this));
_this.inputs = [];
_this.spans = [];
_this.inputsContainer = '';
_this.newActive = '';
return _this;
}
/* Lifecycle, element appended to the DOM */
_createClass(JoomlaSwitcherElement, [{
key: 'connectedCallback',
value: function connectedCallback() {
var _this2 = this;
this.inputs = [].slice.call(this.querySelectorAll('input'));
if (this.inputs.length !== 2 || this.inputs[0].type !== 'radio') {
throw new Error('`Joomla-switcher` requires two inputs type="checkbox"');
}
// Create the markup
this.createMarkup.bind(this)();
this.inputsContainer = this.firstElementChild;
this.inputsContainer.setAttribute('role', 'switch');
if (this.inputs[1].checked) {
this.inputs[1].parentNode.classList.add('active');
this.spans[1].classList.add('active');
// Aria-label ONLY in the container span!
this.inputsContainer.setAttribute('aria-label', this.spans[1].innerHTML);
} else {
this.spans[0].classList.add('active');
// Aria-label ONLY in the container span!
this.inputsContainer.setAttribute('aria-label', this.spans[0].innerHTML);
}
this.inputs.forEach(function (switchEl) {
// Add the active class on click
switchEl.addEventListener('click', _this2.toggle.bind(_this2));
});
this.inputsContainer.addEventListener('keydown', this.keyEvents.bind(this));
}
/* Lifecycle, element removed from the DOM */
}, {
key: 'disconnectedCallback',
value: function disconnectedCallback() {
this.removeEventListener('joomla.switcher.toggle', this.toggle, true);
this.removeEventListener('click', this.switch, true);
this.removeEventListener('keydown', this.keydown, true);
}
/* Method to dispatch events */
}, {
key: 'dispatchCustomEvent',
value: function dispatchCustomEvent(eventName) {
var OriginalCustomEvent = new CustomEvent(eventName, { bubbles: true, cancelable: true });
OriginalCustomEvent.relatedTarget = this;
this.dispatchEvent(OriginalCustomEvent);
this.removeEventListener(eventName, this);
}
/** Method to build the switch */
}, {
key: 'createMarkup',
value: function createMarkup() {
var checked = 0;
// Create the first 'span' wrapper
var spanFirst = document.createElement('span');
spanFirst.classList.add('switcher');
spanFirst.setAttribute('tabindex', 0);
// If no type has been defined, the default as "success"
if (!this.type) {
this.setAttribute('type', 'success');
}
var switchEl = document.createElement('span');
switchEl.classList.add('switch');
this.inputs.forEach(function (input, index) {
// Remove the tab focus from the inputs
input.setAttribute('tabindex', '-1');
if (input.checked) {
spanFirst.setAttribute('aria-checked', true);
}
spanFirst.appendChild(input);
if (index === 1 && input.checked) {
checked = 1;
}
});
spanFirst.appendChild(switchEl);
// Create the second 'span' wrapper
var spanSecond = document.createElement('span');
spanSecond.classList.add('switcher-labels');
var labelFirst = document.createElement('span');
labelFirst.classList.add('switcher-label-0');
labelFirst.innerText = this.offText;
var labelSecond = document.createElement('span');
labelSecond.classList.add('switcher-label-1');
labelSecond.innerText = this.onText;
if (checked === 0) {
labelFirst.classList.add('active');
} else {
labelSecond.classList.add('active');
}
this.spans.push(labelFirst);
this.spans.push(labelSecond);
spanSecond.appendChild(labelFirst);
spanSecond.appendChild(labelSecond);
// Append everything back to the main element
this.appendChild(spanFirst);
this.appendChild(spanSecond);
}
/** Method to toggle the switch */
}, {
key: 'switch',
value: function _switch() {
this.spans.forEach(function (span) {
span.classList.remove('active');
});
if (this.inputsContainer.classList.contains('active')) {
this.inputsContainer.classList.remove('active');
} else {
this.inputsContainer.classList.add('active');
}
// Remove active class from all inputs
this.inputs.forEach(function (input) {
input.classList.remove('active');
});
// Check if active
if (this.newActive === 1) {
this.inputs[this.newActive].classList.add('active');
this.inputs[1].setAttribute('checked', '');
this.inputs[0].removeAttribute('checked');
this.inputsContainer.setAttribute('aria-checked', true);
// Aria-label ONLY in the container span!
this.inputsContainer.setAttribute('aria-label', this.spans[1].innerHTML);
// Dispatch the "joomla.switcher.on" event
this.dispatchCustomEvent('joomla.switcher.on');
} else {
this.inputs[1].removeAttribute('checked');
this.inputs[0].setAttribute('checked', '');
this.inputs[0].classList.add('active');
this.inputsContainer.setAttribute('aria-checked', false);
// Aria-label ONLY in the container span!
this.inputsContainer.setAttribute('aria-label', this.spans[0].innerHTML);
// Dispatch the "joomla.switcher.off" event
this.dispatchCustomEvent('joomla.switcher.off');
}
this.spans[this.newActive].classList.add('active');
}
/** Method to toggle the switch */
}, {
key: 'toggle',
value: function toggle() {
this.newActive = this.inputs[1].classList.contains('active') ? 0 : 1;
this.switch.bind(this)();
}
}, {
key: 'keyEvents',
value: function keyEvents(event) {
if (event.keyCode === KEYCODE.ENTER || event.keyCode === KEYCODE.SPACE) {
event.preventDefault();
this.newActive = this.inputs[1].classList.contains('active') ? 0 : 1;
this.switch.bind(this)();
}
}
}]);
return JoomlaSwitcherElement;
}(HTMLElement);
customElements.define('joomla-field-switcher', JoomlaSwitcherElement);
})(customElements);
},{}]},{},[1]);
No other release has this exact content. See every version of this file.