Skip to content

Commit 213223b

Browse files
author
fat
committed
use capturing phase to prevent unintended js from firing
1 parent 96a227f commit 213223b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

js/zoom.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
this._$document = $(document)
1313
this._$window = $(window)
1414
this._$body = $(document.body)
15+
16+
this._boundClick = $.proxy(this._clickHandler, this)
1517
}
1618

1719
ZoomService.prototype.listen = function () {
@@ -37,10 +39,13 @@
3739
// todo(fat): probably worth throttling this
3840
this._$window.on('scroll.zoom', $.proxy(this._scrollHandler, this))
3941

40-
this._$document.on('click.zoom', $.proxy(this._clickHandler, this))
4142
this._$document.on('keyup.zoom', $.proxy(this._keyHandler, this))
4243
this._$document.on('touchstart.zoom', $.proxy(this._touchStart, this))
4344

45+
// we use a capturing phase here to prevent unintended js events
46+
// sadly no useCapture in jquery api (http://bugs.jquery.com/ticket/14953)
47+
document.addEventListener('click', this._boundClick, true)
48+
4449
e.stopPropagation()
4550
}
4651

@@ -56,6 +61,8 @@
5661
this._$window.off('.zoom')
5762
this._$document.off('.zoom')
5863

64+
document.removeEventListener('click', this._boundClick, true)
65+
5966
this._activeZoom = null
6067
}
6168

0 commit comments

Comments
 (0)