Created
December 24, 2018 16:05
-
-
Save johnd0e/769c2c87d779ba0277b252e2e890ef57 to your computer and use it in GitHub Desktop.
IITC plugin: twofinger-zoom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id iitc-plugin-twofinger-zoom | |
// @name IITC plugin: twofinger-zoom | |
// @description Interaction handler for touch devices enabling zooming out with a two finger tap. | |
// @category test | |
// @version 0.1.0 | |
// @author jd | |
// @namespace https://gist.github.com/johnd0e | |
// @homepageURL https://gist.github.com/johnd0e/% | |
// @supportURL https://gist.github.com/johnd0e/%#new_comment_field | |
// @updateURL https://gist.github.com/johnd0e/%/raw/twofinger-zoom.user.js | |
// @downloadURL https://gist.github.com/johnd0e/%/raw/twofinger-zoom.user.js | |
// @include https://intel.ingress.com/intel* | |
// @grant none | |
// ==/UserScript== | |
function wrapper(plugin_info) { | |
// ensure plugin framework is there, even if iitc is not yet loaded | |
if(typeof window.plugin !== 'function') window.plugin = function() {}; | |
// PLUGIN START //////////////////////////////////////////////////////// | |
// https://github.com/aratcliffe/Leaflet.twofingerzoom/ | |
function setup () { | |
/* | |
Leaflet.twofingerzoom, enables zooming the map out with a two finger tap on touch devices | |
(c) 2014, Adam Ratcliffe, TomTom International BV | |
*/ | |
L.Map.mergeOptions({ | |
twoFingerZoom: L.Browser.touch && !L.Browser.android23 | |
}); | |
L.Map.TwoFingerZoom = L.Handler.extend({ | |
statics: { | |
ZOOM_OUT_THRESHOLD: 100 | |
}, | |
addHooks: function () { | |
L.DomEvent.on(this._map._container, 'touchstart', this._onTouchStart, this); | |
L.DomEvent.on(this._map._container, 'touchend', this._onTouchEnd, this); | |
}, | |
removeHooks: function () { | |
L.DomEvent.off(this._map._container, 'touchstart', this._onTouchStart, this); | |
L.DomEvent.off(this._map._container, 'touchend', this._onTouchEnd, this); | |
}, | |
_onTouchStart: function (e) { | |
var touches = e.touches; | |
if (touches.length !== 2) { | |
return; | |
} | |
this._touchStartTime = new Date(); | |
}, | |
_onTouchEnd: function (e) { | |
var map = this._map, | |
touches = e.changedTouches; | |
if (!this._touchStartTime) { | |
return; | |
} | |
L.DomEvent.preventDefault(e); | |
if (new Date() - this._touchStartTime <= L.Map.TwoFingerZoom.ZOOM_OUT_THRESHOLD) { | |
this._touchStartTime = null; | |
map.zoomOut(); | |
} | |
} | |
}); | |
L.Map.addInitHook('addHandler', 'twoFingerZoom', L.Map.TwoFingerZoom); | |
} | |
// PLUGIN END ////////////////////////////////////////////////////////// | |
setup.info = plugin_info; //add the script info data to the function as a property | |
if(!window.bootPlugins) window.bootPlugins = []; | |
window.bootPlugins.push(setup); | |
// if IITC has already booted, immediately run the 'setup' function | |
if(window.iitcLoaded && typeof setup === 'function') setup(); | |
} // wrapper end | |
// inject code into site context | |
var script = document.createElement('script'); | |
var info = {}; | |
if (typeof GM_info !== 'undefined' && GM_info && GM_info.script) info.script = { version: GM_info.script.version, name: GM_info.script.name, description: GM_info.script.description }; | |
script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');')); | |
(document.body || document.head || document.documentElement).appendChild(script); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment