/* * * ColorPick jQuery plugin * https://github.com/philzet/ColorPick.js * * Copyright (c) 2017-2019 Phil Zet (a.k.a. Phil Zakharchenko) * Licensed under the MIT License * */ !function(c){c.fn.colorPick=function(o){return this.each(function(){new c.colorPick(this,o||{})})},c.colorPick=function(o,e){e=e||{},this.options=c.extend({},c.fn.colorPick.defaults,e),e.str&&(this.options.str=c.extend({},c.fn.colorPick.defaults.str,e.str)),c.fn.colorPick.defaults=this.options,this.color=this.options.initialColor.toUpperCase(),this.element=c(o);o=this.element.data("initialcolor");o&&(this.color=o,this.appendToStorage(this.color));var t=[];return c.each(c.fn.colorPick.defaults.palette.map(function(o){return o.toUpperCase()}),function(o,e){-1===c.inArray(e,t)&&t.push(e)}),this.palette=t,this.element.hasClass(this.options.pickrclass)?this:this.init()},c.fn.colorPick.defaults={initialColor:"#2DAF63B5",paletteLabel:"",allowRecent:!1,recentMax:5,allowCustomColor:!1,palette:["#2ecc71","#27ae60","#3498db","#2980b9","#9b59b6","#f39c12","#e67e22","#d35400","#e74c3c","#c0392b","#ecf0f1","#bdc3c7","#95a5a6","#7f8c8d","#cae5e1","#eadec9","#eadef7","#bedbe1","#98aae7","#ffdfd8","#d1f3c8","#ffffaa","#d2ccca","#848383","#ccccff","#9eccff","#c4acba","#f6b9b4","#d8ee3d","#62d74a"],onColorSelected:function(){this.element.css({backgroundColor:this.color,color:this.color})}},c.colorPick.prototype={init:function(){var t=this;return this.options,c.proxy(c.fn.colorPick.defaults.onColorSelected,this)(),this.element.click(function(o){return o.preventDefault(),t.show(o.pageX,o.pageY),c(".customColorHash").val(t.color),c(".colorPickButton").click(function(o){return t.color=c(o.target).attr("hexValue"),t.appendToStorage(c(o.target).attr("hexValue")),t.hide(),c.proxy(t.options.onColorSelected,t)(),!1}),c(".customColorHash").click(function(o){return!1}).keyup(function(o){var e=c(this).val();0!==e.indexOf("#")&&(e="#"+e),/(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(e)?(t.color=e,t.appendToStorage(e),c.proxy(t.options.onColorSelected,t)(),c(this).removeClass("error")):c(this).addClass("error")}),!1}).blur(function(){return t.element.val(t.color),c.proxy(t.options.onColorSelected,t)(),t.hide(),!1}),c(document).on("click",function(o){return t.hide(),!0}),this},appendToStorage:function(o){var e;!0===c.fn.colorPick.defaults.allowRecent&&(null==(e=JSON.parse(localStorage.getItem("colorPickRecentItems")))&&(e=[]),-1==c.inArray(o,e)&&(e.unshift(o),e=e.slice(0,c.fn.colorPick.defaults.recentMax),localStorage.setItem("colorPickRecentItems",JSON.stringify(e))))},show:function(o,e){c("#colorPick").remove(),c("body").append('"),jQuery.each(this.palette,function(o,e){c("#colorPick").append('
')}),!0===c.fn.colorPick.defaults.allowCustomColor&&c("#colorPick").append(''),!0===c.fn.colorPick.defaults.allowRecent&&(c("#colorPick").append('Recent:'),null==JSON.parse(localStorage.getItem("colorPickRecentItems"))||JSON.parse(localStorage.getItem("colorPickRecentItems"))==[]?c("#colorPick").append('
'):jQuery.each(JSON.parse(localStorage.getItem("colorPickRecentItems")),function(o,e){if(c("#colorPick").append('
'),o==c.fn.colorPick.defaults.recentMax-1)return!1})),c("#colorPick").fadeIn(400)},hide:function(){c("#colorPick").fadeOut(400,function(){return c("#colorPick").remove(),this})}}}(jQuery);