Skip to content

Instantly share code, notes, and snippets.

@GCheung55
Forked from SchizoDuckie/apf_release.prepend.js
Created March 21, 2012 18:21
Show Gist options
  • Save GCheung55/2150710 to your computer and use it in GitHub Desktop.
Save GCheung55/2150710 to your computer and use it in GitHub Desktop.
Cloud9 IDE Touch Enabler Monkeypatch
/**
* A proof of concept monkeypatch to make Cloud9 IDE work on a tablet.
* Since i'm an extremely lazy bastard I prepended this snippet directly in package/client/js/apf_release.js
*
* What does it do?
* - It fires a doubleclick for a 2-finger tap
* - It fires a mousewheel up / down event for a 2-finger swipe up / down.
*
* How does it work?
* Prepend the functions below to <cloud9>/package/client/js/apf_release.js, save, load in tablet.
* - 2-finger tap a file to open it from the tree
* - 2-finger swipe up/down to scroll up/down
*
* Why 2-finger events?
* - I Didn't want to mess with any existing bindings.
*
* Tested on Galaxy Tab 10.1
*/
var startY = 0; // for filtering small movements
// fire doubleclick event for 2 finger touches
document.body.addEventListener('touchstart', function(e) {
var touch = e.touches[0];
if ( !touch || e.touches.length < 2) return;
startY = touch.clientY;
var me = document.createEvent("MouseEvents");
me.initMouseEvent('dblclick', true, true, window, 1, touch.clientY, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, e.target );
touch.target.dispatchEvent(me);
},false);
// fire mousewheel events for swipe up/down
document.body.addEventListener('touchmove', function(e) {
var touch = e.touches[0];
if ( !touch || e.touches.length < 2 || Math.abs(touch.clientY - startY) < 10) return; // filter small movement
var direction = (touch.clientY - startY) > 0 ? 'up': 'down',
me = document.createEvent("MouseEvents"),
wheelData = (direction == 'up') ? 10 : -10;
me.initMouseEvent("mousewheel", true, true, window, wheelData, 0, 0, 0, 0, false, false, false, false, 0, touch.target );
touch.target.dispatchEvent(me);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment