Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:01:07+00:00 2026-06-17T13:01:07+00:00

For a learning exercise I converted a sinatra/backbone app to the Rails environment. I

  • 0

For a learning exercise I converted a sinatra/backbone app to the Rails environment. I got it working on Chrome and Firefox but it doesn’t work on Safari. It turns out that the original app http://backbone-hangman.heroku.com doesn’t work on Safari either. When you click “new game” it doesn’t seem to fire an event. The Safari console doesn’t show any errors (although I’m not that experienced with Safari’s developer tools as I never use them).

Since there is a live version of the app available here http://backbone-hangman.heroku.com I won’t post a lot of code, but this is the view code that sets an event on click #new_game, triggering the startNewGame function. Nothing happens in Safari. Source code for the original is here https://github.com/trivektor/Backbone-Hangman

I googled a bit and found some mention of Safari treating events differently but couldn’t find a solution. Can any recommend anything?

$(function() {

  window.OptionsView = Backbone.View.extend({
    el: $("#options"),
    initialize: function() {
      this.model.bind("gameStartedEvent", this.removeGetAnswerButton, this);
      this.model.bind("guessCheckedEvent", this.showGetAnswerButton, this);
    },
    events: {
      'click #new_game': 'startNewGame',
      'click #show_answer': 'showAnswer'
    },
    startNewGame: function() {
      this.model.new();
    },
    removeGetAnswerButton: function() {
      $("#show_answer").remove();
    },
    showGetAnswerButton: function(response) {
      console.log("showGetAnswerButton");
      console.log(response);
      var threshold = this.model.get("threshold");
      console.log(threshold);
      if (response.incorrect_guesses == this.model.get("threshold")) {
        $(this.el).append('<input type="button" id="show_answer" class="action_button" value="Show answer" />');
      }
    },
    showAnswer: function() {
      this.model.get_answer();
    }
  })

})

Update

Based on one of the comments below the OP, I’m posting more code. This is hangman.js where the objects are instantiated

var game = new Game

  var options_view = new OptionsView({model: game});

  var characters_view = new CharactersView({model: game});

  var hint_view = new HintView({model: game});

  var word_view = new WordView({model: game});

  var hangman_view = new HangmanView({model: game});

  var answer_view = new AnswerView({model: game});
  var stage_view = new StageView({model: game});

The views and models are attached to the window like this

window.AnswerView = Backbone.View.extend({ ...

Update
Aside from Backbone, jQuery and Underscore which are loaded sitewide, the following files are loaded for this specific app in the Rails system.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:01:08+00:00Added an answer on June 17, 2026 at 1:01 pm

    This is jQuery + Safari issue (document.ready)

    You can just move your scripts inside the body tag and remove $(function(){ /**/ }) wrapper in every file.

    Also I added requirejs support and made pull request

    EDIT:

    First of all sorry for my English 🙂


    File views/index.haml:

    We should embed 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.


    File public/javascript/config.js:

    "deps" : ["hangman"]

    This means that application will start with hangman.js


    File public/javascript/hangman.js:

    We don’t need $(function() { wrapper because our script initialized from the body and document is already ‘ready’

    define([
      'models/game',
      'views/answerView',
      /* ... */
    ],
    function(Game, OptionsView, /* ... */) {
      // ...
    }
    

    Here we load our modules (first array element will be available in the first function argument and so on)


    Other files

    We just replace $(function() { with define(['backbone'], function(Backbone) {

    In the first line we load backbone module. When it will be fetched it will be available inside anonymous function (first parameter – Backbone)

    Next we should return the view to avoid undefined module value (public/javascript/hangman.js file should initialize a lot views. It can’t initialize undefined it should initialize Backbone.View that we should return)


    To learn more you should read requirejs documentation.
    I recomend you to start with this article

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a learning exercise, I'm trying to convert an existing Sinatra app to a
I'm writing a simple project management app as a learning exercise in Rails. I
As a learning exercise I'm building a basic scientific computation environment based on .NET.
I'm working on building a pretty simple site mainly as an exercise in learning
I'm learning Java at work, and the exercise we're supposed to do states the
I'm developing a Python web app as a learning exercise, and I am looking
This is a learning exercise in expression trees. I have this working code: class
I am working on a POSIX C learning exercise that involves recursively listing files/folders
As part of learning WPF I just finished working through an MS Lab Exercise
Here's the scoop: As a learning exercise, I'm trying to write a Rails clone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.