From fca4a79f80122de72b0056f02a7bb345fe9c015c Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Wed, 10 Aug 2016 23:24:01 +0200 Subject: [PATCH 1/3] Remove inline javascript on notifications page --- app/assets/javascripts/app/router.js | 8 +++++++- app/views/notifications/index.html.haml | 5 ----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 73b8d2ba2..335fcb29d 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -30,7 +30,7 @@ app.Router = Backbone.Router.extend({ "people/:id/photos": "photos", "people/:id/contacts": "profile", "people": "pageWithAspectMembershipDropdowns", - "notifications": "pageWithAspectMembershipDropdowns", + "notifications": "notifications", "people/:id": "profile", "u/:name": "profile" @@ -83,6 +83,12 @@ app.Router = Backbone.Router.extend({ app.conversations = new app.views.Conversations(); }, + notifications: function() { + this._loadContacts(); + this.renderAspectMembershipDropdowns($(document)); + new app.views.Notifications({el: "#notifications_container"}); + }, + registration: function() { app.page = new app.pages.Registration(); }, diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 4e178dcc6..fde543ffc 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -74,8 +74,3 @@ .no-notifications.well %h4 = t(".no_notifications") - -:javascript - $(document).ready(function(){ - new app.views.Notifications({ el: '#notifications_container' }); - }); From 9c46e69b7a6042130f22d504d45ed0531cd2b4de Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 11 Aug 2016 00:03:51 +0200 Subject: [PATCH 2/3] Fix codestyle in router.js --- app/assets/javascripts/app/router.js | 53 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 335fcb29d..35af4dc0d 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -14,10 +14,8 @@ app.Router = Backbone.Router.extend({ "profile/edit": "settings", "admins/dashboard": "adminDashboard", "admin/pods": "adminPods", - "posts/:id": "singlePost", "p/:id": "singlePost", - "activity": "stream", "stream": "stream", "aspects": "aspects", @@ -31,7 +29,6 @@ app.Router = Backbone.Router.extend({ "people/:id/contacts": "profile", "people": "pageWithAspectMembershipDropdowns", "notifications": "notifications", - "people/:id": "profile", "u/:name": "profile" }, @@ -67,7 +64,7 @@ app.Router = Backbone.Router.extend({ var stream = new app.views.ContactStream({ collection: app.contacts, - el: $(".stream.contacts #contact_stream"), + el: $(".stream.contacts #contact_stream") }); app.page = new app.pages.Contacts({stream: stream}); @@ -97,8 +94,8 @@ app.Router = Backbone.Router.extend({ app.page = new app.pages.Settings(); }, - singlePost : function(id) { - this.renderPage(function(){ return new app.pages.SinglePostViewer({ id: id })}); + singlePost: function(id) { + this.renderPage(function() { return new app.pages.SinglePostViewer({id: id}); }); }, spotlight: function() { @@ -107,28 +104,32 @@ app.Router = Backbone.Router.extend({ }); }, - renderPage : function(pageConstructor){ - app.page && app.page.unbind && app.page.unbind(); //old page might mutate global events $(document).keypress, so unbind before creating - app.page = pageConstructor(); //create new page after the world is clean (like that will ever happen) + renderPage: function(pageConstructor) { + // old page might mutate global events $(document).keypress, so unbind before creating + app.page && app.page.unbind && app.page.unbind(); + // create new page after the world is clean (like that will ever happen) + app.page = pageConstructor(); app.page.render(); - if( !$.contains(document, app.page.el) ) { + if (!$.contains(document, app.page.el)) { // view element isn"t already attached to the DOM, insert it $("#container").empty().append(app.page.el); } }, - stream : function() { + stream: function() { app.stream = new app.models.Stream(); app.stream.fetch(); this._initializeStreamView(); }, - photos : function(guid) { + photos: function(guid) { this._loadContacts(); this.renderPage(function() { return new app.pages.Profile({ + /* eslint-disable camelcase */ person_id: guid, + /* eslint-enable camelcase */ el: $("body > #profile_container"), streamCollection: app.collections.Photos, streamView: app.views.Photos @@ -136,7 +137,9 @@ app.Router = Backbone.Router.extend({ }); }, - followed_tags : function(name) { + /* eslint-disable camelcase */ + followed_tags: function(name) { + /* eslint-enable camelcase */ this.stream(); app.tagFollowings = new app.collections.TagFollowings(); @@ -146,7 +149,7 @@ app.Router = Backbone.Router.extend({ app.tagFollowings.reset(gon.preloads.tagFollowings); - if(name) { + if (name) { var followedTagsAction = new app.views.TagFollowingAction( {tagText: decodeURIComponent(name).toLowerCase()} ); @@ -161,12 +164,18 @@ app.Router = Backbone.Router.extend({ new app.collections.AspectSelections(app.currentUser.get("aspects")); this.aspectsList = this.aspectsList || new app.views.AspectsList({collection: app.aspectSelections}); this.aspectsList.render(); + /* eslint-disable camelcase */ this.aspects_stream(); + /* eslint-enable camelcase */ }, - aspects_stream : function(){ + /* eslint-disable camelcase */ + aspects_stream: function() { + /* eslint-enable camelcase */ var ids = app.aspectSelections.selectedGetAttribute("id"); - app.stream = new app.models.StreamAspects([], { aspects_ids: ids }); + /* eslint-disable camelcase */ + app.stream = new app.models.StreamAspects([], {aspects_ids: ids}); + /* eslint-enable camelcase */ app.stream.fetch(); this._initializeStreamView(); app.publisher.setSelectedAspects(ids); @@ -206,25 +215,25 @@ app.Router = Backbone.Router.extend({ }, _hideInactiveStreamLists: function() { - if(this.aspectsList && Backbone.history.fragment !== "aspects") { + if (this.aspectsList && Backbone.history.fragment !== "aspects") { this.aspectsList.hideAspectsList(); } - if(this.followedTagsView && Backbone.history.fragment !== "followed_tags") { + if (this.followedTagsView && Backbone.history.fragment !== "followed_tags") { this.followedTagsView.hideFollowedTags(); } }, _initializeStreamView: function() { - if(app.page) { + if (app.page) { app.page.unbindInfScroll(); app.page.remove(); } - app.page = new app.views.Stream({model : app.stream}); + app.page = new app.views.Stream({model: app.stream}); 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}); + if ($("#publisher").length !== 0) { + app.publisher = app.publisher || new app.views.Publisher({collection: app.stream.items}); } $("#main_stream").html(app.page.render().el); From 9b4ff768ca987db680f0bcab3d8b7eeed8d648e5 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Thu, 11 Aug 2016 00:15:50 +0200 Subject: [PATCH 3/3] Sort router.js --- app/assets/javascripts/app/router.js | 278 +++++++++++++-------------- 1 file changed, 139 insertions(+), 139 deletions(-) diff --git a/app/assets/javascripts/app/router.js b/app/assets/javascripts/app/router.js index 35af4dc0d..6c27e8b5c 100644 --- a/app/assets/javascripts/app/router.js +++ b/app/assets/javascripts/app/router.js @@ -2,35 +2,35 @@ app.Router = Backbone.Router.extend({ routes: { - "help/:section": "help", - "help/": "help", - "help": "help", - "getting_started": "gettingStarted", - "contacts": "contacts", - "community_spotlight": "spotlight", - "conversations": "conversations", - "user/edit": "settings", - "users/sign_up": "registration", - "profile/edit": "settings", - "admins/dashboard": "adminDashboard", - "admin/pods": "adminPods", - "posts/:id": "singlePost", - "p/:id": "singlePost", "activity": "stream", - "stream": "stream", + "admin/pods": "adminPods", + "admins/dashboard": "adminDashboard", "aspects": "aspects", "commented": "stream", + "community_spotlight": "spotlight", + "contacts": "contacts", + "conversations": "conversations", + "followed_tags": "followed_tags", + "getting_started": "gettingStarted", + "help": "help", + "help/": "help", + "help/:section": "help", "liked": "stream", "mentions": "stream", - "public": "stream", - "followed_tags": "followed_tags", - "tags/:name": "followed_tags", - "people/:id/photos": "photos", - "people/:id/contacts": "profile", - "people": "pageWithAspectMembershipDropdowns", "notifications": "notifications", + "p/:id": "singlePost", + "people": "pageWithAspectMembershipDropdowns", "people/:id": "profile", - "u/:name": "profile" + "people/:id/contacts": "profile", + "people/:id/photos": "photos", + "posts/:id": "singlePost", + "profile/edit": "settings", + "public": "stream", + "stream": "stream", + "tags/:name": "followed_tags", + "u/:name": "profile", + "user/edit": "settings", + "users/sign_up": "registration" }, initialize: function() { @@ -40,12 +40,6 @@ app.Router = Backbone.Router.extend({ this.route(/^bookmarklet(?:\?(.*))?/, "bookmarklet"); }, - help: function(section) { - app.help = new app.views.Help(); - $("#help").prepend(app.help.el); - app.help.render(section); - }, - adminDashboard: function() { app.page = new app.pages.AdminDashboard(); }, @@ -58,107 +52,6 @@ app.Router = Backbone.Router.extend({ }); }, - contacts: function() { - app.aspect = new app.models.Aspect(gon.preloads.aspect); - this._loadContacts(); - - var stream = new app.views.ContactStream({ - collection: app.contacts, - el: $(".stream.contacts #contact_stream") - }); - - app.page = new app.pages.Contacts({stream: stream}); - }, - - gettingStarted: function() { - this.renderPage(function() { - return new app.pages.GettingStarted({inviter: new app.models.Person(app.parsePreload("inviter"))}); - }); - }, - - conversations: function() { - app.conversations = new app.views.Conversations(); - }, - - notifications: function() { - this._loadContacts(); - this.renderAspectMembershipDropdowns($(document)); - new app.views.Notifications({el: "#notifications_container"}); - }, - - registration: function() { - app.page = new app.pages.Registration(); - }, - - settings: function() { - app.page = new app.pages.Settings(); - }, - - singlePost: function(id) { - this.renderPage(function() { return new app.pages.SinglePostViewer({id: id}); }); - }, - - spotlight: function() { - $("#invitations-button").click(function() { - app.helpers.showModal("#invitationsModal"); - }); - }, - - renderPage: function(pageConstructor) { - // old page might mutate global events $(document).keypress, so unbind before creating - app.page && app.page.unbind && app.page.unbind(); - // create new page after the world is clean (like that will ever happen) - app.page = pageConstructor(); - app.page.render(); - - if (!$.contains(document, app.page.el)) { - // view element isn"t already attached to the DOM, insert it - $("#container").empty().append(app.page.el); - } - }, - - stream: function() { - app.stream = new app.models.Stream(); - app.stream.fetch(); - this._initializeStreamView(); - }, - - photos: function(guid) { - this._loadContacts(); - this.renderPage(function() { - return new app.pages.Profile({ - /* eslint-disable camelcase */ - person_id: guid, - /* eslint-enable camelcase */ - el: $("body > #profile_container"), - streamCollection: app.collections.Photos, - streamView: app.views.Photos - }); - }); - }, - - /* eslint-disable camelcase */ - followed_tags: function(name) { - /* eslint-enable camelcase */ - this.stream(); - - app.tagFollowings = new app.collections.TagFollowings(); - this.followedTagsView = new app.views.TagFollowingList({collection: app.tagFollowings}); - $("#tags_list").replaceWith(this.followedTagsView.render().el); - this.followedTagsView.setupAutoSuggest(); - - app.tagFollowings.reset(gon.preloads.tagFollowings); - - if (name) { - var followedTagsAction = new app.views.TagFollowingAction( - {tagText: decodeURIComponent(name).toLowerCase()} - ); - $("#author_info").prepend(followedTagsAction.render().el); - app.tags = new app.views.Tags({hashtagName: name}); - } - this._hideInactiveStreamLists(); - }, - aspects: function() { app.aspectSelections = app.aspectSelections || new app.collections.AspectSelections(app.currentUser.get("aspects")); @@ -188,6 +81,76 @@ app.Router = Backbone.Router.extend({ ).render(); }, + contacts: function() { + app.aspect = new app.models.Aspect(gon.preloads.aspect); + this._loadContacts(); + + var stream = new app.views.ContactStream({ + collection: app.contacts, + el: $(".stream.contacts #contact_stream") + }); + + app.page = new app.pages.Contacts({stream: stream}); + }, + + conversations: function() { + app.conversations = new app.views.Conversations(); + }, + + /* eslint-disable camelcase */ + followed_tags: function(name) { + /* eslint-enable camelcase */ + this.stream(); + + app.tagFollowings = new app.collections.TagFollowings(); + this.followedTagsView = new app.views.TagFollowingList({collection: app.tagFollowings}); + $("#tags_list").replaceWith(this.followedTagsView.render().el); + this.followedTagsView.setupAutoSuggest(); + + app.tagFollowings.reset(gon.preloads.tagFollowings); + + if (name) { + var followedTagsAction = new app.views.TagFollowingAction( + {tagText: decodeURIComponent(name).toLowerCase()} + ); + $("#author_info").prepend(followedTagsAction.render().el); + app.tags = new app.views.Tags({hashtagName: name}); + } + this._hideInactiveStreamLists(); + }, + + gettingStarted: function() { + this.renderPage(function() { + return new app.pages.GettingStarted({inviter: new app.models.Person(app.parsePreload("inviter"))}); + }); + }, + + help: function(section) { + app.help = new app.views.Help(); + $("#help").prepend(app.help.el); + app.help.render(section); + }, + + notifications: function() { + this._loadContacts(); + this.renderAspectMembershipDropdowns($(document)); + new app.views.Notifications({el: "#notifications_container"}); + }, + + photos: function(guid) { + this._loadContacts(); + this.renderPage(function() { + return new app.pages.Profile({ + /* eslint-disable camelcase */ + person_id: guid, + /* eslint-enable camelcase */ + el: $("body > #profile_container"), + streamCollection: app.collections.Photos, + streamView: app.views.Photos + }); + }); + }, + profile: function() { this._loadContacts(); this.renderPage(function() { @@ -197,23 +160,30 @@ app.Router = Backbone.Router.extend({ }); }, - pageWithAspectMembershipDropdowns: function() { - this._loadContacts(); - this.renderAspectMembershipDropdowns($(document)); + registration: function() { + app.page = new app.pages.Registration(); }, - _loadContacts: function() { - app.contacts = new app.collections.Contacts(app.parsePreload("contacts")); + settings: function() { + app.page = new app.pages.Settings(); }, - renderAspectMembershipDropdowns: function($context) { - $context.find(".aspect_membership_dropdown.placeholder").each(function() { - var personId = $(this).data("personId"); - var view = new app.views.AspectMembership({person: app.contacts.findWhere({"person_id": personId}).person}); - $(this).html(view.render().$el); + singlePost: function(id) { + this.renderPage(function() { return new app.pages.SinglePostViewer({id: id}); }); + }, + + spotlight: function() { + $("#invitations-button").click(function() { + app.helpers.showModal("#invitationsModal"); }); }, + stream: function() { + app.stream = new app.models.Stream(); + app.stream.fetch(); + this._initializeStreamView(); + }, + _hideInactiveStreamLists: function() { if (this.aspectsList && Backbone.history.fragment !== "aspects") { this.aspectsList.hideAspectsList(); @@ -238,6 +208,36 @@ app.Router = Backbone.Router.extend({ $("#main_stream").html(app.page.render().el); this._hideInactiveStreamLists(); + }, + + _loadContacts: function() { + app.contacts = new app.collections.Contacts(app.parsePreload("contacts")); + }, + + pageWithAspectMembershipDropdowns: function() { + this._loadContacts(); + this.renderAspectMembershipDropdowns($(document)); + }, + + renderAspectMembershipDropdowns: function($context) { + $context.find(".aspect_membership_dropdown.placeholder").each(function() { + var personId = $(this).data("personId"); + var view = new app.views.AspectMembership({person: app.contacts.findWhere({"person_id": personId}).person}); + $(this).html(view.render().$el); + }); + }, + + renderPage: function(pageConstructor) { + // old page might mutate global events $(document).keypress, so unbind before creating + app.page && app.page.unbind && app.page.unbind(); + // create new page after the world is clean (like that will ever happen) + app.page = pageConstructor(); + app.page.render(); + + if (!$.contains(document, app.page.el)) { + // view element isn"t already attached to the DOM, insert it + $("#container").empty().append(app.page.el); + } } }); // @license-end