diff --git a/public/javascripts/diaspora.js b/public/javascripts/diaspora.js index 6c4ff50fc..6c4c2333e 100644 --- a/public/javascripts/diaspora.js +++ b/public/javascripts/diaspora.js @@ -37,8 +37,6 @@ Diaspora.BaseWidget = { instantiate: function(Widget, element) { - if(typeof Diaspora.Widgets[Widget] === "undefined") { throw new Error("Widget " + Widget + " does not exist"); } - $.extend(Diaspora.Widgets[Widget].prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget)); var widget = new Diaspora.Widgets[Widget](), @@ -50,7 +48,6 @@ }, globalSubscribe: function(eventName, callback, context) { - if(typeof callback === "undefined") { throw new Error("Callback must be defined for event: " + eventName); } Diaspora.page.subscribe(eventName, callback, context); }, @@ -59,6 +56,18 @@ } }; + Diaspora.BasePage = function(body) { + $.extend(this, Diaspora.BaseWidget); + $.extend(this, { + backToTop: this.instantiate("BackToTop", body.find("#back-to-top")), + directionDetector: this.instantiate("DirectionDetector"), + flashMessages: this.instantiate("FlashMessages"), + header: this.instantiate("Header", body.find("header")), + hoverCard: this.instantiate("HoverCard", body.find("#hovercard")), + timeAgo: this.instantiate("TimeAgo", "abbr.timeago") + }); + }; + window.Diaspora = Diaspora; })(); @@ -66,12 +75,13 @@ $(function() { if (typeof Diaspora.Pages[Diaspora.Page] === "undefined") { Diaspora.page = Diaspora.EventBroker.extend(Diaspora.BaseWidget); - return; + } else { + var Page = Diaspora.Pages[Diaspora.Page]; + $.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget)); + + Diaspora.page = new Page(); } - var Page = Diaspora.Pages[Diaspora.Page]; - $.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget)); - - Diaspora.page = new Page(); + $.extend(Diaspora.page, new Diaspora.BasePage($(document.body))); Diaspora.page.publish("page/ready", [$(document.body)]) }); \ No newline at end of file diff --git a/public/javascripts/pages/admins-user_search.js b/public/javascripts/pages/admins-user_search.js deleted file mode 100644 index e28dfbcee..000000000 --- a/public/javascripts/pages/admins-user_search.js +++ /dev/null @@ -1,9 +0,0 @@ -Diaspora.Pages.AdminsUserSearch= function() { - var self = this; - - this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); - }); -}; diff --git a/public/javascripts/pages/aspects-index.js b/public/javascripts/pages/aspects-index.js index c39fc7ffa..898db0372 100644 --- a/public/javascripts/pages/aspects-index.js +++ b/public/javascripts/pages/aspects-index.js @@ -3,13 +3,6 @@ Diaspora.Pages.AspectsIndex = function() { this.subscribe("page/ready", function(evt, document) { self.stream = self.instantiate("Stream", document.find("#aspect_stream_container")); - self.header = self.instantiate("Header", document.find("header")); - - self.backToTop = self.instantiate("BackToTop", document.find("#back-to-top")); - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; \ No newline at end of file diff --git a/public/javascripts/pages/authorizations-index.js b/public/javascripts/pages/authorizations-index.js deleted file mode 100644 index 40bc158b6..000000000 --- a/public/javascripts/pages/authorizations-index.js +++ /dev/null @@ -1,9 +0,0 @@ -Diaspora.Pages.AuthorizationsIndex = function() { - var self = this; - - this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); - }); -}; diff --git a/public/javascripts/pages/contacts-index.js b/public/javascripts/pages/contacts-index.js index 3c422b79d..f374ea18e 100644 --- a/public/javascripts/pages/contacts-index.js +++ b/public/javascripts/pages/contacts-index.js @@ -2,12 +2,6 @@ Diaspora.Pages.ContactsIndex = function() { var self = this; this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; diff --git a/public/javascripts/pages/conversations-index.js b/public/javascripts/pages/conversations-index.js deleted file mode 100644 index fc36e1016..000000000 --- a/public/javascripts/pages/conversations-index.js +++ /dev/null @@ -1,8 +0,0 @@ -Diaspora.Pages.ConversationsIndex = function() { - var self = this; - - this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); - self.directionDetector = self.instantiate("DirectionDetector"); - }); -}; \ No newline at end of file diff --git a/public/javascripts/pages/notifications-index.js b/public/javascripts/pages/notifications-index.js index ab2017c84..ade507196 100644 --- a/public/javascripts/pages/notifications-index.js +++ b/public/javascripts/pages/notifications-index.js @@ -2,13 +2,6 @@ Diaspora.Pages.NotificationsIndex = function() { var self = this; this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; diff --git a/public/javascripts/pages/people-featured_users.js b/public/javascripts/pages/people-featured_users.js deleted file mode 100644 index 87db0d4e9..000000000 --- a/public/javascripts/pages/people-featured_users.js +++ /dev/null @@ -1,12 +0,0 @@ -Diaspora.Pages.PeopleFeaturedUsers = function() { - var self = this; - - this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); - }); -}; diff --git a/public/javascripts/pages/people-index.js b/public/javascripts/pages/people-index.js deleted file mode 100644 index 904344599..000000000 --- a/public/javascripts/pages/people-index.js +++ /dev/null @@ -1,7 +0,0 @@ -Diaspora.Pages.PeopleIndex = function() { - var self = this; - - this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); - }); -}; \ No newline at end of file diff --git a/public/javascripts/pages/people-show.js b/public/javascripts/pages/people-show.js index d6c4f1ee7..84c0173b8 100644 --- a/public/javascripts/pages/people-show.js +++ b/public/javascripts/pages/people-show.js @@ -2,13 +2,7 @@ Diaspora.Pages.PeopleShow = function() { var self = this; this.subscribe("page/ready", function(evt, document) { - self.header = self.instantiate("Header", document.find("header")); self.stream = self.instantiate("Stream", document.find("#main_stream")); - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; \ No newline at end of file diff --git a/public/javascripts/pages/posts-show.js b/public/javascripts/pages/posts-show.js index c707b3446..7ec693718 100644 --- a/public/javascripts/pages/posts-show.js +++ b/public/javascripts/pages/posts-show.js @@ -2,7 +2,6 @@ Diaspora.Pages.PostsShow = function() { var self = this; this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); self.stream = self.instantiate("Stream", body.find("#main_stream")); }); }; \ No newline at end of file diff --git a/public/javascripts/pages/profiles-edit.js b/public/javascripts/pages/profiles-edit.js deleted file mode 100644 index eec586df2..000000000 --- a/public/javascripts/pages/profiles-edit.js +++ /dev/null @@ -1,9 +0,0 @@ -Diaspora.Pages.ProfilesEdit = function() { - var self = this; - - this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); - -// self.peopleSearch = self.instantiate("Search", body.find("#update_profile_form")); - }); -}; \ No newline at end of file diff --git a/public/javascripts/pages/services-finder.js b/public/javascripts/pages/services-finder.js index dd41faf62..b9a9b547b 100644 --- a/public/javascripts/pages/services-finder.js +++ b/public/javascripts/pages/services-finder.js @@ -2,13 +2,6 @@ Diaspora.Pages.ServicesFinder = function() { var self = this; this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; diff --git a/public/javascripts/pages/services-index.js b/public/javascripts/pages/services-index.js deleted file mode 100644 index 41412797d..000000000 --- a/public/javascripts/pages/services-index.js +++ /dev/null @@ -1,9 +0,0 @@ -Diaspora.Pages.ServicesIndex= function() { - var self = this; - - this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); - }); -}; diff --git a/public/javascripts/pages/tags-show.js b/public/javascripts/pages/tags-show.js index e011058bb..293c8d76c 100644 --- a/public/javascripts/pages/tags-show.js +++ b/public/javascripts/pages/tags-show.js @@ -1,14 +1,7 @@ Diaspora.Pages.TagsShow = function() { var self = this; - this.subscribe("page/ready", function(evt, document) { - self.instantiate("Header", document.find("header")); - - - self.hoverCard = self.instantiate("HoverCard", document.find("#hovercard")); + this.subscribe("page/ready", function() { self.infiniteScroll = self.instantiate("InfiniteScroll"); - self.timeAgo = self.instantiate("TimeAgo", "abbr.timeago"); - self.directionDetector = self.instantiate("DirectionDetector"); - self.flashMessages = self.instantiate("FlashMessages"); }); }; diff --git a/public/javascripts/pages/users-edit.js b/public/javascripts/pages/users-edit.js deleted file mode 100644 index c013c2a51..000000000 --- a/public/javascripts/pages/users-edit.js +++ /dev/null @@ -1,7 +0,0 @@ -Diaspora.Pages.UsersEdit = function() { - var self = this; - - this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); - }); -}; \ No newline at end of file diff --git a/public/javascripts/pages/users-getting-started.js b/public/javascripts/pages/users-getting-started.js index 509ca2b6a..dc00a6b22 100644 --- a/public/javascripts/pages/users-getting-started.js +++ b/public/javascripts/pages/users-getting-started.js @@ -2,8 +2,6 @@ Diaspora.Pages.UsersGettingStarted = function() { var self = this; this.subscribe("page/ready", function(evt, body) { - self.header = self.instantiate("Header", body.find("header")); - self.peopleSearch = self.instantiate("Search", body.find("form.people.search_form")); self.tagSearch = self.instantiate("Search", body.find("form.tag.search_form")); }); diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 405fb551c..f864a4964 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -29,6 +29,7 @@ var View = { $(this.search.selector) .blur(this.search.blur) .focus(this.search.focus) + /* Submit the form when the user hits enter */ .keypress(this.search.keyPress);