Giter Club home page Giter Club logo

mootools-mobile's Introduction

Mobile

Makes your web applications more touching. Provides a touch event handler that automatically replaces all your click handlers with touch listeners to overcome the click delay on iOS. Requires MooTools Core 1.3.

Build

Build via Packager, requires MooTools Core to be registered to Packager already

./packager register /path/to/mobile
./packager build Mobile/* > mobile.js

How To Use

If you include Touch/Touch.js (and dependencies) into your application, all click events will automatically be replaced with touch events.

myElement.addEvent('click', function(event){
	// on iOS the click handler has been replaced with touchend
	
	// doSomething
}):

For more information see the included Demo.

Swipe Custom Event

The file Touch/Swipe.js provides a custom swipe event for your elements

myElement.addEvent('swipe', function(event){
	event.direction // either 'left' or 'right'

	event.start // {x: Number, y: Number} where the swipe started
	event.end // {x: Number, y: Number} where the swipe ended
});

Additionally there are some options for swipe events

myElement.store('swipe:distance', 20); // (defaults to 50) amount of pixels to be moved until swipe is being fired
myElement.store('swipe:cancelVertical', true); // (defaults to false) Whether to cancel swipes if the user moved vertically

Pinch Custom Event

The file Touch/Pinch.js provides a custom pinch event for your elements

myElement.addEvent('pinch', function(event){
	event.pinch // Either 'in' or 'out'
});

Additionally there is a threshold option for pinch events

myElement.store('pinch:threshold', 0.4); // (defaults to 0.5) the amount of scaling to be done to fire the pinch event

Touchhold Custom Event

The file Touch/Touchhold.js provides a custom touchhold event for your elements

myElement.addEvent('touchhold', function(event){
	// Touchhold fired
});

Additionally there is delay option for touchhold events

myElement.store('touchhold:delay', 1000); // (defaults to 750) the amount of time in ms to wait until the touchhold event gets fired

Browser Information

To execute code on browsers with touch events available use Browser/Features.Touch.js

if (Browser.Features.Touch){
	// This browser definitely has touch events!
}

Access useful information about the browser environment via Browser/Mobile.js

Browser.Device // Object added to Browser

Browser.Device.name // ipad / iphone / ipod OR other

Browser.Device.ipad // true if on ipad
Browser.Device.iphone // true if on iphone
Browser.Device.ipod // true if on ipod

Browser.hasHighResolution // true on iPhone 4

Browser.isMobile // True on any platform that is not Windows / Linux / Mac

Tips

For an optimal experience use the following CSS Styles

body {
	-webkit-tap-highlight-color: transparent;
}

For elements with touch events use

#myElement {
	-webkit-user-select: none;
}

In addition to that, because the code uses "document.elementFromPoint", it is wise to set pointer-events to none for elements within click handler elements. Usually "a *" as a selector is sufficient, but it should be applied to any overlaying elements that might get in your way.

a * {
	pointer-events: none;
}

Also, to prevent moving the whole page in iOS you can add this script

document.addEvent('touchmove', function(event){
	event.preventDefault();
});

ToDo

  • Click overwrite should probably pass a fake click event (?)
  • Add Android support and add useful Android information
  • Add webOS support and add useful webOS information
  • Remove Chrome 5 fix once Chrome 5 is dead (end of 2010?).

mootools-mobile's People

Contributors

cbeloch avatar cpojer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.