Refactor and reorder backbone app initialization, fixes hovercards
Also added cucumber feature for hovercards
This commit is contained in:
parent
7057f77924
commit
5026eccc6a
3 changed files with 66 additions and 20 deletions
|
|
@ -20,7 +20,7 @@ var app = {
|
||||||
views: {},
|
views: {},
|
||||||
pages: {},
|
pages: {},
|
||||||
forms: {},
|
forms: {},
|
||||||
|
|
||||||
user: function(userAttrs) {
|
user: function(userAttrs) {
|
||||||
if(userAttrs) { return this._user = new app.models.User(userAttrs) }
|
if(userAttrs) { return this._user = new app.models.User(userAttrs) }
|
||||||
return this._user || false
|
return this._user || false
|
||||||
|
|
@ -34,24 +34,12 @@ var app = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
app.router = new app.Router();
|
app.router = new app.Router();
|
||||||
|
|
||||||
if (window.gon == undefined) {
|
this.setupDummyPreloads();
|
||||||
window.gon = {preloads:{}};
|
|
||||||
}
|
|
||||||
|
|
||||||
app.currentUser = app.user(window.gon.user) || new app.models.User();
|
|
||||||
|
|
||||||
this.setupFacebox();
|
this.setupFacebox();
|
||||||
this.setupHovercards();
|
this.setupUser();
|
||||||
|
this.setupHeader();
|
||||||
if(app.currentUser.authenticated()) {
|
this.setupBackboneLinks();
|
||||||
app.header = new app.views.Header();
|
this.setupGlobalViews();
|
||||||
$("header").prepend(app.header.el);
|
|
||||||
app.header.render();
|
|
||||||
}
|
|
||||||
|
|
||||||
Backbone.history.start({pushState: true});
|
|
||||||
|
|
||||||
app.aspectMemberships = new app.views.AspectMembership();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hasPreload : function(prop) {
|
hasPreload : function(prop) {
|
||||||
|
|
@ -63,7 +51,7 @@ var app = {
|
||||||
window.gon.preloads[prop] = val
|
window.gon.preloads[prop] = val
|
||||||
},
|
},
|
||||||
|
|
||||||
parsePreload : function(prop){
|
parsePreload : function(prop) {
|
||||||
if(!app.hasPreload(prop)) { return }
|
if(!app.hasPreload(prop)) { return }
|
||||||
|
|
||||||
var preload = window.gon.preloads[prop]
|
var preload = window.gon.preloads[prop]
|
||||||
|
|
@ -72,13 +60,33 @@ var app = {
|
||||||
return(preload)
|
return(preload)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setupDummyPreloads: function() {
|
||||||
|
if (window.gon == undefined) {
|
||||||
|
window.gon = {preloads:{}};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setupUser: function() {
|
||||||
|
app.currentUser = app.user(window.gon.user) || new app.models.User();
|
||||||
|
},
|
||||||
|
|
||||||
|
setupHeader: function() {
|
||||||
|
if(app.currentUser.authenticated()) {
|
||||||
|
app.header = new app.views.Header();
|
||||||
|
$("header").prepend(app.header.el);
|
||||||
|
app.header.render();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
setupFacebox: function() {
|
setupFacebox: function() {
|
||||||
$.facebox.settings.closeImage = app.baseImageUrl()+'facebox/closelabel.png';
|
$.facebox.settings.closeImage = app.baseImageUrl()+'facebox/closelabel.png';
|
||||||
$.facebox.settings.loadingImage = app.baseImageUrl()+'facebox/loading.gif';
|
$.facebox.settings.loadingImage = app.baseImageUrl()+'facebox/loading.gif';
|
||||||
$.facebox.settings.opacity = 0.75;
|
$.facebox.settings.opacity = 0.75;
|
||||||
},
|
},
|
||||||
|
|
||||||
setupHovercards: function() {
|
setupBackboneLinks: function() {
|
||||||
|
Backbone.history.start({pushState: true});
|
||||||
|
|
||||||
// there's probably a better way to do this...
|
// there's probably a better way to do this...
|
||||||
$("a[rel=backbone]").live("click", function(evt){
|
$("a[rel=backbone]").live("click", function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
@ -87,8 +95,11 @@ var app = {
|
||||||
$(".stream_title").text(link.text())
|
$(".stream_title").text(link.text())
|
||||||
app.router.navigate(link.attr("href").substring(1) ,true)
|
app.router.navigate(link.attr("href").substring(1) ,true)
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setupGlobalViews: function() {
|
||||||
app.hovercard = new app.views.Hovercard();
|
app.hovercard = new app.views.Hovercard();
|
||||||
|
app.aspectMemberships = new app.views.AspectMembership();
|
||||||
},
|
},
|
||||||
|
|
||||||
/* mixpanel wrapper function */
|
/* mixpanel wrapper function */
|
||||||
|
|
|
||||||
20
features/hovercards.feature
Normal file
20
features/hovercards.feature
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
@javascript
|
||||||
|
Feature: Hovercards
|
||||||
|
In order to not having to leave the page to view a persons profile
|
||||||
|
As a user
|
||||||
|
I want to use hovercards
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a user named "Bob Jones" with email "bob@bob.bob"
|
||||||
|
And "bob@bob.bob" has a public post with text "public stuff"
|
||||||
|
And a user named "Alice" with email "alice@alice.alice"
|
||||||
|
And I sign in as "alice@alice.alice"
|
||||||
|
|
||||||
|
|
||||||
|
Scenario: Hovercards on the main stream
|
||||||
|
Given I am on "bob@bob.bob"'s page
|
||||||
|
Then I should see "public stuff" within ".stream_element"
|
||||||
|
When I activate the first hovercard
|
||||||
|
Then I should see a hovercard
|
||||||
|
When I deactivate the first hovercard
|
||||||
|
Then I should not see a hovercard
|
||||||
15
features/step_definitions/hovercard_steps.rb
Normal file
15
features/step_definitions/hovercard_steps.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
When(/^I activate the first hovercard$/) do
|
||||||
|
page.execute_script("$('.hovercardable').first().trigger('mouseenter');")
|
||||||
|
end
|
||||||
|
|
||||||
|
Then(/^I should see a hovercard$/) do
|
||||||
|
page.should have_css '#hovercard'
|
||||||
|
end
|
||||||
|
|
||||||
|
When(/^I deactivate the first hovercard$/) do
|
||||||
|
page.execute_script("$('.hovercardable').first().trigger('mouseleave');")
|
||||||
|
end
|
||||||
|
|
||||||
|
Then(/^I should not see a hovercard$/) do
|
||||||
|
page.should_not have_css '#hovercard'
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue