My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PublicObject  
Manipulating jQTouch directly with Javascript
Featured
Updated Oct 5, 2009 by davidcol...@gmail.com

Public Functions

jQTouch returns a public object when initialized, which can be assigned to a variable (in this case, the variable name is "jQT"):

<script>
    var jQT = new $.jQTouch();
</script>

This public variable has several functions which allow you to directly manipulate jQTouch via Javascript. It is recommended you call these function after the document.ready event. These public functions are:

goTo( pageid: string, animation: string )

Forces jQTouch to animate to a new page (pageid), with the listed animation.

Example: jQT.goTo('#newpage', 'flip');

goBack( to:object )

Forces jQTouch to go back to a certain page in the history. You can pass a specific page ID, a number of pages to go back, or nothing to go back one page. If the specified page can not be found, jQTouch will go back one page by default. Example:

jQT.goBack(2); // Goes back 2 pages in history
jQT.goBack('#home'); // Goes to #home as long as it's in history
jQT.goBack(); // Goes back 1 page in history

addAnimation( animation:Object )

Allows the author to dynamically add custom page animations. For more information, see Animations.

Example:

jQT.addAnimation({ name: 'reveal', selector: '.revealme' });
Comment by j...@mobosplash.com, Jan 4, 2010

I'm using jQT.goTo('#newpage', 'flip') to bring up a new page but whenever I hit back on that page (with the standard jqtouch back button in the toolbar) nothing happens. Looking in Firebug I get an error of "No pages in history." that looks like it happens on the goBack function.

Comment by maral...@gmail.com, Mar 11, 2010

Yes, I am experiencing the same problem here. It seems that the goTo function does not update the history stack. Anyone know of a workaround?

Comment by cypherlo...@gmail.com, Mar 17, 2010

Is there any way to remove a given page from the history? I have a situation where;

1. user clicks a link on a page (page_A)
2. system does a goTo() to a holding page (with spinner or similar) (page_B)
3. page loads in background and does a goTo() to newly loaded page (page_C)
4. back link on newly loaded page (page_C) (automatically generated) needs to go page_A not page_B.

Is there any programmatic way to remove page_B from the history when I transition? Possible in the pageAnimationEnd callback or similar?

Comment by cypherlo...@gmail.com, Mar 19, 2010

Hi, Further to the comments above by maralbjo and above, I notice on the console that there is an 'unknown hash change' at line 408 of jqtouch.js and then a loop logging endlessly 'No pages in history' at line 237. This is only the case if you press the browser back key on the very first (entry) page. It works on all subsequent pages, just not the first one.

Comment by maral...@gmail.com, Mar 23, 2010

The goTo function kind of messes up the history stack a bit. As an alternative, I have had some success with simulating a user press on the back button instead. In order to do that, one must give the back button an ID in order to target it with JQuery. Giving the back button an idea feels odd, but it works despite an error from the jqtouch.js saying: $referrer is not defined.

Comment by cypherlo...@gmail.com, Mar 24, 2010

maralbjo, when you say give the back button an id, can you elaborate? You mean the browser back button? How do you do this?

Comment by webmas...@town2web.com, Mar 24, 2010

I'm wondering where can I add code ((#inputfield).focus()) after automatics goTo. If I write the button click action, I write the goTo and AFTER I write the .focus, but after an automatic goTo where can I put the focus code? If I put it on the onclick in the menu action, is executed before the goTo and after the div page get the focus, the input field lost focus...

Comment by php_n...@yahoo.com, Mar 24, 2010

how to redirect link to a new page ?

above code is not understandable for me..

Comment by cypherlo...@gmail.com, Mar 24, 2010

webmas...@town2web.com Ar you not best attaching the focus operation to the end of animation callback? I suspect it need to be done as the last thing that happens, otherwise you can't count on the page being 'settled', as you have discovered.

Glenn

Comment by maral...@gmail.com, Mar 25, 2010

@cypherlou666: Often I find that I want to send the user back the previous screen after he has performed some action. If I use the goTo-function, that leads to unwanted history stacking, but using this approach works fine:

<div class="toolbar">

<h1>Utgangstid</h1> <a class="button back" id="backToPrev" ref="#target">Back</a> <a class="button flip" href="#help">Help</a>
</div> <div> (main content) </div>

// Send the user back instead of using goTo (using JQuery) $("#backToAdvanced").click();

Comment by maral...@gmail.com, Mar 25, 2010

