UNPKG

xlb-main-login

Version:

``` yarn install ```

1,701 lines (1,396 loc) 122 kB
/*! * Bootstrap Colorpicker - Simple and customizable colorpicker component for Twitter Bootstrap. * @package bootstrap-colorpicker * @version v3.0.0-beta.1 * @license MIT * @link https://farbelous.github.io/bootstrap-colorpicker/ * @link https://github.com/farbelous/bootstrap-colorpicker.git */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("jQuery")); else if(typeof define === 'function' && define.amd) define("bootstrap-colorpicker", ["jQuery"], factory); else if(typeof exports === 'object') exports["bootstrap-colorpicker"] = factory(require("jQuery")); else root["bootstrap-colorpicker"] = factory(root["jQuery"]); })(this, function(__WEBPACK_EXTERNAL_MODULE_0__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 3); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_0__; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 _jquery = __webpack_require__(0); var _jquery2 = _interopRequireDefault(_jquery); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Colorpicker extension class. */ var Extension = function () { /** * @param {Colorpicker} colorpicker * @param {Object} options */ function Extension(colorpicker) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, Extension); /** * @type {Colorpicker} */ this.colorpicker = colorpicker; /** * @type {Object} */ this.options = options; if (!(this.colorpicker.element && this.colorpicker.element.length)) { throw new Error('Extension: this.colorpicker.element is not valid'); } this.colorpicker.element.on('colorpickerCreate.colorpicker-ext', _jquery2.default.proxy(this.onCreate, this)); this.colorpicker.element.on('colorpickerDestroy.colorpicker-ext', _jquery2.default.proxy(this.onDestroy, this)); this.colorpicker.element.on('colorpickerUpdate.colorpicker-ext', _jquery2.default.proxy(this.onUpdate, this)); this.colorpicker.element.on('colorpickerChange.colorpicker-ext', _jquery2.default.proxy(this.onChange, this)); this.colorpicker.element.on('colorpickerInvalid.colorpicker-ext', _jquery2.default.proxy(this.onInvalid, this)); this.colorpicker.element.on('colorpickerShow.colorpicker-ext', _jquery2.default.proxy(this.onShow, this)); this.colorpicker.element.on('colorpickerHide.colorpicker-ext', _jquery2.default.proxy(this.onHide, this)); this.colorpicker.element.on('colorpickerEnable.colorpicker-ext', _jquery2.default.proxy(this.onEnable, this)); this.colorpicker.element.on('colorpickerDisable.colorpicker-ext', _jquery2.default.proxy(this.onDisable, this)); } /** * Function called every time a new color needs to be created. * Return false to skip this resolver and continue with other extensions' ones * or return anything else to consider the color resolved. * * @param {Color|String|*} color * @return {Color|String|*} */ _createClass(Extension, [{ key: 'resolveColor', value: function resolveColor(color) { return false; } /** * @listens Colorpicker#colorpickerCreate * @param {Event} event */ }, { key: 'onCreate', value: function onCreate(event) {} // to be extended /** * @listens Colorpicker#colorpickerDestroy * @param {Event} event */ }, { key: 'onDestroy', value: function onDestroy(event) { this.colorpicker.element.off('.colorpicker-ext'); } /** * @listens Colorpicker#colorpickerUpdate * @param {Event} event */ }, { key: 'onUpdate', value: function onUpdate(event) {} // to be extended /** * @listens Colorpicker#colorpickerChange * @param {Event} event */ }, { key: 'onChange', value: function onChange(event) {} // to be extended /** * @listens Colorpicker#colorpickerInvalid * @param {Event} event */ }, { key: 'onInvalid', value: function onInvalid(event) {} // to be extended /** * @listens Colorpicker#colorpickerHide * @param {Event} event */ }, { key: 'onHide', value: function onHide(event) {} // to be extended /** * @listens Colorpicker#colorpickerShow * @param {Event} event */ }, { key: 'onShow', value: function onShow(event) {} // to be extended /** * @listens Colorpicker#colorpickerDisable * @param {Event} event */ }, { key: 'onDisable', value: function onDisable(event) {} // to be extended /** * @listens Colorpicker#colorpickerEnable * @param {Event} event */ }, { key: 'onEnable', value: function onEnable(event) { // to be extended } }]); return Extension; }(); exports.default = Extension; /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; 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 _Extension2 = __webpack_require__(1); var _Extension3 = _interopRequireDefault(_Extension2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } var defaults = { /** * Key-value pairs defining a color alias and its CSS color representation. * * They can also be just an array of values. In that case, no special names are used, only the real colors. * * @type {Object|Array} * @default null * @example * { * 'black': '#000000', * 'white': '#ffffff', * 'red': '#FF0000', * 'default': '#777777', * 'primary': '#337ab7', * 'success': '#5cb85c', * 'info': '#5bc0de', * 'warning': '#f0ad4e', * 'danger': '#d9534f' * } * * @example ['#f0ad4e', '#337ab7', '#5cb85c'] */ colors: null, /** * If true, the when a color swatch is selected the name (alias) will be used as input value, * otherwise the swatch real color value will be used. * * @type {boolean} * @default true */ namesAsValues: true }; var Palette = function (_Extension) { _inherits(Palette, _Extension); _createClass(Palette, [{ key: 'colors', /** * @returns {Object|Array} */ get: function get() { return this.options.colors; } }]); function Palette(colorpicker) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, Palette); var _this = _possibleConstructorReturn(this, (Palette.__proto__ || Object.getPrototypeOf(Palette)).call(this, colorpicker, Object.assign({}, defaults, options))); if (!Array.isArray(_this.options.colors) && _typeof(_this.options.colors) !== 'object') { _this.options.colors = null; } return _this; } /** * @returns {int} */ _createClass(Palette, [{ key: 'getLength', value: function getLength() { if (!this.options.colors) { return 0; } if (Array.isArray(this.options.colors)) { return this.options.colors.length; } if (_typeof(this.options.colors) === 'object') { return Object.keys(this.options.colors).length; } return 0; } }, { key: 'resolveColor', value: function resolveColor(color) { if (this.getLength() <= 0) { return false; } if (Array.isArray(this.options.colors)) { if (this.options.colors.indexOf(color) >= 0) { return color; } if (this.options.colors.indexOf(color.toUpperCase()) >= 0) { return color.toUpperCase(); } if (this.options.colors.indexOf(color.toLowerCase()) >= 0) { return color.toLowerCase(); } return false; } if (_typeof(this.options.colors) !== 'object') { return false; } if (!this.options.namesAsValues) { return this.getValue(color, false); } return this.getName(color, this.getName('#' + color, this.getValue(color, false))); } /** * Given a color value, returns the corresponding color name or defaultValue. * * @param {String} value * @param {*} defaultValue * @returns {*} */ }, { key: 'getName', value: function getName(value) { var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!(typeof value === 'string') || !this.options.colors) { return defaultValue; } for (var name in this.options.colors) { if (!this.options.colors.hasOwnProperty(name)) { continue; } if (this.options.colors[name].toLowerCase() === value.toLowerCase()) { return name; } } return defaultValue; } /** * Given a color name, returns the corresponding color value or defaultValue. * * @param {String} name * @param {*} defaultValue * @returns {*} */ }, { key: 'getValue', value: function getValue(name) { var defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!(typeof name === 'string') || !this.options.colors) { return defaultValue; } if (this.options.colors.hasOwnProperty(name)) { return this.options.colors[name]; } return defaultValue; } }]); return Palette; }(_Extension3.default); exports.default = Palette; /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; var _Colorpicker = __webpack_require__(4); var _Colorpicker2 = _interopRequireDefault(_Colorpicker); var _jquery = __webpack_require__(0); var _jquery2 = _interopRequireDefault(_jquery); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var plugin = 'colorpicker'; _jquery2.default[plugin] = _Colorpicker2.default; _jquery2.default.fn[plugin] = function (option) { var apiArgs = Array.prototype.slice.call(arguments, 1), isSingleElement = this.length === 1, returnValue = null; var $jq = this.each(function () { var $this = (0, _jquery2.default)(this), inst = $this.data(plugin), options = (typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object' ? option : {}; if (!inst) { inst = new _Colorpicker2.default(this, options); $this.data(plugin, inst); } if (typeof option === 'string') { if (option === 'colorpicker') { returnValue = inst; } else if (_jquery2.default.isFunction(inst[option])) { returnValue = inst[option].apply(inst, apiArgs); } else { // its a property ? if (apiArgs.length) { // set property inst[option] = apiArgs[0]; } returnValue = inst[option]; } } else { returnValue = $this; } }); return isSingleElement ? returnValue : $jq; }; _jquery2.default.fn[plugin].constructor = _Colorpicker2.default; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 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 _Color = __webpack_require__(5); var _Color2 = _interopRequireDefault(_Color); var _Extension = __webpack_require__(1); var _Extension2 = _interopRequireDefault(_Extension); var _options = __webpack_require__(7); var _options2 = _interopRequireDefault(_options); var _extensions = __webpack_require__(8); var _extensions2 = _interopRequireDefault(_extensions); var _jquery = __webpack_require__(0); var _jquery2 = _interopRequireDefault(_jquery); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var colorPickerIdCounter = 0; /** * Colorpicker widget class */ var Colorpicker = function () { _createClass(Colorpicker, [{ key: 'color', /** * color getter * * @type {Color|null} */ get: function get() { return this.element.data('color'); } /** * color setter * * @ignore * @param {Color|null} value */ , set: function set(value) { this.element.data('color', value); } /** * @fires Colorpicker#colorpickerCreate * @param {Object|String} element * @param {Object} options * @constructor */ }], [{ key: 'Color', /** * Color class * * @static * @type {Color} */ get: function get() { return _Color2.default; } /** * Extension class * * @static * @type {Extension} */ }, { key: 'Extension', get: function get() { return _Extension2.default; } /** * Colorpicker bundled extension classes * * @static * @type {{Extension}} */ }, { key: 'Extensions', get: function get() { return _extensions2.default; } }]); function Colorpicker(element, options) { var _this = this; _classCallCheck(this, Colorpicker); colorPickerIdCounter += 1; /** * The colorpicker instance number * @type {number} */ this.id = colorPickerIdCounter; /** * @type {*|jQuery} */ this.element = (0, _jquery2.default)(element).addClass('colorpicker-element'); this.element.attr('data-colorpicker-id', this.id); /** * @type {defaults} */ this.options = Object.assign({}, _options2.default, options, this.element.data()); /** * @type {Extension[]} */ this.extensions = []; if (!Array.isArray(this.options.extensions)) { this.options.extensions = []; } /** * @type {*|jQuery} */ this.component = this.options.component; this.component = this.component !== false ? this.element.find(this.component) : false; if (this.component && this.component.length === 0) { this.component = false; } /** * @type {*|jQuery} */ this.container = this.options.container === true ? this.element : this.options.container; this.container = this.container !== false ? (0, _jquery2.default)(this.container) : false; /** * @type {*|String} * @private */ this.currentSlider = null; /** * @type {{left: number, top: number}} * @private */ this.mousePointer = { left: 0, top: 0 }; /** * Latest external event * * @type {{name: String, e: *}} * @private */ this.lastEvent = { name: null, e: null }; // Is the element an input? Should we search inside for any input? /** * @type {*|jQuery} */ this.input = this.element.is('input') ? this.element : this.options.input ? this.element.find(this.options.input) : false; if (this.input && this.input.length === 0) { this.input = false; } if (this.options.debug) { this.options.extensions.push({ name: 'Debugger' }); } // Register extensions this.options.extensions.forEach(function (ext) { _this.addExtension(ext.name, _extensions2.default[ext.name.toLowerCase()], ext); }); var colorValue = this.options.color !== false ? this.options.color : this.getValue(); this.color = colorValue ? this.createColor(colorValue) : false; if (this.options.format === false) { // If format is false, use the first parsed one from now on this.options.format = this.color.format; } /** * @type {boolean} * @private */ this.disabled = false; // Setup picker var $picker = this.picker = (0, _jquery2.default)(this.options.template); if (this.options.customClass) { $picker.addClass(this.options.customClass); } if (this.options.inline) { $picker.addClass('colorpicker-inline colorpicker-visible'); } else { $picker.addClass('colorpicker-hidden'); } if (this.options.horizontal) { $picker.addClass('colorpicker-horizontal'); } if ((this.options.useAlpha || this.hasColor() && this.color.hasTransparency()) && this.options.useAlpha !== false) { this.options.useAlpha = true; $picker.addClass('colorpicker-with-alpha'); } if (this.options.align === 'right') { $picker.addClass('colorpicker-right'); } if (this.options.inline === true) { $picker.addClass('colorpicker-no-arrow'); } // Prevent closing the colorpicker when clicking on itself $picker.on('mousedown.colorpicker touchstart.colorpicker', _jquery2.default.proxy(function (e) { if (e.target === e.currentTarget) { e.preventDefault(); } }, this)); // Bind click/tap events on the sliders $picker.find('.colorpicker-saturation, .colorpicker-hue, .colorpicker-alpha').on('mousedown.colorpicker touchstart.colorpicker', _jquery2.default.proxy(this._mousedown, this)); $picker.appendTo(this.container ? this.container : (0, _jquery2.default)('body')); // Bind other events if (this.hasInput()) { this.input.on({ 'keyup.colorpicker': _jquery2.default.proxy(this._keyup, this) }); this.input.on({ 'change.colorpicker': _jquery2.default.proxy(this._change, this) }); if (this.component === false) { this.element.on({ 'focus.colorpicker': _jquery2.default.proxy(this.show, this) }); } if (this.options.inline === false) { this.element.on({ 'focusout.colorpicker': _jquery2.default.proxy(this.hide, this) }); } } if (this.component !== false) { this.component.on({ 'click.colorpicker': _jquery2.default.proxy(this.show, this) }); } if (this.hasInput() === false && this.component === false && !this.element.has('.colorpicker')) { this.element.on({ 'click.colorpicker': _jquery2.default.proxy(this.show, this) }); } // for HTML5 input[type='color'] if (this.hasInput() && this.component !== false && this.input.attr('type') === 'color') { this.input.on({ 'click.colorpicker': _jquery2.default.proxy(this.show, this), 'focus.colorpicker': _jquery2.default.proxy(this.show, this) }); } // Update if there is a color option this.update(this.options.color !== false); (0, _jquery2.default)(_jquery2.default.proxy(function () { /** * (Colorpicker) When the Colorpicker instance has been created and the DOM is ready. * * @event Colorpicker#colorpickerCreate */ this.element.trigger({ type: 'colorpickerCreate', colorpicker: this, color: this.color }); }, this)); } /** * Creates and registers the given extension * * @param {String|Extension} extensionName * @param {Extension} ExtensionClass * @param {Object} [config] * @returns {Extension} */ _createClass(Colorpicker, [{ key: 'addExtension', value: function addExtension(extensionName, ExtensionClass) { var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var ext = extensionName instanceof _Extension2.default ? extensionName : new ExtensionClass(this, config); this.extensions.push(ext); return ext; } /** * Destroys the current instance * * @fires Colorpicker#colorpickerDestroy */ }, { key: 'destroy', value: function destroy() { this.picker.remove(); this.element.removeData('colorpicker', 'color').off('.colorpicker'); if (this.hasInput()) { this.input.off('.colorpicker'); } if (this.component !== false) { this.component.off('.colorpicker'); } this.element.removeClass('colorpicker-element'); /** * (Colorpicker) When the instance is destroyed with all events unbound. * * @event Colorpicker#colorpickerDestroy */ this.element.trigger({ type: 'colorpickerDestroy', colorpicker: this, color: this.color }); } /** * Returns true if the current color object is an instance of Color, false otherwise. * @returns {boolean} */ }, { key: 'hasColor', value: function hasColor() { return this.color instanceof _Color2.default; } /** * @returns {*|String|Color} */ }, { key: 'toInputColorString', /** * Formatted color string, with the formatting options applied * (e.g. useHashPrefix) * @returns {String} */ value: function toInputColorString() { var str = this.toCssColorString(); if (!str) { return str; } if (this.options.useHashPrefix === false) { str = str.replace(/^#/g, ''); } return this._resolveColor(str); } /** * Formatted color string, suitable for CSS * @returns {String} */ }, { key: 'toCssColorString', value: function toCssColorString() { if (!this.hasColor()) { return ''; } return this.color.toString(this.format); } /** * If the widget is not inside a container or inline, rearranges its position relative to its element offset. * * @param {Event} [e] * @private * @returns {boolean} Returns false if the widget is inside a container or inline, true otherwise */ }, { key: '_reposition', value: function _reposition(e) { this.lastEvent.name = 'reposition'; this.lastEvent.e = e; if (this.options.inline !== false || this.options.container) { return false; } var type = this.container && this.container[0] !== window.document.body ? 'position' : 'offset'; var element = this.component || this.element; var offset = element[type](); if (this.options.align === 'right') { offset.left -= this.picker.outerWidth() - element.outerWidth(); } this.picker.css({ top: offset.top + element.outerHeight(), left: offset.left }); return true; } /** * Shows the colorpicker widget if hidden. * If the input is disabled this call will be ignored. * * @fires Colorpicker#colorpickerShow * @param {Event} [e] * @returns {boolean} True if was hidden and afterwards visible, false if nothing happened. */ }, { key: 'show', value: function show(e) { this.lastEvent.name = 'show'; this.lastEvent.e = e; if (this.isVisible() || this.isDisabled()) { // Don't show the widget if it's already visible or it is disabled return false; } this.picker.addClass('colorpicker-visible').removeClass('colorpicker-hidden'); this._reposition(e); (0, _jquery2.default)(window).on('resize.colorpicker', _jquery2.default.proxy(this._reposition, this)); if (e && (!this.hasInput() || this.input.attr('type') === 'color')) { if (e.stopPropagation && e.preventDefault) { e.stopPropagation(); e.preventDefault(); } } if ((this.component || !this.input) && this.options.inline === false) { (0, _jquery2.default)(window.document).on({ 'mousedown.colorpicker': _jquery2.default.proxy(this.hide, this) }); } /** * (Colorpicker) When show() is called and the widget can be shown. * * @event Colorpicker#colorpickerShow */ this.element.trigger({ type: 'colorpickerShow', colorpicker: this, color: this.color }); return true; } /** * Hides the colorpicker widget. * Hide is prevented when it is triggered by an event whose target element has been clicked/touched. * * @fires Colorpicker#colorpickerHide * @param {Event} [e] * @returns {boolean} True if was visible and afterwards hidden, false if nothing happened. */ }, { key: 'hide', value: function hide(e) { this.lastEvent.name = 'hide'; this.lastEvent.e = e; if (this.isHidden()) { // Do not trigger if already hidden return false; } if (typeof e !== 'undefined' && e.target) { // Prevent hide if triggered by an event and an element inside the colorpicker has been clicked/touched if ((0, _jquery2.default)(e.currentTarget).parents('.colorpicker').length > 0 || (0, _jquery2.default)(e.target).parents('.colorpicker').length > 0) { return false; } } this.picker.addClass('colorpicker-hidden').removeClass('colorpicker-visible'); (0, _jquery2.default)(window).off('resize.colorpicker', this._reposition); (0, _jquery2.default)(window.document).off({ 'mousedown.colorpicker': this.hide }); /** * (Colorpicker) When hide() is called and the widget can be hidden. * * @event Colorpicker#colorpickerHide */ this.element.trigger({ type: 'colorpickerHide', colorpicker: this, color: this.color }); return true; } /** * Returns true if the colorpicker element has the colorpicker-visible class and not the colorpicker-hidden one. * False otherwise. * * @returns {boolean} */ }, { key: 'isVisible', value: function isVisible() { return this.picker.hasClass('colorpicker-visible') && !this.picker.hasClass('colorpicker-hidden'); } /** * Returns true if the colorpicker element has the colorpicker-hidden class and not the colorpicker-visible one. * False otherwise. * * @returns {boolean} */ }, { key: 'isHidden', value: function isHidden() { return this.picker.hasClass('colorpicker-hidden') && !this.picker.hasClass('colorpicker-visible'); } /** * If the input element is present, it updates the value with the current color object color string. * If value is set, this method fires a "change" event on the input element. * * @fires Colorpicker#change * @private */ }, { key: '_updateInput', value: function _updateInput() { if (this.hasInput()) { var val = this.toInputColorString(); if (val === this.input.prop('value')) { // No need to set value or trigger any event if nothing changed return; } this.input.prop('value', val ? val : ''); /** * (Input) Triggered on the input element when a new color is selected. * * @event Colorpicker#change */ this.input.trigger({ type: 'change', colorpicker: this, color: this.color, value: val }); } } /** * Changes the color adjustment bars using the current color object information. * @private */ }, { key: '_updatePicker', value: function _updatePicker() { if (!this.hasColor()) { return; } var vertical = this.options.horizontal === false, sl = vertical ? this.options.sliders : this.options.slidersHorz; var saturationGuide = this.picker.find('.colorpicker-saturation .colorpicker-guide'), hueGuide = this.picker.find('.colorpicker-hue .colorpicker-guide'), alphaGuide = this.picker.find('.colorpicker-alpha .colorpicker-guide'); var hsva = this.color.hsvaRatio; if (hueGuide.length) { hueGuide.css(vertical ? 'top' : 'left', (vertical ? sl.hue.maxTop : sl.hue.maxLeft) * (1 - hsva.h)); } if (alphaGuide.length) { alphaGuide.css(vertical ? 'top' : 'left', (vertical ? sl.alpha.maxTop : sl.alpha.maxLeft) * (1 - hsva.a)); } if (saturationGuide.length) { saturationGuide.css({ 'top': sl.saturation.maxTop - hsva.v * sl.saturation.maxTop, 'left': hsva.s * sl.saturation.maxLeft }); } this.picker.find('.colorpicker-saturation').css('backgroundColor', this.color.getHueOnlyCopy().toHexString()); // we only need hue this.picker.find('.colorpicker-alpha').css('backgroundColor', this.color.toString('hex6')); // we don't need alpha } /** * If the component element is present, its background color is updated * @private */ }, { key: '_updateComponent', value: function _updateComponent() { if (!this.hasColor()) { return; } if (this.component !== false) { var icn = this.component.find('i').eq(0); if (icn.length > 0) { icn.css({ 'backgroundColor': this.toCssColorString() }); } else { this.component.css({ 'backgroundColor': this.toCssColorString() }); } } } /** * @private * @returns {boolean} */ }, { key: '_shouldUpdate', value: function _shouldUpdate() { return this.hasColor() && this.getValue(false) !== false; } /** * Updated the component color, the input value and the widget if a color is present. * * If force is true, it is updated anyway. * * @fires Colorpicker#colorpickerUpdate * @param {boolean} [force] */ }, { key: 'update', value: function update() { var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; if (this._shouldUpdate() || force === true) { // Update only if the current value (from input or data) is not empty this._updateComponent(); // Do not update input when autoInputFallback is disabled and last event is keyup. var preventInputUpdate = this.options.autoInputFallback !== true && // this.isInvalidColor() || // prevent also on invalid color (on create, leaves invalid colors) this.lastEvent.name === 'keyup'; if (!preventInputUpdate) { this._updateInput(); } this._updatePicker(); /** * (Colorpicker) Fired when the widget is updated. * * @event Colorpicker#colorpickerUpdate */ this.element.trigger({ type: 'colorpickerUpdate', colorpicker: this, color: this.color }); } } /** * Returns the color string from the input value or the 'data-color' attribute of the input or element. * If empty, it returns the defaultValue parameter. * * @param {String|*} [defaultValue] * @returns {String|*} */ }, { key: 'getValue', value: function getValue() { var defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; defaultValue = typeof defaultValue === 'undefined' ? this.fallbackColor : defaultValue; var candidates = [], val = false; if (this.hasInput()) { candidates.push(this.input.val()); candidates.push(this.input.data('color')); } candidates.push(this.element.data('color')); candidates.map(function (item) { if (item && val === false) { val = item; } }); val = val === false ? defaultValue : val; if (val instanceof _Color2.default) { return val.toString(this.format); } return val; } /** * Sets the color manually * * @fires Colorpicker#colorpickerChange * @param {String|Color} val */ }, { key: 'setValue', value: function setValue(val) { if (this.hasColor() && this.color.equals(val)) { // equal color object return; } var color = val ? this.createColor(val) : false; if (!this.hasColor() && !color) { // color was empty and the new one too return; } // force update if color is changed to empty var shouldForceUpdate = this.hasColor() && !color; this.color = color; /** * (Colorpicker) When the color is set programmatically with setValue(). * * @event Colorpicker#colorpickerChange */ this.element.trigger({ type: 'colorpickerChange', colorpicker: this, color: this.color, value: val }); // force update if color has changed to empty this.update(shouldForceUpdate); } /** * Creates a new color using the widget instance options (fallbackColor, format). * * @fires Colorpicker#colorpickerInvalid * @param {*} val * @param {boolean} useFallback * @returns {Color} */ }, { key: 'createColor', value: function createColor(val) { var useFallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var color = new _Color2.default(this._resolveColor(val), { format: this.format }); if (!color.isValid()) { var invalidColor = color, fallback = void 0; if (useFallback) { fallback = this.fallbackColor instanceof _Color2.default && this.fallbackColor.isValid() ? this.fallbackColor : this._resolveColor(this.fallbackColor); color = new _Color2.default(fallback, { format: this.format }); if (!color.isValid() && useFallback) { throw new Error('The fallback color is invalid.'); } } color.previous = invalidColor; /** * (Colorpicker) Fired when the color is invalid and the fallback color is going to be used. * * @event Colorpicker#colorpickerInvalid */ this.element.trigger({ type: 'colorpickerInvalid', colorpicker: this, color: color, value: val }); } if (!this.isAlphaEnabled() && color.hasTransparency()) { // Alpha is disabled color.setAlpha(1); } if (!this.hasColor()) { // No previous color, so no need to compare return color; } var hsva = color.hsvaRatio; var prevHsva = this.color.hsvaRatio; if (hsva.s === 0 && hsva.h === 0 && prevHsva.h !== 0) { // Hue was set to 0 because saturation was 0, use previous hue, since it was not meant to change... color.setHueRatio(prevHsva.h); } if (!this.isAlphaEnabled() && color.hasTransparency()) { // Alpha is disabled color.setAlpha(1); } return color; } /** * Checks if there is a color object, that it is valid and it is not a fallback * @returns {boolean} */ }, { key: 'isInvalidColor', value: function isInvalidColor() { return !this.hasColor() || !this.color.isValid() || !!this.color.previous; } /** * Returns true if the useAlpha option is exactly true, false otherwise * @returns {boolean} */ }, { key: 'isAlphaEnabled', value: function isAlphaEnabled() { return this.options.useAlpha === true; } /** * Resolves a color, in case is not in a standard format (e.g. a custom color alias) * * @private * @param {String|*} color * @returns {String|*|null} */ }, { key: '_resolveColor', value: function _resolveColor(color) { var extResolvedColor = false; _jquery2.default.each(this.extensions, function (name, ext) { if (extResolvedColor !== false) { // skip if resolved return; } extResolvedColor = ext.resolveColor(color); }); if (extResolvedColor !== false) { color = extResolvedColor; } return color; } /** * Returns true if the widget has an associated input element, false otherwise * @returns {boolean} */ }, { key: 'hasInput', value: function hasInput() { return this.input !== false; } /** * Returns true if this instance is disabled * @returns {boolean} */ }, { key: 'isDisabled', value: function isDisabled() { return this.disabled === true; } /** * Disables the widget and the input if any * * @fires Colorpicker#colorpickerDisable * @returns {boolean} */ }, { key: 'disable', value: function disable() { if (this.hasInput()) { this.input.prop('disabled', true); } this.disabled = true; /** * (Colorpicker) When the widget has been disabled. * * @event Colorpicker#colorpickerDisable */ this.element.trigger({ type: 'colorpickerDisable', colorpicker: this, color: this.color }); return true; } /** * Enables the widget and the input if any * * @fires Colorpicker#colorpickerEnable * @returns {boolean} */ }, { key: 'enable', value: function enable() { if (this.hasInput()) { this.input.prop('disabled', false); } this.disabled = false; /** * (Colorpicker) When the widget has been enabled. * * @event Colorpicker#colorpickerEnable */ this.element.trigger({ type: 'colorpickerEnable', colorpicker: this, color: this.color }); return true; } /** * Function triggered when clicking in one of the color adjustment bars * * @private * @fires Colorpicker#mousemove * @param {Event} e * @returns {boolean} */ }, { key: '_mousedown', value: function _mousedown(e) { this.lastEvent.name = 'mousedown'; this.lastEvent.e = e; if (!e.pageX && !e.pageY && e.originalEvent && e.originalEvent.touches) { e.pageX = e.originalEvent.touches[0].pageX; e.pageY = e.originalEvent.touches[0].pageY; } e.stopPropagation(); e.preventDefault(); var target = (0, _jquery2.default)(e.target); // detect the slider and set the limits and callbacks var zone = target.closest('div'); var sl = this.options.horizontal ? this.options.slidersHorz : this.options.sliders; if (!zone.is('.colorpicker')) { if (zone.is('.colorpicker-saturation')) { this.currentSlider = _jquery2.default.extend({}, sl.saturation); } else if (zone.is('.colorpicker-hue')) { this.currentSlider = _jquery2.default.extend({}, sl.hue); } else if (zone.is('.colorpicker-alpha')) { this.currentSlider = _jquery2.default.extend({}, sl.alpha); } else { return false; } var offset = zone.offset(); // reference to guide's style this.currentSlider.guide = zone.find('.colorpicker-guide')[0].style; this.currentSlider.left = e.pageX - offset.left; this.currentSlider.top = e.pageY - offset.top; this.mousePointer = { left: e.pageX, top: e.pageY }; /** * (window.document) Triggered on mousedown for the document object, * so the color adjustment guide is moved to the clicked position. * * @event Colorpicker#mousemove */ (0, _jquery2.default)(window.document).on({ 'mousemove.colorpicker': _jquery2.default.proxy(this._mousemove, this), 'touchmove.colorpicker': _jquery2.default.proxy(this._mousemove, this), 'mouseup.colorpicker': _jquery2.default.proxy(this._mouseup, this), 'touchend.colorpicker': _jquery2.default.proxy(this._mouseup, this) }).trigger('mousemove'); } return false; } /** * Function triggered when dragging a guide inside one of the color adjustment bars. * * @private * @param {Event} e * @returns {boolean} */ }, { key: '_mousemove', value: function _mousemove(e) { this.lastEvent.name = 'mousemove'; this.lastEvent.e = e; var color = !this.hasColor() ? this.createColor(this.fallbackColor) : this.color.getCopy(); if (!e.pageX && !e.pageY && e.originalEvent && e.originalEvent.touches) { e.pageX = e.originalEvent.touches[0].pageX; e.pageY = e.originalEvent.touches[0].pageY; } e.stopPropagation(); e.preventDefault(); var left = Math.max(0, Math.min(this.currentSlider.maxLeft, this.currentSlider.left + ((e.pageX || this.mousePointer.left) - this.mousePointer.left))); var top = Math.max(0, Math.min(this.currentSlider.maxTop, this.currentSlider.top + ((e.pageY || this.mousePointer.top) - this.mousePointer.top))); this.currentSlider.guide.left = left + 'px'; this.currentSlider.guide.top = top + 'px'; if (this.currentSlider.callLeft) { color[this.currentSlider.callLeft].call(color, left / this.currentSlider.maxLeft); } if (this.currentSlider.callTop) { color[this.currentSlider.callTop].call(color, top / this.currentSlider.maxTop); } this.setValue(color); return false; } /** * Function triggered when releasing the click in one of the color adjustment bars. * * @private * @param {Event} e * @returns {boolean} */ }, { key: '_mouseup', value: function _mouseup(e) { this.lastEvent.name = 'mouseup'; this.lastEvent.e = e; e.stopPropagation(); e.preventDefault(); (0, _jquery2.default)(window.document).off({ 'mousemove.colorpicker': this._mousemove, 'touchmove.colorpicker': this._mousemove, 'mouseup.colorpicker': this._mouseup, 'touchend.colorpicker': this._mouseup }); return false; } /** * Function triggered when the input has changed, so the colorpicker gets updated. * * @private * @param {Event} e * @returns {boolean} */ }, { key: '_change', value: function _change(e) { this.lastEvent.name = 'change'; this.lastEvent.e = e; var val = this.input.val(); if (val !== this.toInputColorString()) { this.setValue(val); } } /** * Function triggered after a keyboard key has been released. * * @private * @param {Event} e * @returns {boolean} */ }, { key: '_keyup', value: function _keyup(e) { this.lastEvent.name = 'keyup'; this.lastEvent.e = e; var val = this.input.val(); if (val !== this.toInputColorString()) {