diff --git a/app/assets/javascripts/admin/components/site-setting.js.es6 b/app/assets/javascripts/admin/components/site-setting.js.es6 index 7244c6fb5..f8e3cc6b2 100644 --- a/app/assets/javascripts/admin/components/site-setting.js.es6 +++ b/app/assets/javascripts/admin/components/site-setting.js.es6 @@ -1,9 +1,10 @@ import BufferedContent from 'discourse/mixins/buffered-content'; +import ScrollTop from 'discourse/mixins/scroll-top'; import SiteSetting from 'admin/models/site-setting'; const CustomTypes = ['bool', 'enum', 'list', 'url_list']; -export default Ember.Component.extend(BufferedContent, Discourse.ScrollTop, { +export default Ember.Component.extend(BufferedContent, ScrollTop, { classNameBindings: [':row', ':setting', 'setting.overridden', 'typeClass'], content: Ember.computed.alias('setting'), dirty: Discourse.computed.propertyNotEqual('buffered.value', 'setting.value'), diff --git a/app/assets/javascripts/admin/views/admin-badges-index.js.es6 b/app/assets/javascripts/admin/views/admin-badges-index.js.es6 index 2bd2497f1..f0b0ceb85 100644 --- a/app/assets/javascripts/admin/views/admin-badges-index.js.es6 +++ b/app/assets/javascripts/admin/views/admin-badges-index.js.es6 @@ -1 +1,3 @@ -export default Ember.View.extend(Discourse.ScrollTop); +import ScrollTop from 'discourse/mixins/scroll-top'; + +export default Ember.View.extend(ScrollTop); diff --git a/app/assets/javascripts/admin/views/admin-badges-show.js.es6 b/app/assets/javascripts/admin/views/admin-badges-show.js.es6 index b49d0fad6..55f7e0b64 100644 --- a/app/assets/javascripts/admin/views/admin-badges-show.js.es6 +++ b/app/assets/javascripts/admin/views/admin-badges-show.js.es6 @@ -1,4 +1,6 @@ -export default Ember.View.extend(Discourse.ScrollTop, { +import ScrollTop from 'discourse/mixins/scroll-top'; + +export default Ember.View.extend(ScrollTop, { _scrollOnModelChange: function() { this._scrollTop(); }.observes('controller.model.id') diff --git a/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 b/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 new file mode 100644 index 000000000..e3a5a81f6 --- /dev/null +++ b/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 @@ -0,0 +1,12 @@ +function scrollTop() { + if (Discourse.URL.isJumpScheduled()) { return; } + Ember.run.schedule('afterRender', function() { + $(document).scrollTop(0); + }); +} + +export default Ember.Mixin.create({ + _scrollTop: scrollTop.on('didInsertElement') +}); + +export { scrollTop }; diff --git a/app/assets/javascripts/discourse/mixins/scroll_top.js b/app/assets/javascripts/discourse/mixins/scroll_top.js deleted file mode 100644 index b183fbbb2..000000000 --- a/app/assets/javascripts/discourse/mixins/scroll_top.js +++ /dev/null @@ -1,8 +0,0 @@ -Discourse.ScrollTop = Em.Mixin.create({ - _scrollTop: function() { - if (Discourse.URL.isJumpScheduled()) { return; } - Em.run.schedule('afterRender', function() { - $(document).scrollTop(0); - }); - }.on('didInsertElement') -}); diff --git a/app/assets/javascripts/discourse/routes/discovery.js.es6 b/app/assets/javascripts/discourse/routes/discovery.js.es6 index 572b9536b..e5be7da1e 100644 --- a/app/assets/javascripts/discourse/routes/discovery.js.es6 +++ b/app/assets/javascripts/discourse/routes/discovery.js.es6 @@ -2,11 +2,11 @@ The parent route for all discovery routes. Handles the logic for showing the loading spinners. **/ - import ShowFooter from "discourse/mixins/show-footer"; import OpenComposer from "discourse/mixins/open-composer"; +import { scrollTop } from 'discourse/mixins/scroll-top'; -const DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, OpenComposer, ShowFooter, { +const DiscoveryRoute = Discourse.Route.extend(OpenComposer, ShowFooter, { redirect: function() { return this.redirectIfLoginRequired(); }, beforeModel: function(transition) { @@ -27,7 +27,7 @@ const DiscoveryRoute = Discourse.Route.extend(Discourse.ScrollTop, OpenComposer, loadingComplete: function() { this.controllerFor('discovery').set('loading', false); if (!this.session.get('topicListScrollPosition')) { - this._scrollTop(); + scrollTop(); } }, diff --git a/app/assets/javascripts/discourse/views/badges-index.js.es6 b/app/assets/javascripts/discourse/views/badges-index.js.es6 index 92b93c0be..f0b0ceb85 100644 --- a/app/assets/javascripts/discourse/views/badges-index.js.es6 +++ b/app/assets/javascripts/discourse/views/badges-index.js.es6 @@ -1,2 +1,3 @@ -export default Ember.View.extend(Discourse.ScrollTop); +import ScrollTop from 'discourse/mixins/scroll-top'; +export default Ember.View.extend(ScrollTop); diff --git a/app/assets/javascripts/discourse/views/discovery-categories.js.es6 b/app/assets/javascripts/discourse/views/discovery-categories.js.es6 index 460a15423..82b5904fa 100644 --- a/app/assets/javascripts/discourse/views/discovery-categories.js.es6 +++ b/app/assets/javascripts/discourse/views/discovery-categories.js.es6 @@ -1,6 +1,7 @@ import UrlRefresh from 'discourse/mixins/url-refresh'; +import ScrollTop from 'discourse/mixins/scroll-top'; -export default Discourse.View.extend(UrlRefresh, Discourse.ScrollTop, { +export default Discourse.View.extend(UrlRefresh, ScrollTop, { _addBodyClass: function() { $('body').addClass('categories-list'); }.on('didInsertElement'), diff --git a/app/assets/javascripts/discourse/views/discovery-top.js.es6 b/app/assets/javascripts/discourse/views/discovery-top.js.es6 index a50fbcd77..62950838e 100644 --- a/app/assets/javascripts/discourse/views/discovery-top.js.es6 +++ b/app/assets/javascripts/discourse/views/discovery-top.js.es6 @@ -1,3 +1,4 @@ import UrlRefresh from 'discourse/mixins/url-refresh'; +import ScrollTop from 'discourse/mixins/scroll-top'; -export default Discourse.View.extend(Discourse.ScrollTop, UrlRefresh); +export default Discourse.View.extend(ScrollTop, UrlRefresh); diff --git a/app/assets/javascripts/discourse/views/discovery-topics.js.es6 b/app/assets/javascripts/discourse/views/discovery-topics.js.es6 index 4e1ae4e8c..25b66239b 100644 --- a/app/assets/javascripts/discourse/views/discovery-topics.js.es6 +++ b/app/assets/javascripts/discourse/views/discovery-topics.js.es6 @@ -6,7 +6,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, { actions: { loadMore() { - var self = this; + const self = this; Discourse.notifyTitle(0); this.get('controller').loadMoreTopics().then(function (hasMoreResults) { Em.run.schedule('afterRender', function() { @@ -20,7 +20,7 @@ export default Discourse.View.extend(LoadMore, UrlRefresh, { }, _readjustScrollPosition: function() { - var scrollTo = this.session.get('topicListScrollPosition'); + const scrollTo = this.session.get('topicListScrollPosition'); if (typeof scrollTo !== "undefined") { Em.run.schedule('afterRender', function() { diff --git a/app/assets/javascripts/discourse/views/group-index.js.es6 b/app/assets/javascripts/discourse/views/group-index.js.es6 index b1da6e336..f16ebf262 100644 --- a/app/assets/javascripts/discourse/views/group-index.js.es6 +++ b/app/assets/javascripts/discourse/views/group-index.js.es6 @@ -1,5 +1,6 @@ +import ScrollTop from 'discourse/mixins/scroll-top'; import LoadMore from "discourse/mixins/load-more"; -export default Discourse.View.extend(Discourse.ScrollTop, LoadMore, { +export default Discourse.View.extend(ScrollTop, LoadMore, { eyelineSelector: '.user-stream .item', }); diff --git a/app/assets/javascripts/discourse/views/group-members.js.es6 b/app/assets/javascripts/discourse/views/group-members.js.es6 index 9dbfd112a..e3715a47e 100644 --- a/app/assets/javascripts/discourse/views/group-members.js.es6 +++ b/app/assets/javascripts/discourse/views/group-members.js.es6 @@ -1,5 +1,6 @@ +import ScrollTop from 'discourse/mixins/scroll-top'; import LoadMore from "discourse/mixins/load-more"; -export default Discourse.View.extend(Discourse.ScrollTop, LoadMore, { +export default Discourse.View.extend(ScrollTop, LoadMore, { eyelineSelector: '.group-members tr', }); diff --git a/app/assets/javascripts/discourse/views/static.js.es6 b/app/assets/javascripts/discourse/views/static.js.es6 index 318ee2cf7..12dbfdf60 100644 --- a/app/assets/javascripts/discourse/views/static.js.es6 +++ b/app/assets/javascripts/discourse/views/static.js.es6 @@ -1,8 +1,9 @@ import isElementInViewport from "discourse/lib/is-element-in-viewport"; +import ScrollTop from 'discourse/mixins/scroll-top'; var readFaq = false; -export default Ember.View.extend(Discourse.ScrollTop, { +export default Ember.View.extend(ScrollTop, { _checkRead: function() { const path = this.get('controller.model.path'); diff --git a/app/assets/javascripts/discourse/views/user-badges.js.es6 b/app/assets/javascripts/discourse/views/user-badges.js.es6 index 2bd2497f1..f0b0ceb85 100644 --- a/app/assets/javascripts/discourse/views/user-badges.js.es6 +++ b/app/assets/javascripts/discourse/views/user-badges.js.es6 @@ -1 +1,3 @@ -export default Ember.View.extend(Discourse.ScrollTop); +import ScrollTop from 'discourse/mixins/scroll-top'; + +export default Ember.View.extend(ScrollTop); diff --git a/app/assets/javascripts/discourse/views/user.js.es6 b/app/assets/javascripts/discourse/views/user.js.es6 index 7c795652b..99ccfdb60 100644 --- a/app/assets/javascripts/discourse/views/user.js.es6 +++ b/app/assets/javascripts/discourse/views/user.js.es6 @@ -1,4 +1,6 @@ -export default Ember.View.extend(Discourse.ScrollTop, { +import ScrollTop from 'discourse/mixins/scroll-top'; + +export default Ember.View.extend(ScrollTop, { templateName: 'user/user', userBinding: 'controller.content' });