You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by "Patrick Mueller (Commented) (JIRA)" <ji...@apache.org> on 2012/04/20 19:54:40 UTC
[jira] [Commented] (CB-551) deviceready is fired every time
changePage() is called in jQuery Mobile within a single-page app
[ https://issues.apache.org/jira/browse/CB-551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13258416#comment-13258416 ]
Patrick Mueller commented on CB-551:
------------------------------------
Personally, I avoid all the "external content" stuff when I use jQuery mobile, inline everything, so not a lot of experience here.
Not sure if this is the problem, but pretty sure there is some way to have jQuery Mobile work via page reloading - in the case of traversing to a new "page" that is actually external. I think you can swizzle it to XHR the content instead, bypassing the need for an actual page reload.
Even in the case of XHRing the content instead of traversing to a new page, if you're updating location at all, not hard to imagine that might trigger the page reload-y bits of Cordova. We may need to kind of bullet-proof this stuff and check to see if Cordova is already loaded before running through the deviceReady logic.
If jQuery does have a mode of actually reloading pages, then we WILL actually need to re-init the Cordova bits in the browser again. But we should do the right thing if they just update location and the browser doesn't actually reload the page.
> deviceready is fired every time changePage() is called in jQuery Mobile within a single-page app
> ------------------------------------------------------------------------------------------------
>
> Key: CB-551
> URL: https://issues.apache.org/jira/browse/CB-551
> Project: Apache Callback
> Issue Type: Bug
> Components: BlackBerry
> Affects Versions: 1.6.0
> Reporter: Filip Maj
> Assignee: Filip Maj
>
> Taken from http://stackoverflow.com/questions/10173155/deviceready-called-everytime-i-do-a-changepage-in-blackberry
> Single page app. When switching view divs, something triggers deviceready to be called again. Likely something to do with the {{location.href}} changing. Probably shouldn't be happening.
> Example code:
> {code}
> <!DOCTYPE html>
> <html>
> <head>
> <meta charset="UTF-8">
> <meta name="viewport" id="viewport" content="width=device-width,height=device- height,initial-scale=1.0,user-scalable=no">
> <script src="cordova-1.6.0.js" type="text/javascript"></script>
> <script type="text/javascript" src="jquery/jquery-1.7.1.min.js"></script>
> <link rel="stylesheet" href="jquerymobile/jquery.mobile-1.1.0.min.css" />
> <script type="text/javascript" src="jquerymobile/jquery.mobile-1.1.0.min.js"></script>
> <script type="text/javascript">
> //---------------------------------------------------------------------
> // Cordova event listeners
> //---------------------------------------------------------------------
> function onDeviceReady() {
> alert("Inside Device Ready");
> }
> // register Cordova event listeners when DOM content loaded
> function init() {
> console.log('init()');
> document.addEventListener("deviceready", onDeviceReady, true);
> }
> </script>
> <title>Cordova API Sample</title>
> </head>
> <body onload="init()">
> <div data-role="page" id="home">
> <div data-role="header">
> <h1>Here is the index page.</h1>
> </div>
> <div data-role="content">
> <p><center>Below you may transition to our other pages.</center></p>
> <a href="#about" data-ajax="false" data-role="button" data-inline="true">About Me</a>
> </div>
> </div>
> <div data-role="page" id="about">
> <div data-role="header">
> <h1>About Us</h1>
> </div>
> <div data-role="content">
> <a href="#home" data-ajax="false" data-role="button" data-inline="true">Back Home</a>
> </div>
> </div>
> </body>
> </html>
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira