From 48a1cd594f5107aafca97ed6391dbeb055c4d92a Mon Sep 17 00:00:00 2001 From: Pavel Janda Date: Tue, 21 Apr 2020 14:55:46 +0200 Subject: [PATCH] src/nomodule-es5-fallback.js --- src/nomodule-es5-fallback.js | 234 ++++++++++++++++++++++++++++++++++ src/nomodule-fallback.js | 241 ----------------------------------- 2 files changed, 234 insertions(+), 241 deletions(-) create mode 100644 src/nomodule-es5-fallback.js delete mode 100644 src/nomodule-fallback.js diff --git a/src/nomodule-es5-fallback.js b/src/nomodule-es5-fallback.js new file mode 100644 index 0000000..7013e19 --- /dev/null +++ b/src/nomodule-es5-fallback.js @@ -0,0 +1,234 @@ +function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } + +function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +var Happy = function Happy() { + "use strict"; + + var _this = this; + + _classCallCheck(this, Happy); + + _defineProperty(this, "init", function () { + _this.removeBySelector('.happy-radio'); + + _this.removeBySelector('.happy-checkbox'); + + _this.initRadio(); + + _this.initCheckbox(); + }); + + _defineProperty(this, "reset", function () { + _this.init(); + }); + + _defineProperty(this, "addColorToInput", function (input, happyInput, classString) { + if (input.classList.contains(classString)) { + happyInput.classList.add(classString); + } + + if (input.classList.contains(classString + '-border')) { + happyInput.classList.add(classString + '-border'); + } + }); + + _defineProperty(this, "addThinkessToInput", function (input, happyInput) { + if (input.classList.contains('thin')) { + happyInput.classList.add('thin'); + } + }); + + _defineProperty(this, "setNames", function (input, happyInput) { + happyInput.setAttribute('data-name', input.getAttribute('name')); + var value = input.getAttribute('value'); + + if (value !== 'undefined' && value !== false && value !== null) { + happyInput.setAttribute('data-value', input.getAttribute('value')); + } + }); + + _defineProperty(this, "removeBySelector", function (selector) { + document.querySelectorAll(selector).forEach(function (el) { + el.parentNode.removeChild(el); + }); + }); + + _defineProperty(this, "initRadio", function () { + document.querySelectorAll('input[type=radio].happy').forEach(function (input) { + /** + * Paste happy component into html + */ + input.insertAdjacentHTML('afterend', _this.templates.radio); + var happyInput = input.nextElementSibling; + /** + * Add optional colors + */ + + _this.colors.forEach(function (color) { + _this.addColorToInput(input, happyInput, color); + + _this.setNames(input, happyInput); + }); + + _this.addThinkessToInput(input, happyInput); + /** + * Init state + */ + + + _this.checkRadioState(input); + /** + * Set aciton functionality for native change + */ + + + document.addEventListener('change', _this.radioOnChange); + }); + }); + + _defineProperty(this, "initCheckbox", function () { + document.querySelectorAll('input[type=checkbox].happy').forEach(function (input) { + /** + * Paste happy component into html + */ + input.insertAdjacentHTML('afterend', _this.templates.checkbox); + var happyInput = input.nextElementSibling; + /** + * Add optional colors + */ + + _this.colors.forEach(function (color) { + _this.addColorToInput(input, happyInput, color); + + _this.setNames(input, happyInput); + }); + + _this.addThinkessToInput(input, happyInput); + /** + * Init state + */ + + + _this.checkCheckboxState(input); + /** + * Set action functionality for click || native change + */ + + + document.addEventListener('click', _this.checkCheckboxStateOnClick); + document.addEventListener('change', _this.checkCheckboxStateOnChange); + }); + }); + + _defineProperty(this, "checkCheckboxStateOnClick", function (event) { + var happyInput; + + if (event.target.tagName === 'svg') { + happyInput = event.target.parentNode; + } else if (event.target.tagName === 'rect') { + happyInput = event.target.parentNode.parentNode; + } else { + happyInput = event.target; + } + + if (!happyInput || !happyInput.classList.contains('happy-checkbox')) { + return; + } + + event.preventDefault(); + var selector = 'input[type=checkbox][name="' + happyInput.getAttribute('data-name') + '"]'; + var value = happyInput.getAttribute('data-value'); + + if (_typeof(value != 'undefined') && value != false && value != null) { + selector += '[value="' + value + '"]'; + } + + var input = document.querySelector(selector); + + if (input) { + if (happyInput.classList.contains('active')) { + input.checked = false; + happyInput.classList.remove('active'); + } else { + input.checked = true; + happyInput.classList.add('active'); + } + + if (window.navigator.userAgent.indexOf("MSIE ")) { + event = document.createEvent('Event'); + event.initEvent('change', true, true); + } else { + event = new Event('change', { + 'bubbles': true + }); + } + + input.dispatchEvent(event); + } + }); + + _defineProperty(this, "checkCheckboxStateOnChange", function (event) { + if (event.target.classList.contains('happy')) { + _this.checkCheckboxState(event.target); + } + }); + + _defineProperty(this, "checkRadioState", function (input) { + if (input.checked) { + var name = input.getAttribute('name'); + var value = input.getAttribute('value'); + var selector = '.happy-radio[data-name="' + name + '"][data-value="' + value + '"]'; + var happyRadio = document.querySelector(selector); + + if (happyRadio) { + happyRadio.classList.add('active'); + } + } + }); + + _defineProperty(this, "checkCheckboxState", function (input) { + var selector = '.happy-checkbox[data-name="' + input.getAttribute('name') + '"]'; + var value = input.getAttribute('value'); + + if (_typeof(value != 'undefined') && value != false && value != null) { + selector += '[data-value="' + value + '"]'; + } + + var element = document.querySelector(selector); + + if (element) { + if (input.checked) { + element.classList.add('active'); + } else { + element.classList.remove('active'); + } + } + }); + + _defineProperty(this, "radioOnChange", function (event) { + if (!event.target.classList.contains('happy')) { + return; + } + + var name = event.target.getAttribute('name'); + var selector = '.happy-radio[data-name="' + name + '"]'; + document.querySelectorAll(selector).forEach(function (happyRadio) { + happyRadio.classList.remove('active'); + }); + + _this.checkRadioState(event.target); + }); + + this.colors = ['primary', 'success', 'info', 'warning', 'danger', 'white', 'gray']; + this.templates = { + radio: '
', + checkbox: '
', + text: '', + textarea: '' + }; +}; diff --git a/src/nomodule-fallback.js b/src/nomodule-fallback.js deleted file mode 100644 index eb990c4..0000000 --- a/src/nomodule-fallback.js +++ /dev/null @@ -1,241 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } - -var Happy = function Happy() { - var _this = this; - - _classCallCheck(this, Happy); - - _defineProperty(this, "init", function () { - _this.removeBySelector('.happy-radio'); - - _this.removeBySelector('.happy-checkbox'); - - _this.initRadio(); - - _this.initCheckbox(); - }); - - _defineProperty(this, "reset", function () { - _this.init(); - }); - - _defineProperty(this, "addColorToInput", function (input, happyInput, classString) { - if (input.classList.contains(classString)) { - happyInput.classList.add(classString); - } - - if (input.classList.contains(classString + '-border')) { - happyInput.classList.add(classString + '-border'); - } - }); - - _defineProperty(this, "addThinkessToInput", function (input, happyInput) { - if (input.classList.contains('thin')) { - happyInput.classList.add('thin'); - } - }); - - _defineProperty(this, "setNames", function (input, happyInput) { - happyInput.setAttribute('data-name', input.getAttribute('name')); - var value = input.getAttribute('value'); - - if (value !== 'undefined' && value !== false && value !== null) { - happyInput.setAttribute('data-value', input.getAttribute('value')); - } - }); - - _defineProperty(this, "removeBySelector", function (selector) { - document.querySelectorAll(selector).forEach(function (el) { - el.parentNode.removeChild(el); - }); - }); - - _defineProperty(this, "initRadio", function () { - document.querySelectorAll('input[type=radio].happy').forEach(function (input) { - /** - * Paste happy component into html - */ - input.insertAdjacentHTML('afterend', _this.templates.radio); - var happyInput = input.nextElementSibling; - /** - * Add optional colors - */ - - _this.colors.forEach(function (color) { - _this.addColorToInput(input, happyInput, color); - - _this.setNames(input, happyInput); - }); - - _this.addThinkessToInput(input, happyInput); - /** - * Init state - */ - - - _this.checkRadioState(input); - /** - * Set aciton functionality for native change - */ - - - document.addEventListener('change', _this.radioOnChange); - }); - }); - - _defineProperty(this, "initCheckbox", function () { - document.querySelectorAll('input[type=checkbox].happy').forEach(function (input) { - /** - * Paste happy component into html - */ - input.insertAdjacentHTML('afterend', _this.templates.checkbox); - var happyInput = input.nextElementSibling; - /** - * Add optional colors - */ - - _this.colors.forEach(function (color) { - _this.addColorToInput(input, happyInput, color); - - _this.setNames(input, happyInput); - }); - - _this.addThinkessToInput(input, happyInput); - /** - * Init state - */ - - - _this.checkCheckboxState(input); - /** - * Set action functionality for click || native change - */ - - - document.addEventListener('click', _this.checkCheckboxStateOnClick); - document.addEventListener('change', _this.checkCheckboxStateOnChange); - }); - }); - - _defineProperty(this, "checkCheckboxStateOnClick", function (event) { - var happyInput; - - if (event.target.tagName === 'svg') { - happyInput = event.target.parentNode; - } else if (event.target.tagName === 'rect') { - happyInput = event.target.parentNode.parentNode; - } else { - happyInput = event.target; - } - - if (!happyInput || !happyInput.classList.contains('happy-checkbox')) { - return; - } - - event.preventDefault(); - var selector = 'input[type=checkbox][name="' + happyInput.getAttribute('data-name') + '"]'; - var value = happyInput.getAttribute('data-value'); - - if (_typeof(value != 'undefined') && value != false && value != null) { - selector += '[value="' + value + '"]'; - } - - var input = document.querySelector(selector); - - if (input) { - if (happyInput.classList.contains('active')) { - input.checked = false; - happyInput.classList.remove('active'); - } else { - input.checked = true; - happyInput.classList.add('active'); - } - - if (window.navigator.userAgent.indexOf("MSIE ")) { - event = document.createEvent('Event'); - event.initEvent('change', true, true); - } else { - event = new Event('change', { - 'bubbles': true - }); - } - - input.dispatchEvent(event); - } - }); - - _defineProperty(this, "checkCheckboxStateOnChange", function (event) { - if (event.target.classList.contains('happy')) { - _this.checkCheckboxState(event.target); - } - }); - - _defineProperty(this, "checkRadioState", function (input) { - if (input.checked) { - var name = input.getAttribute('name'); - var value = input.getAttribute('value'); - var selector = '.happy-radio[data-name="' + name + '"][data-value="' + value + '"]'; - var happyRadio = document.querySelector(selector); - - if (happyRadio) { - happyRadio.classList.add('active'); - } - } - }); - - _defineProperty(this, "checkCheckboxState", function (input) { - var selector = '.happy-checkbox[data-name="' + input.getAttribute('name') + '"]'; - var value = input.getAttribute('value'); - - if (_typeof(value != 'undefined') && value != false && value != null) { - selector += '[data-value="' + value + '"]'; - } - - var element = document.querySelector(selector); - - if (element) { - if (input.checked) { - element.classList.add('active'); - } else { - element.classList.remove('active'); - } - } - }); - - _defineProperty(this, "radioOnChange", function (event) { - if (!event.target.classList.contains('happy')) { - return; - } - - var name = event.target.getAttribute('name'); - var selector = '.happy-radio[data-name="' + name + '"]'; - document.querySelectorAll(selector).forEach(function (happyRadio) { - happyRadio.classList.remove('active'); - }); - - _this.checkRadioState(event.target); - }); - - this.colors = ['primary', 'success', 'info', 'warning', 'danger', 'white', 'gray']; - this.templates = { - radio: '
', - checkbox: '
', - text: '', - textarea: '' - }; -}; - -exports.default = Happy;