discourse/public/javascripts/spectrum.js

1 line
28 KiB
JavaScript
Raw Normal View History

!function(t){"use strict";"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof exports&&"object"==typeof module?module.exports=t(require("jquery")):t(jQuery)}(function(jt,Et){"use strict";function Dt(t,e,r,n){for(var a=[],i=0;i<t.length;i++){var o=t[i];if(o){var s=tinycolor(o),l=s.toHsl().l<.5?"sp-thumb-el sp-thumb-dark":"sp-thumb-el sp-thumb-light";l+=tinycolor.equals(e,o)?" sp-thumb-active":"";var c=s.toString(n.preferredFormat||"rgb"),f=Yt?"background-color:"+s.toRgbString():"filter:"+s.toFilter();a.push('<span title="'+c+'" data-color="'+s.toRgbString()+'" class="'+l+'"><span class="sp-thumb-inner" style="'+f+';" /></span>')}else{var u="sp-clear-display";a.push(jt("<div />").append(jt('<span data-color="" style="background-color:transparent;" class="'+u+'"></span>').attr("title",n.noColorSelectedText)).html())}}return"<div class='sp-cf "+r+"'>"+a.join("")+"</div>"}function It(){for(var t=0;t<Wt.length;t++)Wt[t]&&Wt[t].hide()}function zt(t,e){var r=jt.extend({},a,t);return r.callbacks={move:n(r.move,e),change:n(r.change,e),show:n(r.show,e),hide:n(r.hide,e),beforeShow:n(r.beforeShow,e)},r}function e(t,e){function n(){if(F.showPaletteOnly&&(F.showPalette=!0),xt.text(F.showPaletteOnly?F.togglePaletteMoreText:F.togglePaletteLessText),F.palette){J=F.palette.slice(0),U=jt.isArray(J[0])?J:[J],Z={};for(var t=0;t<U.length;t++)for(var e=0;e<U[t].length;e++){var r=tinycolor(U[t][e]).toRgbString();Z[r]=!0}}st.toggleClass("sp-flat",T),st.toggleClass("sp-input-disabled",!F.showInput),st.toggleClass("sp-alpha-enabled",F.showAlpha),st.toggleClass("sp-clear-enabled",qt),st.toggleClass("sp-buttons-disabled",!F.showButtons),st.toggleClass("sp-palette-buttons-disabled",!F.togglePaletteOnly),st.toggleClass("sp-palette-disabled",!F.showPalette),st.toggleClass("sp-palette-only",F.showPaletteOnly),st.toggleClass("sp-initial-disabled",!F.showInitial),st.addClass(F.className).addClass(F.containerClassName),C()}function r(){function t(t){return t.data&&t.data.ignore?(m(jt(t.target).closest(".sp-thumb-el").data("color")),_()):(m(jt(t.target).closest(".sp-thumb-el").data("color")),_(),S(!0),F.hideAfterPaletteSelect&&b()),!1}if(Xt&&st.find("*:not(input)").attr("unselectable","on"),n(),Ct&&it.after(Pt).hide(),qt||wt.hide(),T)it.after(st).hide();else{var e="parent"===F.appendTo?it.parent():jt(F.appendTo);1!==e.length&&(e=jt("body")),e.append(st)}a(),At.bind("click.spectrum touchstart.spectrum",function(t){ot||h(),t.stopPropagation(),jt(t.target).is("input")||t.preventDefault()}),(it.is(":disabled")||!0===F.disabled)&&R(),st.click(Lt),bt.change(u),bt.bind("paste",function(){setTimeout(u,1)}),bt.keydown(function(t){13==t.keyCode&&u()}),yt.text(F.cancelText),yt.bind("click.spectrum",function(t){t.stopPropagation(),t.preventDefault(),v(),b()}),wt.attr("title",F.clearText),wt.bind("click.spectrum",function(t){t.stopPropagation(),t.preventDefault(),Ot=!0,_(),T&&S(!0)}),_t.text(F.chooseText),_t.bind("click.spectrum",function(t){t.stopPropagation(),t.preventDefault(),Xt&&bt.is(":focus")&&bt.trigger("change"),w()&&(S(!0),b())}),xt.text(F.showPaletteOnly?F.togglePaletteMoreText:F.togglePaletteLessText),xt.bind("click.spectrum",function(t){t.stopPropagation(),t.preventDefault(),F.showPaletteOnly=!F.showPaletteOnly,F.showPaletteOnly||T||st.css("left","-="+(lt.outerWidth(!0)+5)),n()}),Kt(pt,function(t,e,r){Q=t/V,Ot=!1,r.shiftKey&&(Q=Math.round(10*Q)/10),_()},s,l),Kt(ut,function(t,e){X=parseFloat(e/K),Ot=!1,F.showAlpha||(Q=1),_()},s,l),Kt(ct,function(t,e,r){if(r.shiftKey){if(!nt){var n=Y*z,a=B-G*B,i=Math.abs(t-n)>Math.abs(e-a);nt=i?"x":"y"}}else nt=null;var o=!nt||"y"===nt;(!nt||"x"===nt)&&(Y=parseFloat(t/z)),o&&(G=parseFloat((B-e)/B)),Ot=!1,F.showAlpha||(Q=1),_()},s,l),Rt?(m(Rt),x(),Ft=F.preferredFormat||tinycolor(Rt).format,i(Rt)):x(),T&&d();var r=Xt?"mousedown.spectrum":"click.spectrum touchstart.spectrum";vt.delegate(".sp-thumb-el",r,t),mt.delegate(".sp-thumb-el:nth-child(1)",r,{ignore:!0},t)}function a(){if(q&&window.localStorage){try{var t=window.localStorage[q].split(",#");1<t.length&&(delete window.localStorage[q],jt.each(t,functio