Search code examples
jqueryblackberry-simulatorblackberry-playbookripple

Playbook WebWorks jQuery on ready being called twice


I'm trying my hand at developing an app for Blackberry Playbook (Yes, I know, it's dead.. bear with me).

I'm using a simple WebWorks app and my jQuery ready() function appears to be called twice when I load my page.

<!doctype html>
<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                    alert("ready");
            });
        </script>
    </head>
    <body>
        Hello World.
    </body>
</html>

Any idea why this would happen? I'm testing in the Ripple simulator for Playbook.


Solution

  • I am pretty sure that the current version of Ripple, on Windows anyway, loads the page twice. It has nothing to do with jQuery (or CoffeScript which I am also using).

    The solution I have that works, even if I don't like it is:

    // earlier
    var runner = function() {
      alert('ready');
    };
    
    // later
    $(function() {
      if(window.tinyHippos) {
        setTimeout(runner, 3000);
      } else {
        runner();
      }
    });
    

    Pretty hacky, but it seems to work. Hopefully in Ripple's next iteration the double-load will go away.