Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added blur detection for swatches tied to inputs.

  • Loading branch information...
commit 04e739d43087cf563004c4ec6f29dcc9c2eb94b5 1 parent b98242c
Scott Gonzalez authored
Showing with 18 additions and 0 deletions.
  1. +18 −0 jquery.nmk.colorswatch.js
View
18 jquery.nmk.colorswatch.js
@@ -49,6 +49,24 @@ $.widget('nmk.colorswatch', {
show: function() {
this.swatch.show();
+
+ var self = this;
+ function detectBlur(event) {
+ var swatch = $(event.target).closest('.nmk-colorswatch'),
+ keepOpen = (swatch.length && swatch[0] == self.swatch[0]) ||
+ (event.target == self.element[0]);
+
+ if (!keepOpen) {
+ $(document).unbind('mousedown keydown', detectBlur);
+ self.hide();
+ return false;
+ }
+ }
+ $(document).bind('mousedown keydown', detectBlur);
+ },
+
+ hide: function() {
+ this.swatch.hide();
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.