[BUGFIX] Change event listening in jquery.minicolors and disable grunt copy 72/49272/4
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Sun, 31 Jul 2016 11:08:53 +0000 (13:08 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 4 Aug 2016 11:45:27 +0000 (13:45 +0200)
A bug in the jquery.minicolors library prevents the generation in an frame
and proper representation in the global document, as the library listens
to events in the frame (`document`) only, but the elements placed are in
`top.document`. Due to this, the event listening is changed and the grunt
copy command for this file is disabled to prevent overriding the library.

Resolves: #77317
Releases: master
Change-Id: I7bf878c377641e20ba5873f9bcc1e6c4d45d1ae0
Reviewed-on: https://review.typo3.org/49272
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Build/Gruntfile.js
typo3/sysext/core/Resources/Public/JavaScript/Contrib/jquery.minicolors.js

index 746afd8..0f21a72 100644 (file)
@@ -219,7 +219,11 @@ module.exports = function(grunt) {
                                        'autosize.js': 'autosize/dist/autosize.min.js',
                                        'taboverride.min.js': 'taboverride/build/output/taboverride.min.js',
                                        'bootstrap-slider.min.js': 'seiyria-bootstrap-slider/dist/bootstrap-slider.min.js',
+                                       /* disabled until events are not bound to document only
+                                               see https://github.com/claviska/jquery-minicolors/issues/192
+                                               see https://github.com/claviska/jquery-minicolors/issues/206
                                        'jquery.minicolors.js': 'jquery-minicolors/jquery.minicolors.min.js',
+                                        */
                                        /* disabled until autocomplete groupBy is fixed by the author
                                                see https://github.com/devbridge/jQuery-Autocomplete/pull/387
                                        'jquery.autocomplete.js': 'devbridge-autocomplete/src/jquery.autocomplete.js',
index 346f7f9..e87b511 100644 (file)
  * @license: http://opensource.org/licenses/MIT
  *
  */
-!function(i){"function"==typeof define&&define.amd?define(["jquery"],i):"object"==typeof exports?module.exports=i(require("jquery")):i(jQuery)}(function($){"use strict";function i(i,t){var o=$('<div class="minicolors" />'),s=$.minicolors.defaults,a,n,r,c,l;if(!i.data("minicolors-initialized")){if(t=$.extend(!0,{},s,t),o.addClass("minicolors-theme-"+t.theme).toggleClass("minicolors-with-opacity",t.opacity).toggleClass("minicolors-no-data-uris",t.dataUris!==!0),void 0!==t.position&&$.each(t.position.split(" "),function(){o.addClass("minicolors-position-"+this)}),a="rgb"===t.format?t.opacity?"25":"20":t.keywords?"11":"7",i.addClass("minicolors-input").data("minicolors-initialized",!1).data("minicolors-settings",t).prop("size",a).wrap(o).after('<div class="minicolors-panel minicolors-slider-'+t.control+'"><div class="minicolors-slider minicolors-sprite"><div class="minicolors-picker"></div></div><div class="minicolors-opacity-slider minicolors-sprite"><div class="minicolors-picker"></div></div><div class="minicolors-grid minicolors-sprite"><div class="minicolors-grid-inner"></div><div class="minicolors-picker"><div></div></div></div></div>'),t.inline||(i.after('<span class="minicolors-swatch minicolors-sprite minicolors-input-swatch"><span class="minicolors-swatch-color"></span></span>'),i.next(".minicolors-input-swatch").on("click",function(t){t.preventDefault(),i.focus()})),c=i.parent().find(".minicolors-panel"),c.on("selectstart",function(){return!1}).end(),t.swatches&&0!==t.swatches.length)for(t.swatches.length>7&&(t.swatches.length=7),c.addClass("minicolors-with-swatches"),n=$('<ul class="minicolors-swatches"></ul>').appendTo(c),l=0;l<t.swatches.length;++l)r=t.swatches[l],r=f(r)?u(r,!0):x(p(r,!0)),$('<li class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color"></span></li>').appendTo(n).data("swatch-color",t.swatches[l]).find(".minicolors-swatch-color").css({backgroundColor:y(r),opacity:r.a}),t.swatches[l]=r;t.inline&&i.parent().addClass("minicolors-inline"),e(i,!1),i.data("minicolors-initialized",!0)}}function t(i){var t=i.parent();i.removeData("minicolors-initialized").removeData("minicolors-settings").removeProp("size").removeClass("minicolors-input"),t.before(i).remove()}function o(i){var t=i.parent(),o=t.find(".minicolors-panel"),a=i.data("minicolors-settings");!i.data("minicolors-initialized")||i.prop("disabled")||t.hasClass("minicolors-inline")||t.hasClass("minicolors-focus")||(s(),t.addClass("minicolors-focus"),o.stop(!0,!0).fadeIn(a.showSpeed,function(){a.show&&a.show.call(i.get(0))}))}function s(){$(".minicolors-focus").each(function(){var i=$(this),t=i.find(".minicolors-input"),o=i.find(".minicolors-panel"),s=t.data("minicolors-settings");o.fadeOut(s.hideSpeed,function(){s.hide&&s.hide.call(t.get(0)),i.removeClass("minicolors-focus")})})}function a(i,t,o){var s=i.parents(".minicolors").find(".minicolors-input"),a=s.data("minicolors-settings"),r=i.find("[class$=-picker]"),e=i.offset().left,c=i.offset().top,l=Math.round(t.pageX-e),h=Math.round(t.pageY-c),d=o?a.animationSpeed:0,p,u,g,m;t.originalEvent.changedTouches&&(l=t.originalEvent.changedTouches[0].pageX-e,h=t.originalEvent.changedTouches[0].pageY-c),0>l&&(l=0),0>h&&(h=0),l>i.width()&&(l=i.width()),h>i.height()&&(h=i.height()),i.parent().is(".minicolors-slider-wheel")&&r.parent().is(".minicolors-grid")&&(p=75-l,u=75-h,g=Math.sqrt(p*p+u*u),m=Math.atan2(u,p),0>m&&(m+=2*Math.PI),g>75&&(g=75,l=75-75*Math.cos(m),h=75-75*Math.sin(m)),l=Math.round(l),h=Math.round(h)),i.is(".minicolors-grid")?r.stop(!0).animate({top:h+"px",left:l+"px"},d,a.animationEasing,function(){n(s,i)}):r.stop(!0).animate({top:h+"px"},d,a.animationEasing,function(){n(s,i)})}function n(i,t){function o(i,t){var o,s;return i.length&&t?(o=i.offset().left,s=i.offset().top,{x:o-t.offset().left+i.outerWidth()/2,y:s-t.offset().top+i.outerHeight()/2}):null}var s,a,n,e,l,h,d,p=i.val(),u=i.attr("data-opacity"),g=i.parent(),f=i.data("minicolors-settings"),v=g.find(".minicolors-input-swatch"),b=g.find(".minicolors-grid"),w=g.find(".minicolors-slider"),y=g.find(".minicolors-opacity-slider"),k=b.find("[class$=-picker]"),M=w.find("[class$=-picker]"),x=y.find("[class$=-picker]"),I=o(k,b),S=o(M,w),z=o(x,y);if(t.is(".minicolors-grid, .minicolors-slider, .minicolors-opacity-slider")){switch(f.control){case"wheel":e=b.width()/2-I.x,l=b.height()/2-I.y,h=Math.sqrt(e*e+l*l),d=Math.atan2(l,e),0>d&&(d+=2*Math.PI),h>75&&(h=75,I.x=69-75*Math.cos(d),I.y=69-75*Math.sin(d)),a=m(h/.75,0,100),s=m(180*d/Math.PI,0,360),n=m(100-Math.floor(S.y*(100/w.height())),0,100),p=C({h:s,s:a,b:n}),w.css("backgroundColor",C({h:s,s:a,b:100}));break;case"saturation":s=m(parseInt(I.x*(360/b.width()),10),0,360),a=m(100-Math.floor(S.y*(100/w.height())),0,100),n=m(100-Math.floor(I.y*(100/b.height())),0,100),p=C({h:s,s:a,b:n}),w.css("backgroundColor",C({h:s,s:100,b:n})),g.find(".minicolors-grid-inner").css("opacity",a/100);break;case"brightness":s=m(parseInt(I.x*(360/b.width()),10),0,360),a=m(100-Math.floor(I.y*(100/b.height())),0,100),n=m(100-Math.floor(S.y*(100/w.height())),0,100),p=C({h:s,s:a,b:n}),w.css("backgroundColor",C({h:s,s:a,b:100})),g.find(".minicolors-grid-inner").css("opacity",1-n/100);break;default:s=m(360-parseInt(S.y*(360/w.height()),10),0,360),a=m(Math.floor(I.x*(100/b.width())),0,100),n=m(100-Math.floor(I.y*(100/b.height())),0,100),p=C({h:s,s:a,b:n}),b.css("backgroundColor",C({h:s,s:100,b:100}))}u=f.opacity?parseFloat(1-z.y/y.height()).toFixed(2):1,r(i,p,u)}else v.find("span").css({backgroundColor:p,opacity:u}),c(i,p,u)}function r(i,t,o){var s,a=i.parent(),n=i.data("minicolors-settings"),r=a.find(".minicolors-input-swatch");n.opacity&&i.attr("data-opacity",o),"rgb"===n.format?(s=f(t)?u(t,!0):x(p(t,!0)),o=""===i.attr("data-opacity")?1:m(parseFloat(i.attr("data-opacity")).toFixed(2),0,1),(isNaN(o)||!n.opacity)&&(o=1),t=i.minicolors("rgbObject").a<=1&&s&&n.opacity?"rgba("+s.r+", "+s.g+", "+s.b+", "+parseFloat(o)+")":"rgb("+s.r+", "+s.g+", "+s.b+")"):(f(t)&&(t=w(t)),t=d(t,n.letterCase)),i.val(t),r.find("span").css({backgroundColor:t,opacity:o}),c(i,t,o)}function e(i,t){var o,s,a,n,r,e,l,h,b,y,M=i.parent(),x=i.data("minicolors-settings"),I=M.find(".minicolors-input-swatch"),S=M.find(".minicolors-grid"),z=M.find(".minicolors-slider"),F=M.find(".minicolors-opacity-slider"),D=S.find("[class$=-picker]"),T=z.find("[class$=-picker]"),j=F.find("[class$=-picker]");switch(f(i.val())?(o=w(i.val()),r=m(parseFloat(v(i.val())).toFixed(2),0,1),r&&i.attr("data-opacity",r)):o=d(p(i.val(),!0),x.letterCase),o||(o=d(g(x.defaultValue,!0),x.letterCase)),s=k(o),n=x.keywords?$.map(x.keywords.split(","),function(i){return $.trim(i.toLowerCase())}):[],e=""!==i.val()&&$.inArray(i.val().toLowerCase(),n)>-1?d(i.val()):f(i.val())?u(i.val()):o,t||i.val(e),x.opacity&&(a=""===i.attr("data-opacity")?1:m(parseFloat(i.attr("data-opacity")).toFixed(2),0,1),isNaN(a)&&(a=1),i.attr("data-opacity",a),I.find("span").css("opacity",a),h=m(F.height()-F.height()*a,0,F.height()),j.css("top",h+"px")),"transparent"===i.val().toLowerCase()&&I.find("span").css("opacity",0),I.find("span").css("backgroundColor",o),x.control){case"wheel":b=m(Math.ceil(.75*s.s),0,S.height()/2),y=s.h*Math.PI/180,l=m(75-Math.cos(y)*b,0,S.width()),h=m(75-Math.sin(y)*b,0,S.height()),D.css({top:h+"px",left:l+"px"}),h=150-s.b/(100/S.height()),""===o&&(h=0),T.css("top",h+"px"),z.css("backgroundColor",C({h:s.h,s:s.s,b:100}));break;case"saturation":l=m(5*s.h/12,0,150),h=m(S.height()-Math.ceil(s.b/(100/S.height())),0,S.height()),D.css({top:h+"px",left:l+"px"}),h=m(z.height()-s.s*(z.height()/100),0,z.height()),T.css("top",h+"px"),z.css("backgroundColor",C({h:s.h,s:100,b:s.b})),M.find(".minicolors-grid-inner").css("opacity",s.s/100);break;case"brightness":l=m(5*s.h/12,0,150),h=m(S.height()-Math.ceil(s.s/(100/S.height())),0,S.height()),D.css({top:h+"px",left:l+"px"}),h=m(z.height()-s.b*(z.height()/100),0,z.height()),T.css("top",h+"px"),z.css("backgroundColor",C({h:s.h,s:s.s,b:100})),M.find(".minicolors-grid-inner").css("opacity",1-s.b/100);break;default:l=m(Math.ceil(s.s/(100/S.width())),0,S.width()),h=m(S.height()-Math.ceil(s.b/(100/S.height())),0,S.height()),D.css({top:h+"px",left:l+"px"}),h=m(z.height()-s.h/(360/z.height()),0,z.height()),T.css("top",h+"px"),S.css("backgroundColor",C({h:s.h,s:100,b:100}))}i.data("minicolors-initialized")&&c(i,e,a)}function c(i,t,o){var s=i.data("minicolors-settings"),a=i.data("minicolors-lastChange"),n,r,e;if(!a||a.value!==t||a.opacity!==o){if(i.data("minicolors-lastChange",{value:t,opacity:o}),s.swatches&&0!==s.swatches.length){for(n=f(t)?u(t,!0):x(t),r=-1,e=0;e<s.swatches.length;++e)if(n.r===s.swatches[e].r&&n.g===s.swatches[e].g&&n.b===s.swatches[e].b&&n.a===s.swatches[e].a){r=e;break}i.parent().find(".minicolors-swatches .minicolors-swatch").removeClass("selected"),-1!==e&&i.parent().find(".minicolors-swatches .minicolors-swatch").eq(e).addClass("selected")}s.change&&(s.changeDelay?(clearTimeout(i.data("minicolors-changeTimeout")),i.data("minicolors-changeTimeout",setTimeout(function(){s.change.call(i.get(0),t,o)},s.changeDelay))):s.change.call(i.get(0),t,o)),i.trigger("change").trigger("input")}}function l(i){var t=p($(i).val(),!0),o=x(t),s=$(i).attr("data-opacity");return o?(void 0!==s&&$.extend(o,{a:parseFloat(s)}),o):null}function h(i,t){var o=p($(i).val(),!0),s=x(o),a=$(i).attr("data-opacity");return s?(void 0===a&&(a=1),t?"rgba("+s.r+", "+s.g+", "+s.b+", "+parseFloat(a)+")":"rgb("+s.r+", "+s.g+", "+s.b+")"):null}function d(i,t){return"uppercase"===t?i.toUpperCase():i.toLowerCase()}function p(i,t){return i=i.replace(/^#/g,""),i.match(/^[A-F0-9]{3,6}/gi)?3!==i.length&&6!==i.length?"":(3===i.length&&t&&(i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]),"#"+i):""}function u(i,t){var o=i.replace(/[^\d,.]/g,""),s=o.split(",");return s[0]=m(parseInt(s[0],10),0,255),s[1]=m(parseInt(s[1],10),0,255),s[2]=m(parseInt(s[2],10),0,255),s[3]&&(s[3]=m(parseFloat(s[3],10),0,1)),t?{r:s[0],g:s[1],b:s[2],a:s[3]?s[3]:null}:"undefined"!=typeof s[3]&&s[3]<=1?"rgba("+s[0]+", "+s[1]+", "+s[2]+", "+s[3]+")":"rgb("+s[0]+", "+s[1]+", "+s[2]+")"}function g(i,t){return f(i)?u(i):p(i,t)}function m(i,t,o){return t>i&&(i=t),i>o&&(i=o),i}function f(i){var t=i.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);return t&&4===t.length?!0:!1}function v(i){return i=i.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i),i&&6===i.length?i[4]:"1"}function b(i){var t={},o=Math.round(i.h),s=Math.round(255*i.s/100),a=Math.round(255*i.b/100);if(0===s)t.r=t.g=t.b=a;else{var n=a,r=(255-s)*a/255,e=(n-r)*(o%60)/60;360===o&&(o=0),60>o?(t.r=n,t.b=r,t.g=r+e):120>o?(t.g=n,t.b=r,t.r=n-e):180>o?(t.g=n,t.r=r,t.b=r+e):240>o?(t.b=n,t.r=r,t.g=n-e):300>o?(t.b=n,t.g=r,t.r=r+e):360>o?(t.r=n,t.g=r,t.b=n-e):(t.r=0,t.g=0,t.b=0)}return{r:Math.round(t.r),g:Math.round(t.g),b:Math.round(t.b)}}function w(i){return i=i.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i),i&&4===i.length?"#"+("0"+parseInt(i[1],10).toString(16)).slice(-2)+("0"+parseInt(i[2],10).toString(16)).slice(-2)+("0"+parseInt(i[3],10).toString(16)).slice(-2):""}function y(i){var t=[i.r.toString(16),i.g.toString(16),i.b.toString(16)];return $.each(t,function(i,o){1===o.length&&(t[i]="0"+o)}),"#"+t.join("")}function C(i){return y(b(i))}function k(i){var t=M(x(i));return 0===t.s&&(t.h=360),t}function M(i){var t={h:0,s:0,b:0},o=Math.min(i.r,i.g,i.b),s=Math.max(i.r,i.g,i.b),a=s-o;return t.b=s,t.s=0!==s?255*a/s:0,0!==t.s?i.r===s?t.h=(i.g-i.b)/a:i.g===s?t.h=2+(i.b-i.r)/a:t.h=4+(i.r-i.g)/a:t.h=-1,t.h*=60,t.h<0&&(t.h+=360),t.s*=100/255,t.b*=100/255,t}function x(i){return i=parseInt(i.indexOf("#")>-1?i.substring(1):i,16),{r:i>>16,g:(65280&i)>>8,b:255&i}}$.minicolors={defaults:{animationSpeed:50,animationEasing:"swing",change:null,changeDelay:0,control:"hue",dataUris:!0,defaultValue:"",format:"hex",hide:null,hideSpeed:100,inline:!1,keywords:"",letterCase:"lowercase",opacity:!1,position:"bottom left",show:null,showSpeed:100,theme:"default",swatches:[]}},$.extend($.fn,{minicolors:function(a,n){switch(a){case"destroy":return $(this).each(function(){t($(this))}),$(this);case"hide":return s(),$(this);case"opacity":return void 0===n?$(this).attr("data-opacity"):($(this).each(function(){e($(this).attr("data-opacity",n))}),$(this));case"rgbObject":return l($(this),"rgbaObject"===a);case"rgbString":case"rgbaString":return h($(this),"rgbaString"===a);case"settings":return void 0===n?$(this).data("minicolors-settings"):($(this).each(function(){var i=$(this).data("minicolors-settings")||{};t($(this)),$(this).minicolors($.extend(!0,i,n))}),$(this));case"show":return o($(this).eq(0)),$(this);case"value":return void 0===n?$(this).val():($(this).each(function(){"object"==typeof n?(n.opacity&&$(this).attr("data-opacity",m(n.opacity,0,1)),n.color&&$(this).val(n.color)):$(this).val(n),e($(this))}),$(this));default:return"create"!==a&&(n=a),$(this).each(function(){i($(this),n)}),$(this)}}}),$(document).on("mousedown.minicolors touchstart.minicolors",function(i){$(i.target).parents().add(i.target).hasClass("minicolors")||s()}).on("mousedown.minicolors touchstart.minicolors",".minicolors-grid, .minicolors-slider, .minicolors-opacity-slider",function(i){var t=$(this);i.preventDefault(),$(document).data("minicolors-target",t),a(t,i,!0)}).on("mousemove.minicolors touchmove.minicolors",function(i){var t=$(document).data("minicolors-target");t&&a(t,i)}).on("mouseup.minicolors touchend.minicolors",function(){$(this).removeData("minicolors-target")}).on("click.minicolors",".minicolors-swatches li",function(i){i.preventDefault();var t=$(this),o=t.parents(".minicolors").find(".minicolors-input"),s=t.data("swatch-color");r(o,s,v(s)),e(o)}).on("mousedown.minicolors touchstart.minicolors",".minicolors-input-swatch",function(i){var t=$(this).parent().find(".minicolors-input");i.preventDefault(),o(t)}).on("focus.minicolors",".minicolors-input",function(){var i=$(this);i.data("minicolors-initialized")&&o(i)}).on("blur.minicolors",".minicolors-input",function(){var i=$(this),t=i.data("minicolors-settings"),o,s,a,n,r;i.data("minicolors-initialized")&&(o=t.keywords?$.map(t.keywords.split(","),function(i){return $.trim(i.toLowerCase())}):[],""!==i.val()&&$.inArray(i.val().toLowerCase(),o)>-1?r=i.val():(f(i.val())?a=u(i.val(),!0):(s=p(i.val(),!0),a=s?x(s):null),r=null===a?t.defaultValue:"rgb"===t.format?u(t.opacity?"rgba("+a.r+","+a.g+","+a.b+","+i.attr("data-opacity")+")":"rgb("+a.r+","+a.g+","+a.b+")"):y(a)),n=t.opacity?i.attr("data-opacity"):1,"transparent"===r.toLowerCase()&&(n=0),i.closest(".minicolors").find(".minicolors-input-swatch > span").css("opacity",n),i.val(r),""===i.val()&&i.val(g(t.defaultValue,!0)),i.val(d(i.val(),t.letterCase)))}).on("keydown.minicolors",".minicolors-input",function(i){var t=$(this);if(t.data("minicolors-initialized"))switch(i.keyCode){case 9:s();break;case 13:case 27:s(),t.blur()}}).on("keyup.minicolors",".minicolors-input",function(){var i=$(this);i.data("minicolors-initialized")&&e(i,!0)}).on("paste.minicolors",".minicolors-input",function(){var i=$(this);i.data("minicolors-initialized")&&setTimeout(function(){e(i,!0)},1)})});
\ No newline at end of file
+(function (factory) {
+       /* jshint ignore:start */
+       if (typeof define === 'function' && define.amd) {
+               // AMD. Register as an anonymous module.
+               define(['jquery'], factory);
+       } else if (typeof exports === 'object') {
+               // Node/CommonJS
+               module.exports = factory(require('jquery'));
+       } else {
+               // Browser globals
+               factory(jQuery);
+       }
+       /* jshint ignore:end */
+}(function ($) {
+
+       'use strict';
+
+       // Defaults
+       $.minicolors = {
+               defaults: {
+                       animationSpeed: 50,
+                       animationEasing: 'swing',
+                       change: null,
+                       changeDelay: 0,
+                       control: 'hue',
+                       context: document,
+                       dataUris: true,
+                       defaultValue: '',
+                       format: 'hex',
+                       hide: null,
+                       hideSpeed: 100,
+                       inline: false,
+                       keywords: '',
+                       letterCase: 'lowercase',
+                       opacity: false,
+                       position: 'bottom left',
+                       show: null,
+                       showSpeed: 100,
+                       theme: 'default',
+                       swatches: []
+               }
+       };
+
+       // Public methods
+       $.extend($.fn, {
+               minicolors: function(method, data) {
+
+                       switch(method) {
+
+                               // Destroy the control
+                               case 'destroy':
+                                       $(this).each( function() {
+                                               destroy($(this));
+                                       });
+                                       return $(this);
+
+                               // Hide the color picker
+                               case 'hide':
+                                       hide();
+                                       return $(this);
+
+                               // Get/set opacity
+                               case 'opacity':
+                                       // Getter
+                                       if( data === undefined ) {
+                                               // Getter
+                                               return $(this).attr('data-opacity');
+                                       } else {
+                                               // Setter
+                                               $(this).each( function() {
+                                                       updateFromInput($(this).attr('data-opacity', data));
+                                               });
+                                       }
+                                       return $(this);
+
+                               // Get an RGB(A) object based on the current color/opacity
+                               case 'rgbObject':
+                                       return rgbObject($(this), method === 'rgbaObject');
+
+                               // Get an RGB(A) string based on the current color/opacity
+                               case 'rgbString':
+                               case 'rgbaString':
+                                       return rgbString($(this), method === 'rgbaString');
+
+                               // Get/set settings on the fly
+                               case 'settings':
+                                       if( data === undefined ) {
+                                               return $(this).data('minicolors-settings');
+                                       } else {
+                                               // Setter
+                                               $(this).each( function() {
+                                                       var settings = $(this).data('minicolors-settings') || {};
+                                                       destroy($(this));
+                                                       $(this).minicolors($.extend(true, settings, data));
+                                               });
+                                       }
+                                       return $(this);
+
+                               // Show the color picker
+                               case 'show':
+                                       show( $(this).eq(0) );
+                                       return $(this);
+
+                               // Get/set the hex color value
+                               case 'value':
+                                       if( data === undefined ) {
+                                               // Getter
+                                               return $(this).val();
+                                       } else {
+                                               // Setter
+                                               $(this).each( function() {
+                                                       if( typeof(data) === 'object' ) {
+                                                               if( data.opacity ) {
+                                                                       $(this).attr('data-opacity', keepWithin(data.opacity, 0, 1));
+                                                               }
+                                                               if( data.color ) {
+                                                                       $(this).val(data.color);
+                                                               }
+                                                       } else {
+                                                               $(this).val(data);
+                                                       }
+                                                       updateFromInput($(this));
+                                               });
+                                       }
+                                       return $(this);
+
+                               // Initializes the control
+                               default:
+                                       if( method !== 'create' ) data = method;
+                                       $(this).each( function() {
+                                               init($(this), data);
+                                       });
+                                       return $(this);
+
+                       }
+
+               }
+       });
+
+       // Initialize input elements
+       function init(input, settings) {
+
+               var minicolors = $('<div class="minicolors" />'),
+                       defaults = $.minicolors.defaults,
+                       size,
+                       swatches,
+                       swatch,
+                       panel,
+                       i;
+
+               // Do nothing if already initialized
+               if( input.data('minicolors-initialized') ) return;
+
+               // Handle settings
+               settings = $.extend(true, {}, defaults, settings);
+
+               // The wrapper
+               minicolors
+                       .addClass('minicolors-theme-' + settings.theme)
+                       .toggleClass('minicolors-with-opacity', settings.opacity)
+                       .toggleClass('minicolors-no-data-uris', settings.dataUris !== true);
+
+               // Custom positioning
+               if( settings.position !== undefined ) {
+                       $.each(settings.position.split(' '), function() {
+                               minicolors.addClass('minicolors-position-' + this);
+                       });
+               }
+
+               // Input size
+               if( settings.format === 'rgb' ) {
+                       size = settings.opacity ? '25' : '20';
+               } else {
+                       size = settings.keywords ? '11' : '7';
+               }
+
+               // The input
+               input
+                       .addClass('minicolors-input')
+                       .data('minicolors-initialized', false)
+                       .data('minicolors-settings', settings)
+                       .prop('size', size)
+                       .wrap(minicolors)
+                       .after(
+                               '<div class="minicolors-panel minicolors-slider-' + settings.control + '">' +
+                               '<div class="minicolors-slider minicolors-sprite">' +
+                               '<div class="minicolors-picker"></div>' +
+                               '</div>' +
+                               '<div class="minicolors-opacity-slider minicolors-sprite">' +
+                               '<div class="minicolors-picker"></div>' +
+                               '</div>' +
+                               '<div class="minicolors-grid minicolors-sprite">' +
+                               '<div class="minicolors-grid-inner"></div>' +
+                               '<div class="minicolors-picker"><div></div></div>' +
+                               '</div>' +
+                               '</div>'
+                       );
+
+               // The swatch
+               if( !settings.inline ) {
+                       input.after('<span class="minicolors-swatch minicolors-sprite minicolors-input-swatch"><span class="minicolors-swatch-color"></span></span>');
+                       input.next('.minicolors-input-swatch').on('click', function(event) {
+                               event.preventDefault();
+                               input.focus();
+                       });
+               }
+
+               // Prevent text selection in IE
+               panel = input.parent().find('.minicolors-panel');
+               panel.on('selectstart', function() { return false; }).end();
+
+               // Swatches
+               if (settings.swatches && settings.swatches.length !== 0) {
+                       if (settings.swatches.length > 7) {
+                               settings.swatches.length = 7;
+                       }
+                       panel.addClass('minicolors-with-swatches');
+                       swatches = $('<ul class="minicolors-swatches"></ul>')
+                               .appendTo(panel);
+                       for(i = 0; i < settings.swatches.length; ++i) {
+                               swatch = settings.swatches[i];
+                               swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true));
+                               $('<li class="minicolors-swatch minicolors-sprite"><span class="minicolors-swatch-color"></span></li>')
+                                       .appendTo(swatches)
+                                       .data('swatch-color', settings.swatches[i])
+                                       .find('.minicolors-swatch-color')
+                                       .css({
+                                               backgroundColor: rgb2hex(swatch),
+                                               opacity: swatch.a
+                                       });
+                               settings.swatches[i] = swatch;
+                       }
+
+               }
+
+               // Inline controls
+               if( settings.inline ) input.parent().addClass('minicolors-inline');
+
+               updateFromInput(input, false);
+
+               input.data('minicolors-initialized', true);
+
+       }
+
+       // Returns the input back to its original state
+       function destroy(input) {
+
+               var minicolors = input.parent();
+
+               // Revert the input element
+               input
+                       .removeData('minicolors-initialized')
+                       .removeData('minicolors-settings')
+                       .removeProp('size')
+                       .removeClass('minicolors-input');
+
+               // Remove the wrap and destroy whatever remains
+               minicolors.before(input).remove();
+
+       }
+
+       // Shows the specified dropdown panel
+       function show(input) {
+
+               var minicolors = input.parent(),
+                       panel = minicolors.find('.minicolors-panel'),
+                       settings = input.data('minicolors-settings');
+
+               // Do nothing if uninitialized, disabled, inline, or already open
+               if( !input.data('minicolors-initialized') ||
+                       input.prop('disabled') ||
+                       minicolors.hasClass('minicolors-inline') ||
+                       minicolors.hasClass('minicolors-focus')
+               ) return;
+
+               hide();
+
+               minicolors.addClass('minicolors-focus');
+               panel
+                       .stop(true, true)
+                       .fadeIn(settings.showSpeed, function() {
+                               if( settings.show ) settings.show.call(input.get(0));
+                       });
+
+       }
+
+       // Hides all dropdown panels
+       function hide() {
+
+               $('.minicolors-focus').each( function() {
+
+                       var minicolors = $(this),
+                               input = minicolors.find('.minicolors-input'),
+                               panel = minicolors.find('.minicolors-panel'),
+                               settings = input.data('minicolors-settings');
+
+                       panel.fadeOut(settings.hideSpeed, function() {
+                               if( settings.hide ) settings.hide.call(input.get(0));
+                               minicolors.removeClass('minicolors-focus');
+                       });
+
+               });
+       }
+
+       // Moves the selected picker
+       function move(target, event, animate) {
+
+               var input = target.parents('.minicolors').find('.minicolors-input'),
+                       settings = input.data('minicolors-settings'),
+                       picker = target.find('[class$=-picker]'),
+                       offsetX = target.offset().left,
+                       offsetY = target.offset().top,
+                       x = Math.round(event.pageX - offsetX),
+                       y = Math.round(event.pageY - offsetY),
+                       duration = animate ? settings.animationSpeed : 0,
+                       wx, wy, r, phi;
+
+               // Touch support
+               if( event.originalEvent.changedTouches ) {
+                       x = event.originalEvent.changedTouches[0].pageX - offsetX;
+                       y = event.originalEvent.changedTouches[0].pageY - offsetY;
+               }
+
+               // Constrain picker to its container
+               if( x < 0 ) x = 0;
+               if( y < 0 ) y = 0;
+               if( x > target.width() ) x = target.width();
+               if( y > target.height() ) y = target.height();
+
+               // Constrain color wheel values to the wheel
+               if( target.parent().is('.minicolors-slider-wheel') && picker.parent().is('.minicolors-grid') ) {
+                       wx = 75 - x;
+                       wy = 75 - y;
+                       r = Math.sqrt(wx * wx + wy * wy);
+                       phi = Math.atan2(wy, wx);
+                       if( phi < 0 ) phi += Math.PI * 2;
+                       if( r > 75 ) {
+                               r = 75;
+                               x = 75 - (75 * Math.cos(phi));
+                               y = 75 - (75 * Math.sin(phi));
+                       }
+                       x = Math.round(x);
+                       y = Math.round(y);
+               }
+
+               // Move the picker
+               if( target.is('.minicolors-grid') ) {
+                       picker
+                               .stop(true)
+                               .animate({
+                                       top: y + 'px',
+                                       left: x + 'px'
+                               }, duration, settings.animationEasing, function() {
+                                       updateFromControl(input, target);
+                               });
+               } else {
+                       picker
+                               .stop(true)
+                               .animate({
+                                       top: y + 'px'
+                               }, duration, settings.animationEasing, function() {
+                                       updateFromControl(input, target);
+                               });
+               }
+
+       }
+
+       // Sets the input based on the color picker values
+       function updateFromControl(input, target) {
+
+               function getCoords(picker, container) {
+
+                       var left, top;
+                       if( !picker.length || !container ) return null;
+                       left = picker.offset().left;
+                       top = picker.offset().top;
+
+                       return {
+                               x: left - container.offset().left + (picker.outerWidth() / 2),
+                               y: top - container.offset().top + (picker.outerHeight() / 2)
+                       };
+
+               }
+
+               var hue, saturation, brightness, x, y, r, phi,
+
+                       hex = input.val(),
+                       opacity = input.attr('data-opacity'),
+
+                       // Helpful references
+                       minicolors = input.parent(),
+                       settings = input.data('minicolors-settings'),
+                       swatch = minicolors.find('.minicolors-input-swatch'),
+
+                       // Panel objects
+                       grid = minicolors.find('.minicolors-grid'),
+                       slider = minicolors.find('.minicolors-slider'),
+                       opacitySlider = minicolors.find('.minicolors-opacity-slider'),
+
+                       // Picker objects
+                       gridPicker = grid.find('[class$=-picker]'),
+                       sliderPicker = slider.find('[class$=-picker]'),
+                       opacityPicker = opacitySlider.find('[class$=-picker]'),
+
+                       // Picker positions
+                       gridPos = getCoords(gridPicker, grid),
+                       sliderPos = getCoords(sliderPicker, slider),
+                       opacityPos = getCoords(opacityPicker, opacitySlider);
+
+               // Handle colors
+               if( target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider') ) {
+
+                       // Determine HSB values
+                       switch(settings.control) {
+
+                               case 'wheel':
+                                       // Calculate hue, saturation, and brightness
+                                       x = (grid.width() / 2) - gridPos.x;
+                                       y = (grid.height() / 2) - gridPos.y;
+                                       r = Math.sqrt(x * x + y * y);
+                                       phi = Math.atan2(y, x);
+                                       if( phi < 0 ) phi += Math.PI * 2;
+                                       if( r > 75 ) {
+                                               r = 75;
+                                               gridPos.x = 69 - (75 * Math.cos(phi));
+                                               gridPos.y = 69 - (75 * Math.sin(phi));
+                                       }
+                                       saturation = keepWithin(r / 0.75, 0, 100);
+                                       hue = keepWithin(phi * 180 / Math.PI, 0, 360);
+                                       brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
+                                       hex = hsb2hex({
+                                               h: hue,
+                                               s: saturation,
+                                               b: brightness
+                                       });
+
+                                       // Update UI
+                                       slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
+                                       break;
+
+                               case 'saturation':
+                                       // Calculate hue, saturation, and brightness
+                                       hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
+                                       saturation = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
+                                       brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
+                                       hex = hsb2hex({
+                                               h: hue,
+                                               s: saturation,
+                                               b: brightness
+                                       });
+
+                                       // Update UI
+                                       slider.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: brightness }));
+                                       minicolors.find('.minicolors-grid-inner').css('opacity', saturation / 100);
+                                       break;
+
+                               case 'brightness':
+                                       // Calculate hue, saturation, and brightness
+                                       hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360);
+                                       saturation = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
+                                       brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100);
+                                       hex = hsb2hex({
+                                               h: hue,
+                                               s: saturation,
+                                               b: brightness
+                                       });
+
+                                       // Update UI
+                                       slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 }));
+                                       minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (brightness / 100));
+                                       break;
+
+                               default:
+                                       // Calculate hue, saturation, and brightness
+                                       hue = keepWithin(360 - parseInt(sliderPos.y * (360 / slider.height()), 10), 0, 360);
+                                       saturation = keepWithin(Math.floor(gridPos.x * (100 / grid.width())), 0, 100);
+                                       brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100);
+                                       hex = hsb2hex({
+                                               h: hue,
+                                               s: saturation,
+                                               b: brightness
+                                       });
+
+                                       // Update UI
+                                       grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 }));
+                                       break;
+
+                       }
+
+                       // Handle opacity
+                       if( settings.opacity ) {
+                               opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2);
+                       } else {
+                               opacity = 1;
+                       }
+
+                       updateInput(input, hex, opacity);
+               }
+               else {
+                       // Set swatch color
+                       swatch.find('span').css({
+                               backgroundColor: hex,
+                               opacity: opacity
+                       });
+
+                       // Handle change event
+                       doChange(input, hex, opacity);
+               }
+       }
+
+       // Sets the value of the input and does the appropriate conversions
+       // to respect settings, also updates the swatch
+       function updateInput(input, value, opacity) {
+               var rgb,
+
+                       // Helpful references
+                       minicolors = input.parent(),
+                       settings = input.data('minicolors-settings'),
+                       swatch = minicolors.find('.minicolors-input-swatch');
+
+               if( settings.opacity ) input.attr('data-opacity', opacity);
+
+               // Set color string
+               if( settings.format === 'rgb' ) {
+                       // Returns RGB(A) string
+
+                       // Checks for input format and does the conversion
+                       if ( isRgb(value) ) {
+                               rgb = parseRgb(value, true);
+                       }
+                       else {
+                               rgb = hex2rgb(parseHex(value, true));
+                       }
+
+                       opacity = input.attr('data-opacity') === '' ? 1 : keepWithin( parseFloat( input.attr('data-opacity') ).toFixed(2), 0, 1 );
+                       if( isNaN( opacity ) || !settings.opacity ) opacity = 1;
+
+                       if( input.minicolors('rgbObject').a <= 1 && rgb && settings.opacity) {
+                               // Set RGBA string if alpha
+                               value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat( opacity ) + ')';
+                       } else {
+                               // Set RGB string (alpha = 1)
+                               value = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
+                       }
+               } else {
+                       // Returns hex color
+
+                       // Checks for input format and does the conversion
+                       if ( isRgb(value) ) {
+                               value = rgbString2hex(value);
+                       }
+
+                       value = convertCase( value, settings.letterCase );
+               }
+
+               // Update value from picker
+               input.val( value );
+
+               // Set swatch color
+               swatch.find('span').css({
+                       backgroundColor: value,
+                       opacity: opacity
+               });
+
+               // Handle change event
+               doChange(input, value, opacity);
+       }
+
+       // Sets the color picker values from the input
+       function updateFromInput(input, preserveInputValue) {
+
+               var hex,
+                       hsb,
+                       opacity,
+                       keywords,
+                       alpha,
+                       value,
+                       x, y, r, phi,
+
+                       // Helpful references
+                       minicolors = input.parent(),
+                       settings = input.data('minicolors-settings'),
+                       swatch = minicolors.find('.minicolors-input-swatch'),
+
+                       // Panel objects
+                       grid = minicolors.find('.minicolors-grid'),
+                       slider = minicolors.find('.minicolors-slider'),
+                       opacitySlider = minicolors.find('.minicolors-opacity-slider'),
+
+                       // Picker objects
+                       gridPicker = grid.find('[class$=-picker]'),
+                       sliderPicker = slider.find('[class$=-picker]'),
+                       opacityPicker = opacitySlider.find('[class$=-picker]');
+
+               // Determine hex/HSB values
+               if( isRgb(input.val()) ) {
+                       // If input value is a rgb(a) string, convert it to hex color and update opacity
+                       hex = rgbString2hex(input.val());
+                       alpha = keepWithin(parseFloat(getAlpha(input.val())).toFixed(2), 0, 1);
+                       if( alpha ) {
+                               input.attr('data-opacity', alpha);
+                       }
+               } else {
+                       hex = convertCase(parseHex(input.val(), true), settings.letterCase);
+               }
+
+               if( !hex ){
+                       hex = convertCase(parseInput(settings.defaultValue, true), settings.letterCase);
+               }
+               hsb = hex2hsb(hex);
+
+               // Get array of lowercase keywords
+               keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
+                       return $.trim(a.toLowerCase());
+               });
+
+               // Set color string
+               if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1 ) {
+                       value = convertCase(input.val());
+               } else {
+                       value = isRgb(input.val()) ? parseRgb(input.val()) : hex;
+               }
+
+               // Update input value
+               if( !preserveInputValue ) input.val(value);
+
+               // Determine opacity value
+               if( settings.opacity ) {
+                       // Get from data-opacity attribute and keep within 0-1 range
+                       opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1);
+                       if( isNaN(opacity) ) opacity = 1;
+                       input.attr('data-opacity', opacity);
+                       swatch.find('span').css('opacity', opacity);
+
+                       // Set opacity picker position
+                       y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height());
+                       opacityPicker.css('top', y + 'px');
+               }
+
+               // Set opacity to zero if input value is transparent
+               if( input.val().toLowerCase() === 'transparent' ) {
+                       swatch.find('span').css('opacity', 0);
+               }
+
+               // Update swatch
+               swatch.find('span').css('backgroundColor', hex);
+
+               // Determine picker locations
+               switch(settings.control) {
+
+                       case 'wheel':
+                               // Set grid position
+                               r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2);
+                               phi = hsb.h * Math.PI / 180;
+                               x = keepWithin(75 - Math.cos(phi) * r, 0, grid.width());
+                               y = keepWithin(75 - Math.sin(phi) * r, 0, grid.height());
+                               gridPicker.css({
+                                       top: y + 'px',
+                                       left: x + 'px'
+                               });
+
+                               // Set slider position
+                               y = 150 - (hsb.b / (100 / grid.height()));
+                               if( hex === '' ) y = 0;
+                               sliderPicker.css('top', y + 'px');
+
+                               // Update panel color
+                               slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
+                               break;
+
+                       case 'saturation':
+                               // Set grid position
+                               x = keepWithin((5 * hsb.h) / 12, 0, 150);
+                               y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
+                               gridPicker.css({
+                                       top: y + 'px',
+                                       left: x + 'px'
+                               });
+
+                               // Set slider position
+                               y = keepWithin(slider.height() - (hsb.s * (slider.height() / 100)), 0, slider.height());
+                               sliderPicker.css('top', y + 'px');
+
+                               // Update UI
+                               slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: hsb.b }));
+                               minicolors.find('.minicolors-grid-inner').css('opacity', hsb.s / 100);
+                               break;
+
+                       case 'brightness':
+                               // Set grid position
+                               x = keepWithin((5 * hsb.h) / 12, 0, 150);
+                               y = keepWithin(grid.height() - Math.ceil(hsb.s / (100 / grid.height())), 0, grid.height());
+                               gridPicker.css({
+                                       top: y + 'px',
+                                       left: x + 'px'
+                               });
+
+                               // Set slider position
+                               y = keepWithin(slider.height() - (hsb.b * (slider.height() / 100)), 0, slider.height());
+                               sliderPicker.css('top', y + 'px');
+
+                               // Update UI
+                               slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 }));
+                               minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (hsb.b / 100));
+                               break;
+
+                       default:
+                               // Set grid position
+                               x = keepWithin(Math.ceil(hsb.s / (100 / grid.width())), 0, grid.width());
+                               y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height());
+                               gridPicker.css({
+                                       top: y + 'px',
+                                       left: x + 'px'
+                               });
+
+                               // Set slider position
+                               y = keepWithin(slider.height() - (hsb.h / (360 / slider.height())), 0, slider.height());
+                               sliderPicker.css('top', y + 'px');
+
+                               // Update panel color
+                               grid.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: 100 }));
+                               break;
+
+               }
+
+               // Fire change event, but only if minicolors is fully initialized
+               if( input.data('minicolors-initialized') ) {
+                       doChange(input, value, opacity);
+               }
+
+       }
+
+       // Runs the change and changeDelay callbacks
+       function doChange(input, value, opacity) {
+
+               var settings = input.data('minicolors-settings'),
+                       lastChange = input.data('minicolors-lastChange'),
+                       obj,
+                       sel,
+                       i;
+
+               // Only run if it actually changed
+               if( !lastChange || lastChange.value !== value || lastChange.opacity !== opacity ) {
+
+                       // Remember last-changed value
+                       input.data('minicolors-lastChange', {
+                               value: value,
+                               opacity: opacity
+                       });
+
+                       // Check and select applicable swatch
+                       if (settings.swatches && settings.swatches.length !== 0) {
+                               if(!isRgb(value)) {
+                                       obj = hex2rgb(value);
+                               }
+                               else {
+                                       obj = parseRgb(value, true);
+                               }
+                               sel = -1;
+                               for(i = 0; i < settings.swatches.length; ++i) {
+                                       if (obj.r === settings.swatches[i].r && obj.g === settings.swatches[i].g && obj.b === settings.swatches[i].b && obj.a === settings.swatches[i].a) {
+                                               sel = i;
+                                               break;
+                                       }
+                               }
+
+                               input.parent().find('.minicolors-swatches .minicolors-swatch').removeClass('selected');
+                               if (i !== -1) {
+                                       input.parent().find('.minicolors-swatches .minicolors-swatch').eq(i).addClass('selected');
+                               }
+                       }
+
+                       // Fire change event
+                       if( settings.change ) {
+                               if( settings.changeDelay ) {
+                                       // Call after a delay
+                                       clearTimeout(input.data('minicolors-changeTimeout'));
+                                       input.data('minicolors-changeTimeout', setTimeout( function() {
+                                               settings.change.call(input.get(0), value, opacity);
+                                       }, settings.changeDelay));
+                               } else {
+                                       // Call immediately
+                                       settings.change.call(input.get(0), value, opacity);
+                               }
+                       }
+                       input.trigger('change').trigger('input');
+               }
+
+       }
+
+       // Generates an RGB(A) object based on the input's value
+       function rgbObject(input) {
+               var hex = parseHex($(input).val(), true),
+                       rgb = hex2rgb(hex),
+                       opacity = $(input).attr('data-opacity');
+               if( !rgb ) return null;
+               if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) });
+               return rgb;
+       }
+
+       // Generates an RGB(A) string based on the input's value
+       function rgbString(input, alpha) {
+               var hex = parseHex($(input).val(), true),
+                       rgb = hex2rgb(hex),
+                       opacity = $(input).attr('data-opacity');
+               if( !rgb ) return null;
+               if( opacity === undefined ) opacity = 1;
+               if( alpha ) {
+                       return 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')';
+               } else {
+                       return 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')';
+               }
+       }
+
+       // Converts to the letter case specified in settings
+       function convertCase(string, letterCase) {
+               return letterCase === 'uppercase' ? string.toUpperCase() : string.toLowerCase();
+       }
+
+       // Parses a string and returns a valid hex string when possible
+       function parseHex(string, expand) {
+               string = string.replace(/^#/g, '');
+               if( !string.match(/^[A-F0-9]{3,6}/ig) ) return '';
+               if( string.length !== 3 && string.length !== 6 ) return '';
+               if( string.length === 3 && expand ) {
+                       string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2];
+               }
+               return '#' + string;
+       }
+
+       // Parses a string and returns a valid RGB(A) string when possible
+       function parseRgb(string, obj) {
+
+               var values = string.replace(/[^\d,.]/g, ''),
+                       rgba = values.split(',');
+
+               rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255);
+               rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255);
+               rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255);
+               if( rgba[3] ) {
+                       rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1);
+               }
+
+               // Return RGBA object
+               if( obj ) {
+                       return {
+                               r: rgba[0],
+                               g: rgba[1],
+                               b: rgba[2],
+                               a: rgba[3] ? rgba[3] : null
+                       };
+               }
+
+               // Return RGBA string
+               if( typeof(rgba[3]) !== 'undefined' && rgba[3] <= 1 ) {
+                       return 'rgba(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ', ' + rgba[3] + ')';
+               } else {
+                       return 'rgb(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ')';
+               }
+
+       }
+
+       // Parses a string and returns a valid color string when possible
+       function parseInput(string, expand) {
+               if( isRgb(string) ) {
+                       // Returns a valid rgb(a) string
+                       return parseRgb(string);
+               } else {
+                       return parseHex(string, expand);
+               }
+       }
+
+       // Keeps value within min and max
+       function keepWithin(value, min, max) {
+               if( value < min ) value = min;
+               if( value > max ) value = max;
+               return value;
+       }
+
+       // Checks if a string is a valid RGB(A) string
+       function isRgb(string) {
+               var rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
+               return (rgb && rgb.length === 4) ? true : false;
+       }
+
+       // Function to get alpha from a RGB(A) string
+       function getAlpha(rgba) {
+               rgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i);
+               return (rgba && rgba.length === 6) ? rgba[4] : '1';
+       }
+
+       // Converts an HSB object to an RGB object
+       function hsb2rgb(hsb) {
+               var rgb = {};
+               var h = Math.round(hsb.h);
+               var s = Math.round(hsb.s * 255 / 100);
+               var v = Math.round(hsb.b * 255 / 100);
+               if(s === 0) {
+                       rgb.r = rgb.g = rgb.b = v;
+               } else {
+                       var t1 = v;
+                       var t2 = (255 - s) * v / 255;
+                       var t3 = (t1 - t2) * (h % 60) / 60;
+                       if( h === 360 ) h = 0;
+                       if( h < 60 ) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; }
+                       else if( h < 120 ) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; }
+                       else if( h < 180 ) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; }
+                       else if( h < 240 ) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; }
+                       else if( h < 300 ) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; }
+                       else if( h < 360 ) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; }
+                       else { rgb.r = 0; rgb.g = 0; rgb.b = 0; }
+               }
+               return {
+                       r: Math.round(rgb.r),
+                       g: Math.round(rgb.g),
+                       b: Math.round(rgb.b)
+               };
+       }
+
+       // Converts an RGB string to a hex string
+       function rgbString2hex(rgb){
+               rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
+               return (rgb && rgb.length === 4) ? '#' +
+               ('0' + parseInt(rgb[1],10).toString(16)).slice(-2) +
+               ('0' + parseInt(rgb[2],10).toString(16)).slice(-2) +
+               ('0' + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
+       }
+
+       // Converts an RGB object to a hex string
+       function rgb2hex(rgb) {
+               var hex = [
+                       rgb.r.toString(16),
+                       rgb.g.toString(16),
+                       rgb.b.toString(16)
+               ];
+               $.each(hex, function(nr, val) {
+                       if (val.length === 1) hex[nr] = '0' + val;
+               });
+               return '#' + hex.join('');
+       }
+
+       // Converts an HSB object to a hex string
+       function hsb2hex(hsb) {
+               return rgb2hex(hsb2rgb(hsb));
+       }
+
+       // Converts a hex string to an HSB object
+       function hex2hsb(hex) {
+               var hsb = rgb2hsb(hex2rgb(hex));
+               if( hsb.s === 0 ) hsb.h = 360;
+               return hsb;
+       }
+
+       // Converts an RGB object to an HSB object
+       function rgb2hsb(rgb) {
+               var hsb = { h: 0, s: 0, b: 0 };
+               var min = Math.min(rgb.r, rgb.g, rgb.b);
+               var max = Math.max(rgb.r, rgb.g, rgb.b);
+               var delta = max - min;
+               hsb.b = max;
+               hsb.s = max !== 0 ? 255 * delta / max : 0;
+               if( hsb.s !== 0 ) {
+                       if( rgb.r === max ) {
+                               hsb.h = (rgb.g - rgb.b) / delta;
+                       } else if( rgb.g === max ) {
+                               hsb.h = 2 + (rgb.b - rgb.r) / delta;
+                       } else {
+                               hsb.h = 4 + (rgb.r - rgb.g) / delta;
+                       }
+               } else {
+                       hsb.h = -1;
+               }
+               hsb.h *= 60;
+               if( hsb.h < 0 ) {
+                       hsb.h += 360;
+               }
+               hsb.s *= 100/255;
+               hsb.b *= 100/255;
+               return hsb;
+       }
+
+       // Converts a hex string to an RGB object
+       function hex2rgb(hex) {
+               hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
+               return {
+                       /* jshint ignore:start */
+                       r: hex >> 16,
+                       g: (hex & 0x00FF00) >> 8,
+                       b: (hex & 0x0000FF)
+                       /* jshint ignore:end */
+               };
+       }
+
+       // Handle events
+       $([document, top.document])
+       // Hide on clicks outside of the control
+               .on('mousedown.minicolors touchstart.minicolors', function(event) {
+                       if( !$(event.target).parents().add(event.target).hasClass('minicolors') ) {
+                               hide();
+                       }
+               })
+               // Start moving
+               .on('mousedown.minicolors touchstart.minicolors', '.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider', function(event) {
+                       var target = $(this);
+                       event.preventDefault();
+                       $(document).data('minicolors-target', target);
+                       move(target, event, true);
+               })
+               // Move pickers
+               .on('mousemove.minicolors touchmove.minicolors', function(event) {
+                       var target = $(document).data('minicolors-target');
+                       if( target ) move(target, event);
+               })
+               // Stop moving
+               .on('mouseup.minicolors touchend.minicolors', function() {
+                       $(this).removeData('minicolors-target');
+               })
+               // Selected a swatch
+               .on('click.minicolors', '.minicolors-swatches li', function(event) {
+                       event.preventDefault();
+                       var target = $(this), input = target.parents('.minicolors').find('.minicolors-input'), color = target.data('swatch-color');
+                       updateInput(input, color, getAlpha(color));
+                       updateFromInput(input);
+               })
+               // Show panel when swatch is clicked
+               .on('mousedown.minicolors touchstart.minicolors', '.minicolors-input-swatch', function(event) {
+                       var input = $(this).parent().find('.minicolors-input');
+                       event.preventDefault();
+                       show(input);
+               })
+               // Show on focus
+               .on('focus.minicolors', '.minicolors-input', function() {
+                       var input = $(this);
+                       if( !input.data('minicolors-initialized') ) return;
+                       show(input);
+               })
+               // Update value on blur
+               .on('blur.minicolors', '.minicolors-input', function() {
+                       var input = $(this),
+                               settings = input.data('minicolors-settings'),
+                               keywords,
+                               hex,
+                               rgba,
+                               swatchOpacity,
+                               value;
+
+                       if( !input.data('minicolors-initialized') ) return;
+
+                       // Get array of lowercase keywords
+                       keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) {
+                               return $.trim(a.toLowerCase());
+                       });
+
+                       // Set color string
+                       if( input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1 ) {
+                               value = input.val();
+                       } else {
+                               // Get RGBA values for easy conversion
+                               if( isRgb(input.val()) ) {
+                                       rgba = parseRgb(input.val(), true);
+                               } else {
+                                       hex = parseHex(input.val(), true);
+                                       rgba = hex ? hex2rgb(hex) : null;
+                               }
+
+                               // Convert to format
+                               if( rgba === null ) {
+                                       value = settings.defaultValue;
+                               } else if( settings.format === 'rgb' ) {
+                                       value = settings.opacity ?
+                                               parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') :
+                                               parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')');
+                               } else {
+                                       value = rgb2hex(rgba);
+                               }
+                       }
+
+                       // Update swatch opacity
+                       swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1;
+                       if( value.toLowerCase() === 'transparent' ) swatchOpacity = 0;
+                       input
+                               .closest('.minicolors')
+                               .find('.minicolors-input-swatch > span')
+                               .css('opacity', swatchOpacity);
+
+                       // Set input value
+                       input.val(value);
+
+                       // Is it blank?
+                       if( input.val() === '' ) input.val(parseInput(settings.defaultValue, true));
+
+                       // Adjust case
+                       input.val( convertCase(input.val(), settings.letterCase) );
+
+               })
+               // Handle keypresses
+               .on('keydown.minicolors', '.minicolors-input', function(event) {
+                       var input = $(this);
+                       if( !input.data('minicolors-initialized') ) return;
+                       switch(event.keyCode) {
+                               case 9: // tab
+                                       hide();
+                                       break;
+                               case 13: // enter
+                               case 27: // esc
+                                       hide();
+                                       input.blur();
+                                       break;
+                       }
+               })
+               // Update on keyup
+               .on('keyup.minicolors', '.minicolors-input', function() {
+                       var input = $(this);
+                       if( !input.data('minicolors-initialized') ) return;
+                       updateFromInput(input, true);
+               })
+               // Update on paste
+               .on('paste.minicolors', '.minicolors-input', function() {
+                       var input = $(this);
+                       if( !input.data('minicolors-initialized') ) return;
+                       setTimeout( function() {
+                               updateFromInput(input, true);
+                       }, 1);
+               });
+
+}));