diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 62f3d74..7c17193 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,8 @@ X-editable changelog
Version 1.1.1 wip
----------------------------
+[enh] object can be passed in 'option' method to set several options simultaneously (vitalets)
+[enh #20] toggle editable by 'dblclick' and 'mouseenter' (vitalets)
[enh] added 'inputs-ext' directory with sample input 'address'. They will not be concatenated to main files (vitalets)
[enh #13] 'onblur' option: to cancel, submit or ignore when user clicks outside the form (vitalets)
[enh] 'ajaxOptions' parameter for advanced ajax configuration (vitalets)
diff --git a/src/element/editable-element.js b/src/element/editable-element.js
index 8b07eb8..4d91d58 100644
--- a/src/element/editable-element.js
+++ b/src/element/editable-element.js
@@ -136,10 +136,24 @@ Makes editable any HTML element on the page. Applied as jQuery method.
Sets new option
@method option(key, value)
- @param {string} key
- @param {mixed} value
+ @param {string|object} key option name or object with several options
+ @param {mixed} value option new value
+ @example
+ $('.editable').editable('option', 'pk', 2);
**/
option: function(key, value) {
+ //set option(s) by object
+ if(key && typeof key === 'object') {
+ $.each(key, $.proxy(function(k, v){
+ this.option($.trim(k), v);
+ }, this));
+ return;
+ }
+
+ //set option by string
+ this.options[key] = value;
+
+ //disabled
if(key === 'disabled') {
if(value) {
this.disable();
@@ -148,12 +162,15 @@ Makes editable any HTML element on the page. Applied as jQuery method.
}
return;
}
-
- this.options[key] = value;
+
+ //value
+ if(key === 'value') {
+ this.setValue(value);
+ }
//transfer new option to container!
if(this.container) {
- this.container.option(key, value);
+ this.container.option(key, value);
}
},
@@ -177,7 +194,9 @@ Makes editable any HTML element on the page. Applied as jQuery method.
}
}
},
-
+ /*
+ show / hide editable container when element triggers event defined by toggle option
+ */
activate: function (e) {
e.preventDefault();
if(this.options.disabled) {
diff --git a/test/unit/api.js b/test/unit/api.js
index 313e682..47f6ca2 100644
--- a/test/unit/api.js
+++ b/test/unit/api.js
@@ -287,7 +287,7 @@ $(function () {
});
- test("option method", function () {
+ test("option method (string and object)", function () {
var e = $('abc').appendTo('#qunit-fixture').editable(),
e1 = $('abc').appendTo('#qunit-fixture').editable(),
url = 'abc';
@@ -296,6 +296,12 @@ $(function () {
equal(e.data('editable').options.pk, 2, 'pk set correctly');
equal(e1.data('editable').options.pk, 2, 'pk2 set correctly');
+
+ $('#qunit-fixture a').editable('option', {pk: 3, value: 'abcd'});
+
+ equal(e.data('editable').options.pk, 3, 'pk set correctly (by object)');
+ equal(e.data('editable').value, 'abcd', 'value set correctly (by object)');
+ equal(e.text(), 'abcd', 'text set correctly (by object)');
});
asyncTest("'submit' method: client and server validation", function () {