Skip to content

Instantly share code, notes, and snippets.

@SchizoDuckie
Created March 20, 2012 20:19
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save SchizoDuckie/2140878 to your computer and use it in GitHub Desktop.
Save SchizoDuckie/2140878 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);
@fer
Copy link

fer commented Mar 21, 2012

Nice that now we can see this amazing IDE also from the bed... Nice work! Thanks!

@reynish
Copy link

reynish commented May 30, 2012

Good work! Hope they implement this soon.

@omar-shazly
Copy link

This is amazing! How can I prepend the functions to /package/client/js/apf_release.js?

@Jab2870
Copy link

Jab2870 commented Nov 27, 2012

Just started using cloud 9, how should I set this up?

@timfall
Copy link

timfall commented Apr 18, 2013

Fantastic work! Any interested in tests from an iPad?

Might also be worth making this available as an extension https://github.com/ajaxorg/cloud9/wiki/List-of-3rd-party-extensions

@pmarreck
Copy link

Two years later and they still haven't made this a standard feature. And the code (assuming it still works the way it is here, or with something just as simple) is right here.

How can you be SO CLOSE to an implementation of functionality on a completely new device and yet not actually take the little leap to get there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment