From 1416bc747596198df3831a6b12da3e1e4857324d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 5 Mar 2013 14:52:35 -0500 Subject: [PATCH] Some javascript refactoring: Move markdown functions into their own classs, remove extraneous `window.` calls. --- .../javascripts/admin/models/admin_user.js | 8 +++---- .../discourse/components/transition_helper.js | 2 +- .../discourse/models/category_list.js | 4 ++-- .../discourse/models/input_validation.js | 2 +- .../javascripts/discourse/models/post.js | 2 +- .../javascripts/discourse/models/topic.js | 2 +- .../discourse/models/user_action.js | 2 +- .../discourse/views/application_view.js | 2 +- .../discourse/views/featured_topics_view.js | 2 +- .../views/list/list_categories_view.js | 2 +- .../modal/archetype_options_modal_view.js | 2 +- .../discourse/views/search/search_view.js | 2 +- .../discourse/views/topic_admin_menu_view.js | 2 +- .../javascripts/discourse/views/topic_view.js | 6 ++--- .../views/user/preferences_email_view.js | 2 +- .../javascripts/discourse/views/view.js | 2 +- app/assets/javascripts/env.js | 22 ++++++++----------- .../common/_discourse_javascript.html.erb | 2 +- 18 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index 2886f927827..c26a93a904c 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -1,13 +1,13 @@ /** Our data model for dealing with users from the admin section. - @class AdminUser + @class AdminUser @extends Discourse.Model @namespace Discourse @module Discourse -**/ +**/ Discourse.AdminUser = Discourse.Model.extend({ - + deleteAllPosts: function() { this.set('can_delete_all_posts', false); jQuery.ajax("/admin/users/" + (this.get('id')) + "/delete_all_posts", {type: 'PUT'}); @@ -137,7 +137,7 @@ Discourse.AdminUser = Discourse.Model.extend({ }); -window.Discourse.AdminUser.reopenClass({ +Discourse.AdminUser.reopenClass({ bulkApprove: function(users) { users.each(function(user) { diff --git a/app/assets/javascripts/discourse/components/transition_helper.js b/app/assets/javascripts/discourse/components/transition_helper.js index 67398b6e1c2..262bc887ea9 100644 --- a/app/assets/javascripts/discourse/components/transition_helper.js +++ b/app/assets/javascripts/discourse/components/transition_helper.js @@ -34,7 +34,7 @@ _getTransitionEndEventName = function() { }; transitionEnd = _getTransitionEndEventName(); -window.Discourse.TransitionHelper = { +Discourse.TransitionHelper = { after: function(element, callback) { return $(element).on(transitionEnd, callback); } diff --git a/app/assets/javascripts/discourse/models/category_list.js b/app/assets/javascripts/discourse/models/category_list.js index 3674351ef8a..9ea53c9dc5d 100644 --- a/app/assets/javascripts/discourse/models/category_list.js +++ b/app/assets/javascripts/discourse/models/category_list.js @@ -6,9 +6,9 @@ @namespace Discourse @module Discourse **/ -window.Discourse.CategoryList = Discourse.Model.extend({}); +Discourse.CategoryList = Discourse.Model.extend({}); -window.Discourse.CategoryList.reopenClass({ +Discourse.CategoryList.reopenClass({ categoriesFrom: function(result) { var categories, users; diff --git a/app/assets/javascripts/discourse/models/input_validation.js b/app/assets/javascripts/discourse/models/input_validation.js index 6150002a6d1..28ed8a6ae3b 100644 --- a/app/assets/javascripts/discourse/models/input_validation.js +++ b/app/assets/javascripts/discourse/models/input_validation.js @@ -6,6 +6,6 @@ @namespace Discourse @module Discourse **/ -window.Discourse.InputValidation = Discourse.Model.extend({}); +Discourse.InputValidation = Discourse.Model.extend({}); diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index bab33aac6ed..dbed9bac192 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -260,7 +260,7 @@ Discourse.Post = Discourse.Model.extend({ }).property('reply_count') }); -window.Discourse.Post.reopenClass({ +Discourse.Post.reopenClass({ createActionSummary: function(result) { var lookup; diff --git a/app/assets/javascripts/discourse/models/topic.js b/app/assets/javascripts/discourse/models/topic.js index a62a56faa65..eb9f7e26670 100644 --- a/app/assets/javascripts/discourse/models/topic.js +++ b/app/assets/javascripts/discourse/models/topic.js @@ -343,7 +343,7 @@ Discourse.Topic = Discourse.Model.extend({ } }); -window.Discourse.Topic.reopenClass({ +Discourse.Topic.reopenClass({ NotificationLevel: { WATCHING: 3, TRACKING: 2, diff --git a/app/assets/javascripts/discourse/models/user_action.js b/app/assets/javascripts/discourse/models/user_action.js index 57d6d1595fe..1a53422935e 100644 --- a/app/assets/javascripts/discourse/models/user_action.js +++ b/app/assets/javascripts/discourse/models/user_action.js @@ -138,7 +138,7 @@ Discourse.UserAction.reopenClass({ GOT_PRIVATE_MESSAGE: 13 }); -window.Discourse.UserAction.reopenClass({ +Discourse.UserAction.reopenClass({ statGroups: (function() { var g; g = {}; diff --git a/app/assets/javascripts/discourse/views/application_view.js b/app/assets/javascripts/discourse/views/application_view.js index af98cb71892..6b18deb0eab 100644 --- a/app/assets/javascripts/discourse/views/application_view.js +++ b/app/assets/javascripts/discourse/views/application_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.ApplicationView = Discourse.View.extend({ +Discourse.ApplicationView = Discourse.View.extend({ templateName: 'application' }); diff --git a/app/assets/javascripts/discourse/views/featured_topics_view.js b/app/assets/javascripts/discourse/views/featured_topics_view.js index 6f4fa644ec1..4db934486a3 100644 --- a/app/assets/javascripts/discourse/views/featured_topics_view.js +++ b/app/assets/javascripts/discourse/views/featured_topics_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.FeaturedTopicsView = Discourse.View.extend({ +Discourse.FeaturedTopicsView = Discourse.View.extend({ templateName: 'featured_topics', classNames: ['category-list-item'] }); diff --git a/app/assets/javascripts/discourse/views/list/list_categories_view.js b/app/assets/javascripts/discourse/views/list/list_categories_view.js index e1ccd02d9bb..c4a5d537d06 100644 --- a/app/assets/javascripts/discourse/views/list/list_categories_view.js +++ b/app/assets/javascripts/discourse/views/list/list_categories_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.ListCategoriesView = Discourse.View.extend({ +Discourse.ListCategoriesView = Discourse.View.extend({ templateName: 'list/categories', diff --git a/app/assets/javascripts/discourse/views/modal/archetype_options_modal_view.js b/app/assets/javascripts/discourse/views/modal/archetype_options_modal_view.js index 9cbfa02127e..b102a156fc1 100644 --- a/app/assets/javascripts/discourse/views/modal/archetype_options_modal_view.js +++ b/app/assets/javascripts/discourse/views/modal/archetype_options_modal_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.ArchetypeOptionsModalView = window.Discourse.ModalBodyView.extend({ +Discourse.ArchetypeOptionsModalView = Discourse.ModalBodyView.extend({ templateName: 'modal/archetype_options', title: Em.String.i18n('topic.options') }); diff --git a/app/assets/javascripts/discourse/views/search/search_view.js b/app/assets/javascripts/discourse/views/search/search_view.js index 21ad26bf212..33a3139c304 100644 --- a/app/assets/javascripts/discourse/views/search/search_view.js +++ b/app/assets/javascripts/discourse/views/search/search_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.SearchView = Discourse.View.extend({ +Discourse.SearchView = Discourse.View.extend({ tagName: 'div', classNames: ['d-dropdown'], elementId: 'search-dropdown', diff --git a/app/assets/javascripts/discourse/views/topic_admin_menu_view.js b/app/assets/javascripts/discourse/views/topic_admin_menu_view.js index f4bb74e0904..ebe64b0483a 100644 --- a/app/assets/javascripts/discourse/views/topic_admin_menu_view.js +++ b/app/assets/javascripts/discourse/views/topic_admin_menu_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.TopicAdminMenuView = Discourse.View.extend({ +Discourse.TopicAdminMenuView = Discourse.View.extend({ willDestroyElement: function() { $('html').off('mouseup.discourse-topic-admin-menu'); diff --git a/app/assets/javascripts/discourse/views/topic_view.js b/app/assets/javascripts/discourse/views/topic_view.js index 25007f4662d..d0c7a6230a2 100644 --- a/app/assets/javascripts/discourse/views/topic_view.js +++ b/app/assets/javascripts/discourse/views/topic_view.js @@ -489,7 +489,7 @@ Discourse.TopicView = Discourse.View.extend(Discourse.Scrolling, { } }); -window.Discourse.TopicView.reopenClass({ +Discourse.TopicView.reopenClass({ // Scroll to a given post, if in the DOM. Returns whether it was in the DOM or not. scrollTo: function(topicId, postNumber, callback) { @@ -504,11 +504,11 @@ window.Discourse.TopicView.reopenClass({ header = $('header'); title = $('#topic-title'); expectedOffset = title.height() - header.find('.contents').height(); - + if (expectedOffset < 0) { expectedOffset = 0; } - + $('html, body').scrollTop(existing.offset().top - (header.outerHeight(true) + expectedOffset)); } return true; diff --git a/app/assets/javascripts/discourse/views/user/preferences_email_view.js b/app/assets/javascripts/discourse/views/user/preferences_email_view.js index 8f90c3a4551..63031a769ea 100644 --- a/app/assets/javascripts/discourse/views/user/preferences_email_view.js +++ b/app/assets/javascripts/discourse/views/user/preferences_email_view.js @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -window.Discourse.PreferencesEmailView = Discourse.View.extend({ +Discourse.PreferencesEmailView = Discourse.View.extend({ templateName: 'user/email', classNames: ['user-preferences'], didInsertElement: function() { diff --git a/app/assets/javascripts/discourse/views/view.js b/app/assets/javascripts/discourse/views/view.js index 69bf24b1ee1..682e875f810 100644 --- a/app/assets/javascripts/discourse/views/view.js +++ b/app/assets/javascripts/discourse/views/view.js @@ -7,4 +7,4 @@ @namespace Discourse @module Discourse **/ - window.Discourse.View = Ember.View.extend(Discourse.Presence, {}); + Discourse.View = Ember.View.extend(Discourse.Presence, {}); diff --git a/app/assets/javascripts/env.js b/app/assets/javascripts/env.js index 6e4ded766f7..98996e8c05a 100644 --- a/app/assets/javascripts/env.js +++ b/app/assets/javascripts/env.js @@ -1,16 +1,12 @@ -/* These will help us migrate up to the new ember's default behavior -*/ - - - window.ENV = { - CP_DEFAULT_CACHEABLE: true, - VIEW_PRESERVES_CONTEXT: true, - MANDATORY_SETTER: false - }; - - window.Discourse = {}; - - window.Discourse.SiteSettings = {}; +// These will help us migrate up to the new ember's default behavior +window.ENV = { + CP_DEFAULT_CACHEABLE: true, + VIEW_PRESERVES_CONTEXT: true, + MANDATORY_SETTER: false +}; + +window.Discourse = {}; +Discourse.SiteSettings = {}; diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index 87670cece30..0ecaa8f1d6b 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -36,7 +36,7 @@ Discourse.CDN = '<%= Rails.configuration.action_controller.asset_host %>'; Discourse.BaseUrl = '<%= RailsMultisite::ConnectionManagement.current_hostname %>'; Discourse.Environment = '<%= Rails.env %>'; - window.Discourse.Router.map(function() { + Discourse.Router.map(function() { return Discourse.routeBuilder.call(this); }); Discourse.start()