Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goTo() no longer support external urls (custom fix inside) #523

Open
tegola opened this issue Mar 19, 2015 · 3 comments
Open

goTo() no longer support external urls (custom fix inside) #523

tegola opened this issue Mar 19, 2015 · 3 comments

Comments

@tegola
Copy link

tegola commented Mar 19, 2015

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

@tegola
Copy link
Author

tegola commented Mar 19, 2015

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.

@tegola tegola changed the title goTo() no longer support external urls goTo() no longer support external urls (custom fix found) Mar 27, 2015
@tegola tegola changed the title goTo() no longer support external urls (custom fix found) goTo() no longer support external urls (custom fix inside) Mar 27, 2015
@tnmtechnologies
Copy link

Thanks @tegola for this fix. I used it for an old jQTouch version.

@tegola
Copy link
Author

tegola commented Jun 19, 2016

I'm glad it helped 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants