|
CallbackEvents
Built-in Triggers/Events in jQTouch.
Events must be added after document has loaded. For this, we use the jQuery .ready() method. Page Animations
$(document).ready(function(e){
$('#portfolio').bind('pageAnimationEnd', function(event, info){
if (info.direction == 'in') loadWorks();
})
});Orientation Changes $(function(){
$('body').bind('turn', function(event, info){
console.log(info.orientation); // landscape or profile
});
});Touch EventsTouch events will only trigger on items which are initialized, either automatically via the initialization function (initializeTouch: 'a, .touchable') or manually ( $('#mydiv').addTouchEvents()). $(function(){
$('#swipeme').bind('swipe', function(event, info){
console.log(info.direction);
});
});You can also use the jQuery-style event shortcut, like: $(function(){
$('#swipeme').swipe( function(event, info){
console.log(info.direction);
});
});
|
Sign in to add a comment
I'm pretty sure console.log(info.orientation); // landscape or portrait should be console.log(info.orientation); // landscape or profile
Is there a way to force rotation to landscape?
I wanted to be able to attach an onsubmit to forms, here is how I did in in jqtouch.js about line 472.
function submitForm(e, callback){ var $form = (typeof(e)==='string') ? $(e) : $(e.target); if ($form.length && $form.is(jQTSettings.formSelector) && $form.attr('action')) { var onsubmit = false; if($form.attr('onsubmit')){onsubmit = (new Function($form.attr('onsubmit')))()}; if(onsubmit) { showPageByHref($form.attr('action'), { data: $form.serialize(), method: $form.attr('method') || "POST", animation: animations[0] || null, callback: callback }); } return false; } return true; }This allows you to use onsubmit like you regularly would. Note that you can not however use arguments ( which I usually use something like onsubmit="return validate(this)".
Not sure this is the best way to do it but this worked and I thought I'd share :)
paul.vudmaska,
You can just use the jQuery form submit event handler. The jqTouch submit is attached to the html body, so the submit event on the form will be called first. If you wish to stop the submit from going through, just use event.Propagation() or event.stopImmediatePropagation()
basic example:
$(function() { $('#theFormId').submit(function(e) { validateFields(); if (error) { e.stopImmediatePropagation(); alert(error); } }); });