This is jQuery + Safari problem (document.ready)
You can simply transfer your scripts inside the body tag and remove the $(function(){ /**/ }) wrapper in each file.
I also added requirejs support and made a transfer request
EDIT:
First of all, sorry for my English :)
View /index.haml Files:
We have to insert js at the bottom of the page (to avoid Safari error)
= javascript_include_tag "javascript/require.js", :"data-main" => "javascript/config"
Here javascript/config is the path to requirejs config.
Publishing the /javascript/config.js file:
"deps" : ["hangman"]
This means the application will start with hangman.js
Publishing /javascript/hangman.js file:
We do not need a wrapper $(function() { , because our script, initialized from the body and the document, is already "ready"
define([ 'models/game', 'views/answerView', ], function(Game, OptionsView, /* ... */) {
Here we load our modules (the first element of the array will be available in the first argument of the function, etc.)
Other files
We simply replace $(function() { with define(['backbone'], function(Backbone) {
In the first line we load the base module. When it is extracted, it will be available inside an anonymous function (the first parameter is the Trunk)
Then we must return the view in order to avoid the value of the undefined module ( public/javascript/hangman.js file must initialize the views a lot. It is not possible to initialize undefined it must initialize the Backbone.View , which we must return)
To learn more, you should read the requirejs documentation. I recommend you start with this article.