Do not instanciate publisher if not publisher element is present

This commit is contained in:
Augier 2016-02-16 12:49:56 +01:00 committed by Steffen van Bergerem
parent b1d60d7c9a
commit 8f021be20b
3 changed files with 14 additions and 2 deletions

View file

@ -180,8 +180,10 @@ app.Router = Backbone.Router.extend({
}
app.page = new app.views.Stream({model : app.stream});
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
app.shortcuts = app.shortcuts || new app.views.StreamShortcuts({el: $(document)});
if($("#publisher").length !== 0){
app.publisher = app.publisher || new app.views.Publisher({collection : app.stream.items});
}
$("#main_stream").html(app.page.render().el);
this._hideInactiveStreamLists();

View file

@ -2,7 +2,9 @@
app.views.Tags = Backbone.View.extend({
initialize: function(opts) {
app.publisher.setText("#"+ opts.hashtagName + " ");
if(app.publisher){
app.publisher.setText("#"+ opts.hashtagName + " ");
}
}
});
// @license-end

View file

@ -2,6 +2,7 @@ describe('app.Router', function () {
describe('followed_tags', function() {
beforeEach(function() {
factory.preloads({tagFollowings: []});
spec.loadFixture("aspects_index");
});
it('decodes name before passing it into TagFollowingAction', function () {
@ -92,6 +93,7 @@ describe('app.Router', function () {
delete app.page;
delete app.publisher;
delete app.shortcuts;
spec.loadFixture("aspects_index");
});
it("sets app.page", function() {
@ -112,6 +114,12 @@ describe('app.Router', function () {
expect(app.publisher.jasmineTestValue).toEqual(42);
});
it("doesn't set app.publisher if there is no publisher element in page", function(){
$("#publisher").remove();
app.router._initializeStreamView();
expect(app.publisher).toBeUndefined();
});
it("sets app.shortcuts", function() {
expect(app.shortcuts).toBeUndefined();
app.router._initializeStreamView();