pass object in option method

This commit is contained in:
vitalets 2012-11-30 14:20:18 +04:00
parent 5b8f00d01b
commit 3dc331cf5b
3 changed files with 34 additions and 7 deletions

@ -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)

@ -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) {

@ -287,7 +287,7 @@ $(function () {
});
test("option method", function () {
test("option method (string and object)", function () {
var e = $('<a href="#" data-url="post.php" data-name="text">abc</a>').appendTo('#qunit-fixture').editable(),
e1 = $('<a href="#" data-pk="1" data-name="text1">abc</a>').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 () {