/* * @copyright 2022 Matias De lellis * * @author 2022 Matias De lellis * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ 'use strict'; function QnColorPick(parentSelector, onSelectColor) { this._parentSelector = parentSelector; this._onSelectColor = onSelectColor; this._color = undefined; this._template = '' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
'; this.select = function (hexcolor) { this._color = hexcolor; }; this.close = function () { var picker = document.getElementById("colorPickWrapper"); picker.remove(); }; this.show = function (hexcolor) { var self = this; var parent = document.querySelector(this._parentSelector); parent.innerHTML += this._template; var colors = document.querySelectorAll(".colorPickButton"); colors.forEach (function(color) { if (hexcolor == color.getAttribute("hexvalue")) { color.classList.add("icon-checkmark"); } color.addEventListener("click", function () { self._color = color.getAttribute("hexvalue"); self._onSelectColor(self._color); self.close (); }); }); }; this.isVisible = function () { var picker = document.getElementById("colorPickWrapper"); return picker != null; }; this.toggle = function () { if (this.isVisible()) { this.close(); } else { this.show(this._color); } }; }