add workaround for shown/hidden events of popover: check second argument
This commit is contained in:
parent
e97783378a
commit
b9977b25bb
@ -137,7 +137,9 @@ Applied as jQuery method.
|
||||
resize: $.proxy(this.setPosition, this), //this allows to re-position container when form size is changed
|
||||
rendered: $.proxy(function(){
|
||||
/**
|
||||
Fired when container is shown and form is rendered (for select will wait for loading dropdown options)
|
||||
Fired when container is shown and form is rendered (for select will wait for loading dropdown options).
|
||||
**Note:** Bootstrap popover has own `shown` event that now cannot be separated from x-editable's one.
|
||||
The workaround is to check `arguments.length` that is always `2` for x-editable.
|
||||
|
||||
@event shown
|
||||
@param {Object} event event object
|
||||
@ -147,7 +149,10 @@ Applied as jQuery method.
|
||||
editable.input.$input.val('overwriting value of input..');
|
||||
});
|
||||
**/
|
||||
this.$element.triggerHandler('shown');
|
||||
/*
|
||||
added second param mainly to distinguish bootstrap's shown event. It's a hotfix that will be solved in 1.5 via namespaced events.
|
||||
*/
|
||||
this.$element.triggerHandler('shown', this);
|
||||
}, this)
|
||||
})
|
||||
.editableform('render');
|
||||
@ -213,11 +218,13 @@ Applied as jQuery method.
|
||||
this.innerHide();
|
||||
|
||||
/**
|
||||
Fired when container was hidden. It occurs on both save or cancel.
|
||||
Fired when container was hidden. It occurs on both save or cancel.
|
||||
**Note:** Bootstrap popover has own `hidden` event that now cannot be separated from x-editable's one.
|
||||
The workaround is to check `arguments.length` that is always `2` for x-editable.
|
||||
|
||||
@event hidden
|
||||
@param {object} event event object
|
||||
@param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|nochange|undefined (=manual)</code>
|
||||
@param {string} reason Reason caused hiding. Can be <code>save|cancel|onblur|nochange|manual</code>
|
||||
@example
|
||||
$('#username').on('hidden', function(e, reason) {
|
||||
if(reason === 'save' || reason === 'cancel') {
|
||||
@ -226,7 +233,7 @@ Applied as jQuery method.
|
||||
}
|
||||
});
|
||||
**/
|
||||
this.$element.triggerHandler('hidden', reason);
|
||||
this.$element.triggerHandler('hidden', reason || 'manual');
|
||||
},
|
||||
|
||||
/* internal show method. To be overwritten in child classes */
|
||||
|
@ -85,12 +85,16 @@ $(function () {
|
||||
e = $('<a href="#" data-pk="1" data-type="select" data-url="post.php" data-name="text" data-value="'+val+'"></a>').appendTo(fx);
|
||||
|
||||
e.on('shown', function(event) {
|
||||
var editable = $(this).data('editable');
|
||||
equal(editable.value, val, 'shown triggered, value correct');
|
||||
//distinguish from native bootstrap popover event
|
||||
if(arguments.length != 2) return;
|
||||
var editable = $(this).data('editable');
|
||||
equal(editable.value, val, 'shown triggered, value correct');
|
||||
});
|
||||
|
||||
e.on('hidden', function(event, reason) {
|
||||
ok((reason === test_reason) || (test_reason === 'manual' && reason === undefined), 'hidden triggered, reason ok');
|
||||
//distinguish from native bootstrap popover event
|
||||
if(arguments.length != 2) return;
|
||||
ok((reason === test_reason) || (test_reason === 'manual' && reason === undefined), 'hidden triggered, reason ok');
|
||||
});
|
||||
|
||||
e.editable({
|
||||
@ -104,28 +108,28 @@ $(function () {
|
||||
|
||||
test_reason = 'cancel'
|
||||
p.find('.editable-cancel').click(); //cancel
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
ok(!p.is(':visible'), 'popover closed '+test_reason);
|
||||
|
||||
test_reason = 'onblur'
|
||||
e.click();
|
||||
p = tip(e);
|
||||
ok(p.is(':visible'), 'popover shown');
|
||||
ok(p.is(':visible'), 'popover shown '+test_reason);
|
||||
e.parent().click();
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
ok(!p.is(':visible'), 'popover closed '+test_reason);
|
||||
|
||||
test_reason = 'nochange'
|
||||
e.click();
|
||||
p = tip(e);
|
||||
ok(p.is(':visible'), 'popover shown');
|
||||
ok(p.is(':visible'), 'popover shown '+test_reason);
|
||||
p.find('form').submit(); //submit value without changes
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
ok(!p.is(':visible'), 'popover closed '+test_reason);
|
||||
|
||||
test_reason = 'manual'
|
||||
e.click();
|
||||
p = tip(e);
|
||||
ok(p.is(':visible'), 'popover shown');
|
||||
ok(p.is(':visible'), 'popover shown '+test_reason);
|
||||
e.editable('hide');
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
ok(!p.is(':visible'), 'popover closed '+test_reason);
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
@ -143,6 +147,8 @@ $(function () {
|
||||
});
|
||||
|
||||
e.on('hidden', function(event, reason) {
|
||||
//distinguish from native bootstrap popover event
|
||||
if(arguments.length != 2) return;
|
||||
equal(reason, 'save', 'hidden triggered, reason ok');
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user