A module of buttons for the mobile web
$ npm install mobile-button --save
Require mobile-button
var MButton = require('mobile-button');
All buttons have the following methods:
- setEl(el:DOMElement): set the button dom element
- setF(f:function): set the callback function
- bind(): attach all events handlers
- unbind(): remove all events handlers
All common options:
- el:DOMElement, the button dom element
- f:function, the callback function
- activeCls:String, the css active class
- autobind:Boolean, option to auto bind the button, if el is already available
- monotouchable:Boolean, option to create a button a mono touchable element
- setActiveCls:Boolean, option to control if the css active class is used or not, default to true
The callback function can return a promise. If so, the button will wait until it's fulfilled to return to an inactive state.
Default Buttons are contained only in non scrollable elements.
A touchstart button triggers his callback on touchstart.
It accepts a delay option.
var btn = new MButton.Touchstart({
el: myElement,
f: function () {
alert('...');
},
delay: 500 // in ms
});
A touchend button triggers his callback on touchend if the finger is in the active zone of the underlying button dom element.
This button accepts a activeBorder option in px.
var btn = new MButton.Touchend({
el: myElement,
f: function () {
alert('...');
},
activeBorder: 20 // in px
});
A push button triggers the f
callback on touchstart and the g
callback on
touchend or when the finger leaves the active zone of the underlying button dom
element. As f
and g
are chained g
always executes after f
.
This button accepts a delay and a g function in the options
object.
var btn = new MButton.Push({
el: myElement,
f: function () {
alert('f');
},
g: function () {
alert('g');
},
delay: 500 // in ms
});
Buttons contained in a Y scrollable element (iscroll or on ios 5+ with -webkit-overflow-scrolling:touch;).
This touchend button will get canceled if the fingermove more than tolerance pixels in the Y axis. It extends the default touchend button.
This button accepts a tolerance option in px.
var ScrollableBtn = require('mobile-button').ScrollableY;
var btn = new ScrollableBtn.Touchend({
el: myElement,
f: function () {
alert('...');
},
tolerance: 5 // in px
});
Buttons contained in a X scrollable element (iscroll or on ios 5+ with -webkit-overflow-scrolling:touch;).
This touchend button will get canceled if the fingermove more than tolerance pixels in the X axis. It extends the default touchend button.
This button accepts a tolerance option in px.
var ScrollableBtn = require('mobile-button').ScrollableX;
var btn = new ScrollableBtn.Touchend({
el: myElement,
f: function () {
alert('...');
},
tolerance: 5 // in px
});
to build examples and tests
npm install
npm run build
Check the examples.
Design taken from @Noxdzine Orange UI kit
run the tests
- fix
touchcancel
usage #24
- Add
setActiveCls
option
- Add a PushButton which accepts two callback functions.
- Better handling of exceptions thrown from callback function with
Q.done
- Add
monotouchable
option
- Replaced the ClickButton with default, scrollable-x and scrollable-y buttons based on mouse events. The mobile button behavior is now consistent across all platforms, mobile and desktop.
- Handling pointer events.
autobind:true
by default now. No need tobind()
when you don't need it!
to upgrade from <= v0.2.0, you need to remove some bind()
calls or add autobind:false
to the button option.
- quick and dirty click buttons...
- fix buttons when f the callback button function returns rejected promises.
- Touchend buttons: remove active class on
touchend
- upgrade q to 1.0.0
- back to iscroll, 5.0.9 supports commonjs
- using iscroll-browserify for scrollable views
- preventDefault some
touchmove
for chrome on android - fix ie tests
- initial release
- Handling touchevents on scroll (or why the 0.0.3 will include iscroll for scrollables...): https://docs.google.com/document/d/12k_LL_Ot9GjF8zGWP9eI_3IMbSizD72susba0frg44Y