diff --git a/package.json b/package.json index 6d09021..f77d44f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "src/piklor.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "min": "uglifyjs src/piklor.js > src/piklor.min.js", + "min": "uglifyjs src/piklor.js -c -m > src/piklor.min.js", "update-min": "cp src/piklor.min.js example/js/piklor.js && git add example && git commit -m 'Updated piklor.js in the example dir' .", "deploy": "cp -r example ../_tmp && git checkout gh-pages && cp -r ../_tmp/* . && git add . -A && git commit -m 'Rebuild.' && rm -rf ../_tmp ../_tmp.js" }, @@ -30,4 +30,4 @@ "devDependencies": { "uglifyjs": "^2.4.10" } -} \ No newline at end of file +} diff --git a/src/piklor.min.js b/src/piklor.min.js index 30680c9..f29eec4 100644 --- a/src/piklor.min.js +++ b/src/piklor.min.js @@ -1 +1 @@ -(function(root){function Piklor(sel,colors,options){var self=this;options=options||{};options.open=self.getElm(options.open);options.openEvent=options.openEvent||"click";options.style=Object(options.style);options.style.display=options.style.display||"block";options.closeOnBlur=options.closeOnBlur||false;options.template=options.template||'
';self.elm=self.getElm(sel);self.cbs=[];self.isOpen=true;self.colors=colors;self.options=options;self.render();if(options.open){options.open.addEventListener(options.openEvent,function(ev){self.isOpen?self.close():self.open()})}self.elm.addEventListener("click",function(ev){var col=ev.target.getAttribute("data-col");if(!col){return}self.set(col);self.close()});if(options.closeOnBlur){window.addEventListener("click",function(ev){if(ev.target!=options.open&&ev.target!=self.elm&&self.isOpen){self.close()}})}if(options.autoclose!==false){self.close()}}Piklor.prototype.getElm=function(el){if(typeof el==="string"){return document.querySelector(el)}return el};Piklor.prototype.render=function(){var self=this,html="";self.colors.forEach(function(c){html+=self.options.template.replace(/\{color\}/g,c)});self.elm.innerHTML=html};Piklor.prototype.close=function(){this.elm.style.display="none";this.isOpen=false};Piklor.prototype.open=function(){this.elm.style.display=this.options.style.display;this.isOpen=true};Piklor.prototype.colorChosen=function(cb){this.cbs.push(cb)};Piklor.prototype.set=function(c,p){var self=this;self.color=c;if(p===false){return}self.cbs.forEach(function(cb){cb.call(self,c)})};root.Piklor=Piklor})(this); \ No newline at end of file +!function(e){function t(e,t,o){var n=this;o=o||{},o.open=n.getElm(o.open),o.openEvent=o.openEvent||"click",o.style=Object(o.style),o.style.display=o.style.display||"block",o.closeOnBlur=o.closeOnBlur||!1,o.template=o.template||'
',n.elm=n.getElm(e),n.cbs=[],n.isOpen=!0,n.colors=t,n.options=o,n.render(),o.open&&o.open.addEventListener(o.openEvent,function(e){n.isOpen?n.close():n.open()}),n.elm.addEventListener("click",function(e){var t=e.target.getAttribute("data-col");t&&(n.set(t),n.close())}),o.closeOnBlur&&window.addEventListener("click",function(e){e.target!=o.open&&e.target!=n.elm&&n.isOpen&&n.close()}),o.autoclose!==!1&&n.close()}t.prototype.getElm=function(e){return"string"==typeof e?document.querySelector(e):e},t.prototype.render=function(){var e=this,t="";e.colors.forEach(function(o){t+=e.options.template.replace(/\{color\}/g,o)}),e.elm.innerHTML=t},t.prototype.close=function(){this.elm.style.display="none",this.isOpen=!1},t.prototype.open=function(){this.elm.style.display=this.options.style.display,this.isOpen=!0},t.prototype.colorChosen=function(e){this.cbs.push(e)},t.prototype.set=function(e,t){var o=this;o.color=e,t!==!1&&o.cbs.forEach(function(t){t.call(o,e)})},e.Piklor=t}(this);