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 8495981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:43:28+00:00 2026-06-10T23:43:28+00:00

I am working on the following feature: When a user clicks on a photo

  • 0

I am working on the following feature: When a user clicks on a photo on the page, a modal modalView appears with more details of that item. In modalView, the user can click on the photo of another item, which will close the first modal window modalView and open a new modal window modalView containing full details of this next item. The opening and closing of modalViews are handled by the router functions.

(the user may experience a flicker, but thats another problem)

Problem: When the user clicks on the photo of another item within modalView, showModal() will cause the current modalView to close and the URL updates to that of the next item /product/1234, but the new modalView does not appear! Using console.log() to debug, I found that the first modalView closes, the 2nd modalView opens then closes!

What has happened, and how can this be fixed?

Router

var AppRouter = Backbone.Router.extend({
    routes: {,
        'product/:id': 'showModal'
    },


    showModal: function(id) {
        // Close any existing ModalView
        if(app.modalView) {
            app.modalView.closeModal();
            console.log('closing');
        }

        // Create new ModalView
        app.modalView = new ModalView({ model: new Product({id:id}) });
        console.log('creating new');
    }

});

app = new AppRouter();
Backbone.history.start({
    pushState: true,
    root: '/'
});

View

ModalView = Backbone.View.extend({
    el: $('#modal'),

    template: _.template( $('#tpl_modal').html() ),

    events: {
        'click .more_photo': 'showModal',
    },

    initialize: function() {
        // Update Model with Full details
        var self = this;
        this.model.fetch({
            data: {post_id: self.model.get('id')},
            processData: true,
            success: function() {
                self.render();
        });
    },

    render: function() {
        $(this.el).show().append( this.template( this.model.toJSON( this.model ) ) );
    },

    closeModal: function() {
        // Restore scrollbars
        $(this.el).css('overflow-y', 'auto');
        $('body').removeClass('noscroll');

        // Close modal and remove contents
        $(this.el).fadeOut();
        $(this.el).empty();
    },

    showModal: function() {
        // Update URL & Trigger Router function `showModal`
        app.navigate('/product/' + this.model.get('id'), {trigger:true});
    }
});

Console.log Output

creating new
               <----clicks on another photo
closing
creating new
  • 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-10T23:43:30+00:00Added an answer on June 10, 2026 at 11:43 pm

    Based on the code you provided I’m not sure why your closeModal method might be firing twice, I’ve created a simplified version off of your code and the method was only called once each time (of course I improvised a bit so maybe that had something to do with it).

    As an alternative to closing your and reopening your modal view each time you might want to try just swapping the model.

    For example

     showModal: function(id) {
    
            if(app.modalView) {
                app.modalView.model = new Product({id:id});
                app.modalView.model.fetch();
            } else {
               app.modalView = new ModalView({ model: new Product({id:id}) });
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following is the Script i am working that will indicate the Feature Detection for
I am working on an application, using java, that has the following features: User
I'm currently working on incorporating an authorization feature for Twitter following the approach described
I am working with the following piece; def index @user = User.find(params[:id]) rescue flash[:notice]
I implemented a feature that lets users set default profile photos and photo-album cover
Well guys, I'm trying to get that MongoDB feature working for hours: http://www.mongodb.org/display/DOCS/Http+Interface I
I'm working on a large Symfony2 app that has the following bundles (all under
I'm working on a new app and would love to have the following feature.
I conjured up the following code while working on some Vim emulation feature: If
In the following (working) code example, the templated register_enum() function is used to iterate

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.