Permalink
Browse files

Fix for #58; okOnEnter option

Render popup HTML after opening and remove upon closing.
  • Loading branch information...
Martijn Martijn
Martijn authored and Martijn committed Aug 10, 2013
1 parent 8c1b787 commit e4d95cf0ff1c38a8bba192acaa8d60930f1f266a
Showing with 29 additions and 3 deletions.
  1. +3 −0 README.md
  2. +1 −0 TODO
  3. +15 −0 index.html
  4. +10 −3 jquery.colorpicker.js
View
@@ -155,6 +155,9 @@ Determines the functionality of the map and bar components. Allowed
values are; 'h', 's', 'l', 'r', 'g', 'b' or 'a', for hue, saturation,
luminosity, red, green, blue and alpha respectively.
+### okOnEnter (false)
+Close the window when pressing the Enter key on the keyboard, keeping the selected color.
+
### parts ('')
Determine which parts to display.
Use any of the preset names ('full', 'popup' or 'inline') or specify an array
View
1 TODO
@@ -1,3 +1,4 @@
+$.undelegate and remove keydown methods for opening upon close()
Separate into a pure dialog and a "caller" plugin.
Implement a getColor method.
Use preconfigured/default output color.
View
@@ -52,6 +52,7 @@ <h1>jQuery ColorPicker</h1>
<li><a href="#tab-plugins">Plugins</a></li>
<li><a href="#tab-buttonImageOnly">buttonImageOnly</a></li>
<li><a href="#tab-revert">Revert</a></li>
+ <li><a href="#tab-okonenter">Close on enter</a></li>
</ul>
<div id="tab-input">
@@ -424,6 +425,20 @@ <h2>Revert color on non-button exit.</h2>
});
</script>
</div>
+
+ <div id="tab-okonenter">
+ <h2>Close OK on enter</h2>
+ Close the popup by pressing the enter key, keeping the selected color.
+ <input type="text" class="cp-okonenter" value="a83b19"/>
+
+ <script>
+ $(function() {
+ $('.cp-okonenter').colorpicker({
+ okOnEnter: true
+ });
+ });
+ </script>
+ </div>
</div>
<h2>A feature-packed colorpicker for jQuery and jQueryUI.</h2>
View
@@ -2014,6 +2014,7 @@
limit: '', // Limit color "resolution": '', 'websafe', 'nibble', 'binary', 'name'
modal: false, // Modal dialog?
mode: 'h', // Initial editing mode, h, s, v, r, g, b or a
+ okOnEnter: false, // Close (with OK) when pressing the enter key
parts: '', // leave empty for automatic selection
regional: '',
revert: false, // Revert color upon non
@@ -2236,13 +2237,19 @@
that.close(that.options.revert);
});
- // close on ESC key
$(document).keydown(function (event) {
- if (event.keyCode == 27 && that.opened && that.options.closeOnEscape) {
+ // close on ESC key
+ if (that.opened && event.keyCode === 27 && that.options.closeOnEscape) {
that.close(that.options.revert);
}
+
+ // OK on Enter key
+ if (that.opened && event.keyCode === 13 && that.options.okOnEnter) {
+ that.close();
+ }
});
-
+
+ // Close (with OK) on tab key in element
that.element.keydown(function (event) {
if (event.keyCode === 9) {
that.close();

0 comments on commit e4d95cf

Please sign in to comment.