Skip to content

Commit 413732f

Browse files
committed
Possibility to enable and disable Jeditable programmatically.
Example usage, first attach Jeditable to all elements with class "editable". Later disable Jeditable from one element. $('.editable').editable('http://www.example.com/save.php', { type : 'textarea', submit : 'OK', cancel : 'cancel', }); $('#notme').editable('disable'); If you later want to re-enable just use: $('#notme').editable('enable');
1 parent c543966 commit 413732f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

jquery.jeditable.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@
6060
(function($) {
6161

6262
$.fn.editable = function(target, options) {
63-
63+
64+
if ('disable' == target) {
65+
$(this).data('editable', {disabled : true});
66+
return;
67+
}
68+
if ('enable' == target) {
69+
$(this).data('editable', {disabled : false});
70+
return;
71+
}
72+
6473
var settings = {
6574
target : target,
6675
name : 'value',
@@ -106,7 +115,7 @@
106115

107116
settings.autowidth = 'auto' == settings.width;
108117
settings.autoheight = 'auto' == settings.height;
109-
118+
110119
return this.each(function() {
111120

112121
/* save this to self because this changes when scope changes */
@@ -123,7 +132,13 @@
123132
}
124133

125134
$(this).bind(settings.event, function(e) {
126-
135+
136+
/* abort if disabled for this element */
137+
if ('undefined' != typeof($(this).data('editable'))
138+
&& true === $(this).data('editable').disabled) {
139+
return;
140+
}
141+
127142
/* prevent throwing an exeption if edit field is clicked again */
128143
if (self.editing) {
129144
return;

0 commit comments

Comments
 (0)