Difference between revisions of "User:Moussekateer/vector.js"

From Team Fortress Wiki
Jump to: navigation, search
m
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)
+
// hai
{
+
var clickms = 250;
if( !$(oo)[0] )
+
var lastTouchDown = -1;
  { return false; }
+
// /hai
 +
 
 +
 
 +
 
 +
function touchHandler(event) {
 +
    var touch = event.changedTouches[0];
  
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)
+
// hai
 +
var d = new Date();
 +
switch(event.type)
 
{
 
{
     var bSame = (ev.target == this);
+
     case "touchstart": type = "mousedown"; lastTouchDown = d.getTime(); break;
     if( bIgnoreChilds && !bSame )
+
    case "touchmove": type="mousemove"; lastTouchDown = -1; break;      
    { return; }
+
     case "touchend": if(lastTouchDown > -1 && (d.getTime() - lastTouchDown) < clickms){lastTouchDown = -1; type="click"; break;} type="mouseup"; break;
 
+
     default: return;
    var b = (!bSame && ev.target.__ajqmeclk), // Get if object is already tested or input type
+
}
        e = ev.originalEvent;
+
// /hai
     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] )
+
     var simulatedEvent = document.createEvent("MouseEvent");
    { return; } //allow default clicks to work (and on inputs)
+
        simulatedEvent.initMouseEvent(type, true, true, window, 1,
 +
        touch.screenX, touch.screenY,
 +
        touch.clientX, touch.clientY, false,
 +
        false, false, false, 0, null);
  
     // https://developer.mozilla.org/en/DOM/event.initMouseEvent for API
+
     touch.target.dispatchEvent(simulatedEvent);
    var touch = e.changedTouches[0], newEvent = document.createEvent("MouseEvent");
+
     event.preventDefault();
     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);
+
function touchinit() {
     e.preventDefault();
+
     $('.viewer-3d').addEventListener("touchstart", touchHandler, true);
     ev.stopImmediatePropagation();
+
     $('.viewer-3d').addEventListener("touchmove", touchHandler, true);
     ev.stopPropagation();
+
     $('.viewer-3d').addEventListener("touchend", touchHandler, true);
    ev.preventDefault();
+
     $('.viewer-3d').addEventListener("touchcancel", touchHandler, true);
});
+
}
return true;
 
};
 
  
 
$(document).ready(function() {
 
$(document).ready(function() {
   simulateTouchEvents($('viewer-3d'));
+
   touchinit();
 
});
 
});

Revision as of 05:05, 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');

// hai
var clickms = 250;
var lastTouchDown = -1;
// /hai



function touchHandler(event) {
    var touch = event.changedTouches[0];


// hai
var d = new Date();
switch(event.type)
{
    case "touchstart": type = "mousedown"; lastTouchDown = d.getTime(); break;
    case "touchmove": type="mousemove"; lastTouchDown = -1; break;        
    case "touchend": if(lastTouchDown > -1 && (d.getTime() - lastTouchDown) < clickms){lastTouchDown = -1; type="click"; break;} type="mouseup"; break;
    default: return;
}
// /hai


    var simulatedEvent = document.createEvent("MouseEvent");
        simulatedEvent.initMouseEvent(type, true, true, window, 1,
        touch.screenX, touch.screenY,
        touch.clientX, touch.clientY, false,
        false, false, false, 0, null);

    touch.target.dispatchEvent(simulatedEvent);
    event.preventDefault();
}

function touchinit() {
    $('.viewer-3d').addEventListener("touchstart", touchHandler, true);
    $('.viewer-3d').addEventListener("touchmove", touchHandler, true);
    $('.viewer-3d').addEventListener("touchend", touchHandler, true);
    $('.viewer-3d').addEventListener("touchcancel", touchHandler, true);
}

$(document).ready(function() {
  touchinit();
});