Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

FIX: fix palette overflow bug #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 60 additions & 6 deletions js/jquery.colorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -350,3 +403,4 @@
};

})(jQuery);

27 changes: 1 addition & 26 deletions js/jquery.colorPicker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.