(That didn't quite format as I intended, sorry)

Comment by maral...@gmail.com, Mar 26, 2010

Although (@cypherlou666), you should be ware of  issue 102  that in my opinion renders this functionality obsolete. A fix/workaroud would be warmly appreciated.

http://code.google.com/p/jqtouch/issues/detail?id=102#makechanges

Comment by ricky.de...@gmail.com, Mar 31, 2010

Is there a way to create a link (normally something like <a href="mailto:my@email.com">Email</a>) to send a file, with JQTouch/Javascript?

Comment by cypherlo...@gmail.com, Apr 19, 2010

ricky.dejong It clearly states in the i-phone web-app developers documentation that this is not a supported feature of the device. If you/anyone else knows to the contrary then I would be interested to hear.

glenn

Comment by jimmybro...@gmail.com, Jun 30, 2010

Trying to figure out how to disable a link if it exists on the page the link is linking to. Anyone know how to do this? Or even how to return the name or ID of the current page?

I have a global toolbar and say you click "Home" while you're already on the home page, the app goes nuts and gives you a blank page.

Comment by GTUi...@gmail.com, Jul 2, 2010

Help me i need examples of the function goTo

Comment by vyle...@gmail.com, Aug 2, 2010

is there a way to find out what page are you currently in?

Comment by cyberm...@gmail.com, Aug 10, 2010

<is there a way to find out what page are you currently in?>

currentpage = $('.current').attr('id');

Comment by dax2...@gmail.com, Nov 5, 2010

hi, someone know if is possible send goTo another page html or jsp? many thanks!

Comment by sirmark@gmail.com, Jan 2, 2011

jimmybrooks.com, i was running into the same issue. The workaround that i found was to add in an if statement that checks to see if the toPage is equal to the fromPage. A rewrite for the animate pages function is below. Replace it with the one at line 332 in jqtouch.js. Hope this helps.

function animatePages(fromPage, toPage, animation, backwards) {

if (fromPage.selector == toPage.selector){
// do nothing
}else{
// Error check for target page if(toPage.length === 0){
$.fn.unselect(); console.error('Target element is missing.'); return false;
}
// Collapse the keyboard $(':focus').blur();
// Make sure we are scrolled up to hide location bar scrollTo(0, 0);
// Define callback to run after animation completes var callback = function(event){
if (animation) {
toPage.removeClass('in reverse ' + animation.name); fromPage.removeClass('current out reverse ' + animation.name);
} else {
fromPage.removeClass('current');
}
toPage.trigger('pageAnimationEnd', { direction: 'in' }); fromPage.trigger('pageAnimationEnd', { direction: 'out' });
clearInterval(dumbLoop); currentPage = toPage; location.hash = currentPage.attr('id'); dumbLoopStart();
var $originallink = toPage.data('referrer'); if ($originallink) {
$originallink.unselect();
} lastAnimationTime = (new Date()).getTime(); tapReady = true;
}
fromPage.trigger('pageAnimationStart', { direction: 'out' }); toPage.trigger('pageAnimationStart', { direction: 'in' });
if ($.support.WebKitAnimationEvent? && animation && jQTSettings.useAnimations) {
toPage.one('webkitAnimationEnd', callback); tapReady = false; toPage.addClass(animation.name + ' in current ' + (backwards ? ' reverse' : '')); fromPage.addClass(animation.name + ' out' + (backwards ? ' reverse' : ''));
} else {
toPage.addClass('current'); callback();
}
return true;
}

Comment by josemari...@gmail.com, Jan 12, 2011

Is it possible to load a new page and go to a specified id?

Ex: $('.class').click(function(){

location.href('index.html'); //This works but i want to add an id to load the specified content
});

Comment by sf20...@gmail.com, Jun 6, 2011

@ sirmark Can you dubblecheck your function? This has lots of syntax issues in it. Lots of { are closed although they where not opened.

Comment by BrentMCl...@gmail.com, Jun 30, 2011

I am looking for a way for people to pass jqTouch links around and have them work as one would expect them to. For example: jqTouch follows www.mysite.com/ContactUs?.html and loads the ContactUs? form on to the screen. It then sets the page URL to www.mysite.com/#ContactUs?. If the user then copies this URL and e-mails it to a friend the friend can not get back to that page because it's not in history and "#ContactUs?" means nothing to jqTouch on first entry.

I already know of one way to do this but I am looking for best practice. What's recommended?

Comment by GnkMahen...@gmail.com, Jan 11, 2012

hello there,. i ve problem, can you help me,.. i want to add animation in "go to" script,. i try this:

$('#laFactory').swipeLeft(function(e, info){

jQT.goTo($('#pro', 'slideleft'));
}); $('#pro').swipeLeft(function(e, info){
jQT.goTo($('#facile', 'slideleft'));
})
$('#facile').swipeLeft(function(e, info){
jQT.goTo($('#modulable', 'slideleft'));
})
$('#modulable').swipeLeft(function(e, info){
jQT.goTo($('#ethique', 'slideleft'));
})
// SWIPE RIGHT
$('#pro').swipeRight(function(e, info){
jQT.goTo($('#laFactory', 'slideright'));
})
$('#facile').swipeRight(function(e, info){
jQT.goTo($('#pro', 'slideright'));
})
$('#modulable').swipeRight(function(e, info){
jQT.goTo($('#facile', 'slideright'));
}) $('#ethique').swipeRight(function(e, info){
jQT.goTo($('#modulable', 'slideright'));
})

but still not add animation,.. i dont know what is wrong,. sorry for my english,..

thank regards.

Comment by omicron....@gmail.com, Jan 17, 2012

@GnkMahen?

Hi, you do not need to use selector in the goTo parameter.

Simply do this instead > jQT.goTo('#id', 'slideleft');

Comment by naveenmo...@gmail.com, Feb 17, 2012

To disable jqt back button navigation comment the following lines in goBack() function and return false from goBack() function.

//if (doNavigation(from.page, to.page, from.animation, true)) {

// return publicObj; //} else { // //debug('Could not go back.'); // return false; //} return false;


Sign in to add a comment
Powered by Google Project Hosting