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); } }; }