Skip to content

Commit d33c1f9

Browse files
committed
Editable: Parse editor options in a straightforward way.
- Eg. editor: "spinner" for no options; or editor: { spinner: { min: 4, max: 20 } } for options;
1 parent e224e6d commit d33c1f9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ui/jquery.ui.editable.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,27 @@ $.widget( "ui.editable", {
7575
// Show placeholder if empty
7676
this._show();
7777
}
78+
this._getEditorOptions();
7879
// First bind custom_events, then this._events. Changing that order may cause problems (_start must precede _events[click] when this.options.event is click).
7980
custom_events[this.options.event] = "_start";
8081
this._bind( custom_events );
8182
this._bind( this._events );
8283
this.element.addClass( editableClass );
8384
},
8485

86+
_getEditorOptions: function() {
87+
if ( typeof this.options.editor === "string" ) {
88+
this._editor = this.options.editor;
89+
this._editorOptions = {};
90+
}
91+
else if ( typeof this.options.editor === "object" ) {
92+
for(var i in this.options.editor) {
93+
this._editor = i;
94+
this._editorOptions = this.options.editor[i];
95+
}
96+
}
97+
},
98+
8599
_events: {
86100
click: function( event ) {
87101
var $this = $( event.target );
@@ -143,7 +157,7 @@ $.widget( "ui.editable", {
143157
},
144158

145159
_form: function() {
146-
var editor = $.ui.editable.editors[ this.options.editor ],
160+
var editor = $.ui.editable.editors[ this._editor ],
147161
form = $( "<form></form>" )
148162
.addClass( formClass ),
149163
saveButton, cancelButton;
@@ -194,7 +208,7 @@ $.widget( "ui.editable", {
194208

195209
_formEvents: function() {
196210
var self = this,
197-
editor = $.ui.editable.editors[ self.options.editor ];
211+
editor = $.ui.editable.editors[ this._editor ];
198212
$( "form", this.element )
199213
.submit( function( event ) {
200214
self._save.call( self, event, editor.value( self, this ) );

0 commit comments

Comments
 (0)