This commit is contained in:
Kevin Malakoff
2015-10-03 23:03:27 +00:00
3 changed files with 38 additions and 6 deletions

23
dist/clipboard.js vendored
View File

@@ -477,11 +477,21 @@ var Clipboard = (function (_Emitter) {
_classCallCheck(this, Clipboard); _classCallCheck(this, Clipboard);
_Emitter.call(this); _Emitter.call(this);
this.initialize = this.initialize.bind(this); // pre-bind for consistent reference on remove
this.resolveOptions(options); this.resolveOptions(options);
this.delegateClick(selector); this.delegateClick(selector);
} }
/**
* @param {String} selector
* @param {Object} options
*/
Clipboard.prototype.destroy = function destroy() {
this.undelegateClick();
};
/** /**
* Defines if attributes would be resolved using internal setter functions * Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor. * or custom functions that were passed in the constructor.
@@ -502,11 +512,16 @@ var Clipboard = (function (_Emitter) {
*/ */
Clipboard.prototype.delegateClick = function delegateClick(selector) { Clipboard.prototype.delegateClick = function delegateClick(selector) {
var _this = this; _delegateEvents2['default'].bind(document.body, selector, 'click', this.initialize);
};
_delegateEvents2['default'].bind(document.body, selector, 'click', function (e) { /**
return _this.initialize(e); * Undelegates a click event on the passed selector.
}); * @param {String} selector
*/
Clipboard.prototype.undelegateClick = function undelegateClick() {
_delegateEvents2['default'].unbind(document.body, 'click', this.initialize);
}; };
/** /**

File diff suppressed because one or more lines are too long

View File

@@ -15,11 +15,20 @@ class Clipboard extends Emitter {
*/ */
constructor(selector, options) { constructor(selector, options) {
super(); super();
this.initialize = this.initialize.bind(this); // pre-bind for consistent reference on remove
this.resolveOptions(options); this.resolveOptions(options);
this.delegateClick(selector); this.delegateClick(selector);
} }
/**
* @param {String} selector
* @param {Object} options
*/
destroy() {
this.undelegateClick();
}
/** /**
* Defines if attributes would be resolved using internal setter functions * Defines if attributes would be resolved using internal setter functions
* or custom functions that were passed in the constructor. * or custom functions that were passed in the constructor.
@@ -36,7 +45,15 @@ class Clipboard extends Emitter {
* @param {String} selector * @param {String} selector
*/ */
delegateClick(selector) { delegateClick(selector) {
Delegate.bind(document.body, selector, 'click', (e) => this.initialize(e)); Delegate.bind(document.body, selector, 'click', this.initialize);
}
/**
* Undelegates a click event on the passed selector.
* @param {String} selector
*/
undelegateClick() {
Delegate.unbind(document.body, 'click', this.initialize);
} }
/** /**