diff --git a/js/jquery.colorPicker.js b/js/jquery.colorPicker.js
index 72b38b1..1cd7777 100644
--- a/js/jquery.colorPicker.js
+++ b/js/jquery.colorPicker.js
@@ -224,19 +224,72 @@
$('.colorPicker-palette').hide();
},
+
/**
- * Show the color palette modal.
- **/
- showPalette : function (palette) {
- var hexColor = selectorOwner.prev("input").val();
+ * calculate the top position of palette
+ **/
+ calculatePalettePositionTop: function (palette) {
+ var win = $(window),
+ winBottom= win.scrollTop() + win.height();
+
+ var ownerTop = selectorOwner.offset().top,
+ ownerHeight = selectorOwner.outerHeight();
+
+ var top = ownerTop + ownerHeight,
+ height = palette.outerHeight(),
+ bottom = top + height;
+
+ if (bottom > winBottom) { // if palette overflow bottom
+ top = ownerTop - height;
+ }
+
+ return top;
+ },
+
+ /**
+ * calculate the left position of palette
+ **/
+ calculatePalettePositionLeft: function (palette) {
+ var win = $(window),
+ winRight = win.scrollLeft() + win.width();
+
+ var ownerLeft = selectorOwner.offset().left,
+ ownerRight = selectorOwner.offset().left + selectorOwner.outerWidth();
+
+ var left = ownerLeft,
+ width = palette.outerWidth(),
+ right = left + width;
+
+ if (right > winRight) { // if palette overflows right
+ var margin = 10;// This is a magic number
+ left = Math.min(ownerRight, winRight - margin) - width;
+ }
+
+ return left;
+ },
+
+ adjustPalettePosition: function (palette) {
+ var top = $.fn.colorPicker.calculatePalettePositionTop(palette);
+ var left = $.fn.colorPicker.calculatePalettePositionLeft(palette);
palette.css({
- top: selectorOwner.offset().top + (selectorOwner.outerHeight()),
- left: selectorOwner.offset().left
+ /**
+ * adjust the position of color palette modal
+ **/
+ top: top,
+ left: left
});
+ },
+ /**
+ * Show the color palette modal.
+ **/
+ showPalette : function (palette) {
+ var hexColor = selectorOwner.prev("input").val();
$("#color_value").val(hexColor);
+ $.fn.colorPicker.adjustPalettePosition(palette);
+
palette.show();
$(document).bind("mousedown", $.fn.colorPicker.checkMouse);
@@ -350,3 +403,4 @@
};
})(jQuery);
+
diff --git a/js/jquery.colorPicker.min.js b/js/jquery.colorPicker.min.js
index 9ed7f64..5b2c01a 100644
--- a/js/jquery.colorPicker.min.js
+++ b/js/jquery.colorPicker.min.js
@@ -1,26 +1 @@
-/**
- * Really Simple Color Picker in jQuery
- *
- * Licensed under the MIT (MIT-LICENSE.txt) licenses.
- *
- * Copyright (c) 2008-2012
- * Lakshan Perera (www.laktek.com) & Daniel Lacy (daniellacy.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */(function(a){var b,c,d=0,e={control:a('
'),palette:a(''),swatch:a('
'),hexLabel:a(''),hexField:a('')},f="transparent",g;a.fn.colorPicker=function(b){return this.each(function(){var c=a(this),g=a.extend({},a.fn.colorPicker.defaults,b),h=a.fn.colorPicker.toHex(c.val().length>0?c.val():g.pickerDefault),i=e.control.clone(),j=e.palette.clone().attr("id","colorPicker_palette-"+d),k=e.hexLabel.clone(),l=e.hexField.clone(),m=j[0].id,n,o;a.each(g.colors,function(b){n=e.swatch.clone(),g.colors[b]===f?(n.addClass(f).text("X"),a.fn.colorPicker.bindPalette(l,n,f)):(n.css("background-color","#"+this),a.fn.colorPicker.bindPalette(l,n)),n.appendTo(j)}),k.attr("for","colorPicker_hex-"+d),l.attr({id:"colorPicker_hex-"+d,value:h}),l.bind("keydown",function(b){if(b.keyCode===13){var d=a.fn.colorPicker.toHex(a(this).val());a.fn.colorPicker.changeColor(d?d:c.val())}b.keyCode===27&&a.fn.colorPicker.hidePalette()}),l.bind("keyup",function(b){var d=a.fn.colorPicker.toHex(a(b.target).val());a.fn.colorPicker.previewColor(d?d:c.val())}),a('').append(k).appendTo(j),j.find(".colorPicker_hexWrap").append(l),g.showHexField===!1&&(l.hide(),k.hide()),a("body").append(j),j.hide(),i.css("background-color",h),i.bind("click",function(){c.is(":not(:disabled)")&&a.fn.colorPicker.togglePalette(a("#"+m),a(this))}),b&&b.onColorChange?i.data("onColorChange",b.onColorChange):i.data("onColorChange",function(){}),(o=c.data("text"))&&i.html(o),c.after(i),c.bind("change",function(){c.next(".colorPicker-picker").css("background-color",a.fn.colorPicker.toHex(a(this).val()))}),c.val(h);if(c[0].tagName.toLowerCase()==="input")try{c.attr("type","hidden")}catch(p){c.css("visibility","hidden").css("position","absolute")}else c.hide();d++})},a.extend(!0,a.fn.colorPicker,{toHex:function(a){if(a.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i))return a.charAt(0)==="#"?a:"#"+a;if(!a.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/))return!1;var b=[parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10)],c=function(a){if(a.length<2)for(var b=0,c=2-a.length;b0)return;a.fn.colorPicker.hidePalette()},hidePalette:function(){a(document).unbind("mousedown",a.fn.colorPicker.checkMouse),a(".colorPicker-palette").hide()},showPalette:function(c){var d=b.prev("input").val();c.css({top:b.offset().top+b.outerHeight(),left:b.offset().left}),a("#color_value").val(d),c.show(),a(document).bind("mousedown",a.fn.colorPicker.checkMouse)},togglePalette:function(d,e){e&&(b=e),c=d,c.is(":visible")?a.fn.colorPicker.hidePalette():a.fn.colorPicker.showPalette(d)},changeColor:function(c){b.css("background-color",c),b.prev("input").val(c).change(),a.fn.colorPicker.hidePalette(),b.data("onColorChange").call(b,a(b).prev("input").attr("id"),c)},previewColor:function(a){b.css("background-color",a)},bindPalette:function(c,d,e){e=e?e:a.fn.colorPicker.toHex(d.css("background-color")),d.bind({click:function(b){g=e,a.fn.colorPicker.changeColor(e)},mouseover:function(b){g=c.val(),a(this).css("border-color","#598FEF"),c.val(e),a.fn.colorPicker.previewColor(e)},mouseout:function(d){a(this).css("border-color","#000"),c.val(b.css("background-color")),c.val(g),a.fn.colorPicker.previewColor(g)}})}}),a.fn.colorPicker.defaults={pickerDefault:"FFFFFF",colors:["000000","993300","333300","000080","333399","333333","800000","FF6600","808000","008000","008080","0000FF","666699","808080","FF0000","FF9900","99CC00","339966","33CCCC","3366FF","800080","999999","FF00FF","FFCC00","FFFF00","00FF00","00FFFF","00CCFF","993366","C0C0C0","FF99CC","FFCC99","FFFF99","CCFFFF","99CCFF","FFFFFF"],addColors:[],showHexField:!0}})(jQuery);
\ No newline at end of file
+!function(e){var o,t,r,c=0,i={control:e('
'),palette:e(''),swatch:e('
'),hexLabel:e(''),hexField:e('')},n="transparent";e.fn.colorPicker=function(o){return this.each(function(){var t,r,l=e(this),a=e.extend({},e.fn.colorPicker.defaults,o),s=e.fn.colorPicker.toHex(l.val().length>0?l.val():a.pickerDefault),d=i.control.clone(),f=i.palette.clone().attr("id","colorPicker_palette-"+c),u=i.hexLabel.clone(),h=i.hexField.clone(),P=f[0].id;if(e.each(a.colors,function(o){t=i.swatch.clone(),a.colors[o]===n?(t.addClass(n).text("X"),e.fn.colorPicker.bindPalette(h,t,n)):(t.css("background-color","#"+this),e.fn.colorPicker.bindPalette(h,t)),t.appendTo(f)}),u.attr("for","colorPicker_hex-"+c),h.attr({id:"colorPicker_hex-"+c,value:s}),h.bind("keydown",function(o){if(13===o.keyCode){var t=e.fn.colorPicker.toHex(e(this).val());e.fn.colorPicker.changeColor(t?t:l.val())}27===o.keyCode&&e.fn.colorPicker.hidePalette()}),h.bind("keyup",function(o){var t=e.fn.colorPicker.toHex(e(o.target).val());e.fn.colorPicker.previewColor(t?t:l.val())}),e('').append(u).appendTo(f),f.find(".colorPicker_hexWrap").append(h),a.showHexField===!1&&(h.hide(),u.hide()),e("body").append(f),f.hide(),d.css("background-color",s),d.bind("click",function(){l.is(":not(:disabled)")&&e.fn.colorPicker.togglePalette(e("#"+P),e(this))}),o&&o.onColorChange?d.data("onColorChange",o.onColorChange):d.data("onColorChange",function(){}),(r=l.data("text"))&&d.html(r),l.after(d),l.bind("change",function(){l.next(".colorPicker-picker").css("background-color",e.fn.colorPicker.toHex(e(this).val()))}),l.val(s),"input"===l[0].tagName.toLowerCase())try{l.attr("type","hidden")}catch(e){l.css("visibility","hidden").css("position","absolute")}else l.hide();c++})},e.extend(!0,e.fn.colorPicker,{toHex:function(e){if(e.match(/[0-9A-F]{6}|[0-9A-F]{3}$/i))return"#"===e.charAt(0)?e:"#"+e;if(!e.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/))return!1;var o=[parseInt(RegExp.$1,10),parseInt(RegExp.$2,10),parseInt(RegExp.$3,10)],t=function(e){if(e.length<2)for(var o=0,t=2-e.length;o0||e.fn.colorPicker.hidePalette()},hidePalette:function(){e(document).unbind("mousedown",e.fn.colorPicker.checkMouse),e(".colorPicker-palette").hide()},calculatePalettePositionTop:function(t){var r=e(window),c=r.scrollTop()+r.height(),i=o.offset().top,n=o.outerHeight(),l=i+n,a=t.outerHeight(),s=l+a;return s>c&&(l=i-a),l},calculatePalettePositionLeft:function(t){var r=e(window),c=r.scrollLeft()+r.width(),i=o.offset().left,n=o.offset().left+o.outerWidth(),l=i,a=t.outerWidth(),s=l+a;if(s>c){var d=10;l=Math.min(n,c-d)-a}return l},adjustPalettePosition:function(o){var t=e.fn.colorPicker.calculatePalettePositionTop(o),r=e.fn.colorPicker.calculatePalettePositionLeft(o);o.css({top:t,left:r})},showPalette:function(t){var r=o.prev("input").val();e("#color_value").val(r),e.fn.colorPicker.adjustPalettePosition(t),t.show(),e(document).bind("mousedown",e.fn.colorPicker.checkMouse)},togglePalette:function(r,c){c&&(o=c),t=r,t.is(":visible")?e.fn.colorPicker.hidePalette():e.fn.colorPicker.showPalette(r)},changeColor:function(t){o.css("background-color",t),o.prev("input").val(t).change(),e.fn.colorPicker.hidePalette(),o.data("onColorChange").call(o,e(o).prev("input").attr("id"),t)},previewColor:function(e){o.css("background-color",e)},bindPalette:function(t,c,i){i=i?i:e.fn.colorPicker.toHex(c.css("background-color")),c.bind({click:function(o){r=i,e.fn.colorPicker.changeColor(i)},mouseover:function(o){r=t.val(),e(this).css("border-color","#598FEF"),t.val(i),e.fn.colorPicker.previewColor(i)},mouseout:function(c){e(this).css("border-color","#000"),t.val(o.css("background-color")),t.val(r),e.fn.colorPicker.previewColor(r)}})}}),e.fn.colorPicker.defaults={pickerDefault:"FFFFFF",colors:["000000","993300","333300","000080","333399","333333","800000","FF6600","808000","008000","008080","0000FF","666699","808080","FF0000","FF9900","99CC00","339966","33CCCC","3366FF","800080","999999","FF00FF","FFCC00","FFFF00","00FF00","00FFFF","00CCFF","993366","C0C0C0","FF99CC","FFCC99","FFFF99","CCFFFF","99CCFF","FFFFFF"],addColors:[],showHexField:!0}}(jQuery);
\ No newline at end of file