Skip to content

Commit

Permalink
Added a destroy method which removes the bindings created, this to av…
Browse files Browse the repository at this point in the history
…oid memory issues
  • Loading branch information
NAndreasson committed Jul 23, 2013
1 parent f58a0a5 commit 7e79339
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bootstrap-contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* New options added by @jeremyhubble for javascript launching
* $('#elem').contextmenu({target:'#menu',before:function(e) { return true; } });
*
*
*
* Twitter Bootstrap (http://twitter.github.com/bootstrap).
*/
Expand Down Expand Up @@ -40,7 +40,7 @@
this.options = options
this.before = this.options.before || this.before
this.onItem = this.options.onItem || this.onItem
if (this.options.target)
if (this.options.target)
this.$elements.attr('data-target',this.options.target)

this.listen()
Expand Down Expand Up @@ -106,6 +106,14 @@
});
}

,destroy: function() {
this.$elements.off('.context.data-api').removeData('context');
$('html').off('.context.data-api');

var $target = $(this.$elements.attr('data-target'));
$target.off('.context.data-api');
}

,getMenu: function () {
var selector = this.$elements.attr('data-target')
, $menu;
Expand Down Expand Up @@ -163,7 +171,7 @@
return (function () {
var data = $this.data('context')
, options = typeof option == 'object' && option

if (!data) $this.data('context', (data = new ContextMenu($this, options)));
// "show" method must also be passed the event for positioning
if (typeof option == 'string') data[option].call(data,e);
Expand Down

0 comments on commit 7e79339

Please sign in to comment.