Permalink
Browse files

bugfix: when in hide_buttons mode, automatically cancel the edit when…

… the control looses focus
  • Loading branch information...
1 parent 5bb765b commit 485892d4e71969cd630acf5ac9baed2e341e86f2 @reednj committed Aug 12, 2011
Showing with 38 additions and 7 deletions.
  1. +8 −1 Source/InlineEditor.Combo.js
  2. +15 −6 Source/InlineEditor.js
  3. +15 −0 Test/simpletest.html
@@ -118,7 +118,14 @@ InlineEditor.Combo = new Class({
this.save_edit();
}
}.bind(this),
- 'change': this._selection_changed.bind(this)
+ 'change': this._selection_changed.bind(this),
+ 'blur': function(e) {
+ // when in hide_buttons mode, we want to automatically cancel
+ // if the user clicks off the control.
+ if(this.options.hide_buttons){
+ this.cancel_edit();
+ }
+ }.bind(this)
}});
},
View
@@ -112,12 +112,21 @@ var InlineEditor = new Class({
_create_input: function() {
return $e('input', {
'type':'text',
- 'events': {'keydown': function(e) {
- // detect the escape key, and use it to cancel the edit
- if(e.key == 'esc') {
- this.cancel_edit();
- }
- }.bind(this)}
+ 'events': {
+ 'keydown': function(e) {
+ // detect the escape key, and use it to cancel the edit
+ if(e.key == 'esc') {
+ this.cancel_edit();
+ }
+ }.bind(this),
+ 'blur': function(e) {
+ // when in hide_buttons mode, we want to automatically cancel
+ // if the user clicks off the control.
+ if(this.options.hide_buttons){
+ this.cancel_edit();
+ }
+ }.bind(this)
+ }
});
},
View
@@ -66,6 +66,12 @@
}
});
+ new InlineEditor.Combo('color-select-2', {
+ onSuccess: function(new_text, new_value) {
+ $('color-target').setStyle('background-color', new_value);
+ }
+ });
+
new InlineEditor('jsonpost', {
url: 'api/edittest.php',
method: 'POST',
@@ -118,6 +124,15 @@
<div data-value='#FFF'>White</div>
</div>
+
+<div id='color-select-2' data-selected='#F00' data-hidebuttons='true'>
+ <div data-value='#F00'>Red</div>
+ <div data-value='#0F0'>Green</div>
+ <div data-value='#00F'>Blue</div>
+ <div data-value='#000'>Black</div>
+ <div data-value='#FFF'>White</div>
+</div>
+
<div id='color-target' style='width: 48px; height: 48px; background-color: gray; border: 2px solid gray;'></div>
<div class='editable' data-format='N3'>123456.12345</div>

0 comments on commit 485892d

Please sign in to comment.