Created
April 9, 2012 21:28
-
-
Save billsaysthis/2346669 to your computer and use it in GitHub Desktop.
Backbone with TB2 modal sample View class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZPCommon.Views.SocialSharesView = Backbone.View.extend({ | |
template: 'public/common/socialShares_hb', | |
id: 'socialShares', | |
className: 'buttonBox', | |
initialize: function() { | |
_.bindAll(this, 'emailShare'); | |
}, | |
events: { | |
'click #emailShareBtn': 'emailShare' | |
}, | |
emailShare: function(e) { | |
e.preventDefault(); | |
$('#emailShareModal').modal('show'); | |
} | |
}); |
Is that #emailShareModal triggering a route?
Shouldn't be, we have very few routes and none have a hash at the start. Also, I would have expected the preventDefault() to block that.
Bill, I figured it out. Hard to say what I was doing wrong but mainly because I'm still learning how Backbone fires and responds to events in Views. Thanks for chiming in.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It goes directly into twitter-bootstrap.js. The modal shows, but is immediately replaced with a full page load.
The link I have for the user is like this:
After clicking the browser URL shows as http://example-acme.localhost:9300/emailShareModal. This seems strange since the original href is #emailShareModal (that is, a relative path) and selecting copy URL from the browser context menu shows the link on the page has an href of:
http://example-acme.localhost:9300/campaigns/552/reviews/86459#emailShareModal
Note that I only know the modal loads and is briefly visible is from stepping through code with Firebug, otherwise the changes happen so fast the modal isn't seen.