Skip to content

Commit

Permalink
Ensure events are namespaced correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Mar 2, 2017
1 parent 6303695 commit 3a538d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions js/fileinput.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
if ($h.isEmpty($el.attr('id'))) {
$el.attr('id', $h.uniqId());
}
self.namespace = '.kvFile' + $el.attr('id').replace(/-/g, '');
if (self.$container === undefined) {
self.$container = self._createContainer();
} else {
Expand Down Expand Up @@ -986,26 +987,26 @@
}
},
_listen: function () {
var self = this, $el = self.$element, $form = self.$form, $cont = self.$container, n = '.' + $el.attr('id');
var self = this, $el = self.$element, $form = self.$form, $cont = self.$container, ns = self.namespace;
$h.handler($el, 'change', $.proxy(self._change, self));
if (self.showBrowse) {
$h.handler(self.$btnFile, 'click', $.proxy(self._browse, self));
}
$h.handler($cont.find('.fileinput-remove:not([disabled])'), 'click', $.proxy(self.clear, self));
$h.handler($cont.find('.fileinput-cancel'), 'click', $.proxy(self.cancel, self));
self._initDragDrop();
$h.handler($form, 'reset', $.proxy(self.reset, self), n);
$h.handler($form, 'reset', $.proxy(self.reset, self), ns);
if (!self.isUploadable) {
$h.handler($form, 'submit', $.proxy(self._submitForm, self), n);
$h.handler($form, 'submit', $.proxy(self._submitForm, self), ns);
}
$h.handler(self.$container.find('.fileinput-upload'), 'click', $.proxy(self._uploadClick, self));
$h.handler($(window), 'resize', function () {
self._listenFullScreen(screen.width === window.innerWidth && screen.height === window.innerHeight);
}, true);
}, ns);
$h.handler($(document), 'webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange',
function () {
self._listenFullScreen($h.checkFullScreen());
}, true);
}, ns);
self._initClickable();
},
_initClickable: function () {
Expand Down Expand Up @@ -3264,9 +3265,11 @@
return self.$element;
},
destroy: function () {
var self = this, $form = self.$form, $cont = self.$container, $el = self.$element;
var self = this, $form = self.$form, $cont = self.$container, $el = self.$element, ns = self.namespace;
$(document).off(ns);
$(window).off(ns);
if ($form && $form.length) {
$form.off('.' + self.$element.attr('id'));
$form.off(ns);
}
$el.insertBefore($cont).off($h.NAMESPACE).removeData();
$cont.off().remove();
Expand Down
Loading

0 comments on commit 3a538d9

Please sign in to comment.