add destroy method

This commit is contained in:
vitalets 2013-01-08 12:36:35 +04:00
parent 87f214adf4
commit 2fd6340b03
4 changed files with 44 additions and 2 deletions

@ -4,6 +4,7 @@ X-editable changelog
Version 1.4.0 wip
----------------------------
[enh] added `destroy` method, see #61 (vitalets)
[enh] textarea: added `rows` property (vitalets)
[enh #60] added wysihtml5 input (vitalets)
[enh] added IOS-style clear button for text inputs (vitalets)

@ -261,6 +261,8 @@ Applied as jQuery method.
**/
destroy: function() {
this.call('destroy');
this.$element.off('destroyed');
this.$element.removeData('editableContainer');
},
/*

@ -341,7 +341,24 @@ Makes editable any HTML element on the page. Applied as jQuery method.
if(this.container) {
this.container.activate();
}
}
},
/**
Removes editable feature from element
@method destroy()
**/
destroy: function() {
if(this.options.toggle !== 'manual') {
this.$element.removeClass('editable-click');
this.$element.off(this.options.toggle + '.editable');
}
if(this.container) {
this.container.destroy();
}
this.$element.removeClass('editable');
this.$element.removeClass('editable-open');
this.$element.removeData('editable');
}
};
/* EDITABLE PLUGIN DEFINITION

@ -365,6 +365,28 @@ $(function () {
equal(e.data('editable').value, 2, 'new value correct');
equal(e.text(), groups[2], 'new text shown correctly');
});
});
test("`destroy` method", function () {
var e = $('<a href="#" data-name="name" data-type="text" data-url="post.php"></a>').appendTo('#qunit-fixture').editable({
});
e.click();
var p = tip(e);
ok(p.is(':visible'), 'container visible');
e.editable('destroy');
ok(!p.is(':visible'), 'container closed');
ok(!e.data('editable'), 'editable instance removed');
ok(!e.data('editableContainer'), 'editableContainer instance removed');
ok(!e.hasClass('editable'), 'editable class removed');
ok(!e.hasClass('editable-click'), 'editable-click class removed');
e.click();
});
});