Difference between revisions of "User:Moussekateer/vector.js"
Moussekateer (talk | contribs) m |
Moussekateer (talk | contribs) m |
||
Line 3: | Line 3: | ||
importScriptURI('https://raw.github.com/Moussekateer/TFWiki-scripts/master/wikifi_toolbox.js', 'text/javascript'); | importScriptURI('https://raw.github.com/Moussekateer/TFWiki-scripts/master/wikifi_toolbox.js', 'text/javascript'); | ||
− | + | function simulateTouchEvents(oo,bIgnoreChilds) | |
− | + | { | |
− | + | if( !$(oo)[0] ) | |
− | + | { return false; } | |
+ | if( !window.__touchTypes ) | ||
+ | { | ||
+ | window.__touchTypes = {touchstart:'mousedown',touchmove:'mousemove',touchend:'mouseup'}; | ||
+ | window.__touchInputs = {INPUT:1,TEXTAREA:1,SELECT:1,OPTION:1,'input':1,'textarea':1,'select':1,'option':1}; | ||
+ | } | ||
+ | $(oo).bind('touchstart touchmove touchend', function(ev) | ||
+ | { | ||
+ | var bSame = (ev.target == this); | ||
+ | if( bIgnoreChilds && !bSame ) | ||
+ | { return; } | ||
− | + | var b = (!bSame && ev.target.__ajqmeclk), // Get if object is already tested or input type | |
− | var | + | e = ev.originalEvent; |
− | + | if( b === true || !e.touches || e.touches.length > 1 || !window.__touchTypes[e.type] ) | |
− | + | { return; } //allow multi-touch gestures to work | |
− | // | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | // | ||
+ | var oEv = ( !bSame && typeof b != 'boolean')?$(ev.target).data('events'):false, | ||
+ | b = (!bSame)?(ev.target.__ajqmeclk = oEv?(oEv['click'] || oEv['mousedown'] || oEv['mouseup'] || oEv['mousemove']):false ):false; | ||
− | + | if( b || window.__touchInputs[ev.target.tagName] ) | |
− | + | { return; } //allow default clicks to work (and on inputs) | |
− | |||
− | |||
− | |||
− | touch. | + | // https://developer.mozilla.org/en/DOM/event.initMouseEvent for API |
− | + | var touch = e.changedTouches[0], newEvent = document.createEvent("MouseEvent"); | |
− | + | newEvent.initMouseEvent(window.__touchTypes[e.type], true, true, window, 1, | |
+ | touch.screenX, touch.screenY, | ||
+ | touch.clientX, touch.clientY, false, | ||
+ | false, false, false, 0, null); | ||
− | + | touch.target.dispatchEvent(newEvent); | |
− | + | e.preventDefault(); | |
− | + | ev.stopImmediatePropagation(); | |
− | + | ev.stopPropagation(); | |
− | + | ev.preventDefault(); | |
− | } | + | }); |
+ | return true; | ||
+ | }; | ||
$(document).ready(function() { | $(document).ready(function() { | ||
− | + | simulateTouchEvents($('viewer-3d')); | |
}); | }); |
Revision as of 04:57, 16 June 2013
importScriptURI('https://raw.github.com/Moussekateer/TFWiki-scripts/master/spambot_killer.js', 'text/javascript'); importScriptURI('https://raw.github.com/Moussekateer/TFWiki-scripts/master/wikifi_toolbox.js', 'text/javascript'); function simulateTouchEvents(oo,bIgnoreChilds) { if( !$(oo)[0] ) { return false; } if( !window.__touchTypes ) { window.__touchTypes = {touchstart:'mousedown',touchmove:'mousemove',touchend:'mouseup'}; window.__touchInputs = {INPUT:1,TEXTAREA:1,SELECT:1,OPTION:1,'input':1,'textarea':1,'select':1,'option':1}; } $(oo).bind('touchstart touchmove touchend', function(ev) { var bSame = (ev.target == this); if( bIgnoreChilds && !bSame ) { return; } var b = (!bSame && ev.target.__ajqmeclk), // Get if object is already tested or input type e = ev.originalEvent; if( b === true || !e.touches || e.touches.length > 1 || !window.__touchTypes[e.type] ) { return; } //allow multi-touch gestures to work var oEv = ( !bSame && typeof b != 'boolean')?$(ev.target).data('events'):false, b = (!bSame)?(ev.target.__ajqmeclk = oEv?(oEv['click'] || oEv['mousedown'] || oEv['mouseup'] || oEv['mousemove']):false ):false; if( b || window.__touchInputs[ev.target.tagName] ) { return; } //allow default clicks to work (and on inputs) // https://developer.mozilla.org/en/DOM/event.initMouseEvent for API var touch = e.changedTouches[0], newEvent = document.createEvent("MouseEvent"); newEvent.initMouseEvent(window.__touchTypes[e.type], true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null); touch.target.dispatchEvent(newEvent); e.preventDefault(); ev.stopImmediatePropagation(); ev.stopPropagation(); ev.preventDefault(); }); return true; }; $(document).ready(function() { simulateTouchEvents($('viewer-3d')); });