Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / src / dom / DomEvent.DoubleTap.js
blob08bd79b9c922532ee6810a2bc9fd1f7bb54833b8
1 L.Util.extend(L.DomEvent, {
2 // inspired by Zepto touch code by Thomas Fuchs
3 addDoubleTapListener: function(obj, handler, id) {
4 var last,
5 doubleTap = false,
6 delay = 250,
7 touch,
8 pre = '_leaflet_',
9 touchstart = 'touchstart',
10 touchend = 'touchend';
12 function onTouchStart(e) {
13 if (e.touches.length != 1) return;
15 var now = Date.now(),
16 delta = now - (last || now);
18 touch = e.touches[0];
19 doubleTap = (delta > 0 && delta <= delay);
20 last = now;
22 function onTouchEnd(e) {
23 if (doubleTap) {
24 touch.type = 'dblclick';
25 handler(touch);
26 last = null;
29 obj[pre + touchstart + id] = onTouchStart;
30 obj[pre + touchend + id] = onTouchEnd;
32 obj.addEventListener(touchstart, onTouchStart, false);
33 obj.addEventListener(touchend, onTouchEnd, false);
36 removeDoubleTapListener: function(obj, id) {
37 var pre = '_leaflet_';
38 obj.removeEventListener(obj, obj[pre + 'touchstart' + id], false);
39 obj.removeEventListener(obj, obj[pre + 'touchend' + id], false);
41 });