jQTouch
jQTouch copied to clipboard
goTo() no longer support external urls (custom fix inside)
Hello, I'm hoping this project has still a little support from the community. I've switched from a pre-coffeescript version of jqtouch to the latest one, and I am having troubles porting my app.
The main issue is that the goTo
method, that once supported both IDs and urls, now gives an error.
With Zepto:
> jQT.goTo('mobile/projects')
zepto.js:261 Uncaught DOMException: Failed to execute 'querySelectorAll' on 'Document': '/mobile/projects' is not a valid selector.
zepto.js:261 zepto.qsa
zepto.js:188 zepto.init
zepto.js:218 $
jqt.js:243 (anonymous function)
VM4881:2 (anonymous function)
VM4846:847 InjectedScript._evaluateOn
VM4846:780 InjectedScript._evaluateAndWrap
VM4846:646 InjectedScript.evaluate
With jQuery 2 + jqtouch-jquery2.js:
> jQT.goTo('mobile/projects')
jquery-2.1.3.js:1453 Uncaught Error: Syntax error, unrecognized expression: mobile/projects
jquery-2.1.3.js:1453 Sizzle.error
jquery-2.1.3.js:2070 Sizzle.tokenize
jquery-2.1.3.js:2474 Sizzle.select
jquery-2.1.3.js:850 Sizzle
jquery-2.1.3.js:2690 jQuery.fn.extend.find
jquery-2.1.3.js:2798 jQuery.fn.init
jquery-2.1.3.js:76 jQuery
jqt.js:243 (anonymous function)
VM4896:2 (anonymous function)
VM4894:847 InjectedScript._evaluateOn
VM4894:780 InjectedScript._evaluateAndWrap
VM4894:646 InjectedScript.evaluate
Any cue?
Thanks
After playing a bit with the js file generated by CoffeeScript (which I'm not familiar with), I've managed to fix it:
Here's the original bit:
if (typeof toPage === "string") {
nextPage = $(toPage);
if (!nextPage.length) {
showPageByHref(toPage, {
animation: animation
});
return;
} else {
toPage = nextPage;
}
}
And here's the fix:
if (typeof toPage === "string") {
try {
nextPage = $(toPage);
}
catch(e){
// toPage was not a valid selector
showPageByHref(toPage, {
animation: animation
});
return;
}
toPage = nextPage;
}
I'm not sure if it's the right fix, but it works for me. Summoning @thomasyip and @davidkaneda to have a look at it and update the original CoffeeScript file.
Thanks @tegola for this fix. I used it for an old jQTouch version.
I'm glad it helped 👍