This repository was archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Events
wGEric edited this page Sep 14, 2011
·
1 revision
Binding events adds the event listener to the object. Unbinding removes the listener. Events can be chained.
Titanium Code
var scrollview = Titanium.UI.createScrollView();
scrollview.addEventListener('click', function() {
// do something
});
scrollview.addEventListener('dblclick', function() {
scrollview.removeEventListener('click');
});
TiQuery
var scrollview = $.ScrollView();
$(scrollview).bind('click', function() {
// do something
}).bind('dblclick', function() {
$(scrollview).unbind('click');
});
Events can be triggered through the code using $(element).trigger();
Titanium
scrollview.fireEvent('click');
TiQuery
$(scrollview).trigger('click');
TiQuery adds shortcuts to common events so that you don't have to type as much. For example:
$(scrollview).click(function() {
alert('I was clicked');
});
That will bind a click event to the scrollview. If you don't pass a parameter into the shortcut then it will trigger the event. The following example would trigger the click event on the scrollview.
$(scrollview).click();
Here are all of the available shortcuts:
- blur
- cancel
- click
- dblclick
- doubletap
- focus
- orientationchange
- scroll
- shake
- singletap
- swipe
- touchcancel
- touchend
- touchmove
- touchstart
- twofingertap
You can register shortcuts for your own events using registerEvent.
$.registerEvent('myEvent');
$(scrollview).myEvent(function() {
// do something
});
$(scrollview).myEvent();