diff --git a/app/assets/javascripts/discourse/views/discovery-categories.js.es6 b/app/assets/javascripts/discourse/components/discovery-categories.js.es6 similarity index 82% rename from app/assets/javascripts/discourse/views/discovery-categories.js.es6 rename to app/assets/javascripts/discourse/components/discovery-categories.js.es6 index ee4b13d7dce..d4b969b56d8 100644 --- a/app/assets/javascripts/discourse/views/discovery-categories.js.es6 +++ b/app/assets/javascripts/discourse/components/discovery-categories.js.es6 @@ -3,7 +3,9 @@ import { on } from 'ember-addons/ember-computed-decorators'; const CATEGORIES_LIST_BODY_CLASS = "categories-list"; -export default Ember.View.extend(UrlRefresh, { +export default Ember.Component.extend(UrlRefresh, { + classNames: ['contents'], + @on("didInsertElement") addBodyClass() { $('body').addClass(CATEGORIES_LIST_BODY_CLASS); diff --git a/app/assets/javascripts/discourse/views/discovery-topics.js.es6 b/app/assets/javascripts/discourse/components/discovery-topics-list.js.es6 similarity index 68% rename from app/assets/javascripts/discourse/views/discovery-topics.js.es6 rename to app/assets/javascripts/discourse/components/discovery-topics-list.js.es6 index ef5e3712c8e..d5a67e3f635 100644 --- a/app/assets/javascripts/discourse/views/discovery-topics.js.es6 +++ b/app/assets/javascripts/discourse/components/discovery-topics-list.js.es6 @@ -1,27 +1,15 @@ -import UrlRefresh from 'discourse/mixins/url-refresh'; -import LoadMore from "discourse/mixins/load-more"; import { on, observes } from "ember-addons/ember-computed-decorators"; +import LoadMore from "discourse/mixins/load-more"; +import UrlRefresh from 'discourse/mixins/url-refresh'; -export default Ember.View.extend(LoadMore, UrlRefresh, { +const DiscoveryTopicsListComponent = Ember.Component.extend(UrlRefresh, LoadMore, { + _viaComponent: true, + + classNames: ['contents'], eyelineSelector: '.topic-list-item', - actions: { - loadMore() { - const self = this; - Discourse.notifyTitle(0); - this.get('controller').loadMoreTopics().then(hasMoreResults => { - Ember.run.schedule('afterRender', () => self.saveScrollPosition()); - if (!hasMoreResults) { - this.get('eyeline').flushRest(); - } else if ($(window).height() >= $(document).height()) { - this.send("loadMore"); - } - }); - } - }, - @on("didInsertElement") - @observes("controller.model") + @observes("model") _readjustScrollPosition() { const scrollTo = this.session.get('topicListScrollPosition'); if (scrollTo && scrollTo >= 0) { @@ -31,19 +19,33 @@ export default Ember.View.extend(LoadMore, UrlRefresh, { } }, - @observes("controller.topicTrackingState.incomingCount") + @observes("incomingCount") _updateTitle() { - Discourse.notifyTitle(this.get('controller.topicTrackingState.incomingCount')); + Discourse.notifyTitle(this.get('incomingCount')); }, - // Remember where we were scrolled to saveScrollPosition() { this.session.set('topicListScrollPosition', $(window).scrollTop()); }, - // When the topic list is scrolled scrolled() { this._super(); this.saveScrollPosition(); + }, + + actions: { + loadMore() { + Discourse.notifyTitle(0); + this.get('model').loadMore().then(hasMoreResults => { + Ember.run.schedule('afterRender', () => this.saveScrollPosition()); + if (!hasMoreResults) { + this.get('eyeline').flushRest(); + } else if ($(window).height() >= $(document).height()) { + this.send("loadMore"); + } + }); + } } }); + +export default DiscoveryTopicsListComponent; diff --git a/app/assets/javascripts/discourse/components/group-post-stream.js.es6 b/app/assets/javascripts/discourse/components/group-post-stream.js.es6 new file mode 100644 index 00000000000..fc83f2dbb62 --- /dev/null +++ b/app/assets/javascripts/discourse/components/group-post-stream.js.es6 @@ -0,0 +1,8 @@ +export default Ember.Component.extend({ + actions: { + // TODO: When on Ember 1.13, use a closure action + loadMore() { + this.sendAction('loadMore'); + } + } +}); diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index 5e869506348..cc411691c5b 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -138,11 +138,8 @@ const controllerOpts = { return I18n.t("topics.none.educate." + split[0], { userPrefsUrl: Discourse.getURL("/users/") + (Discourse.User.currentProp("username_lower")) + "/preferences" }); - }.property('allLoaded', 'model.topics.length'), + }.property('allLoaded', 'model.topics.length') - loadMoreTopics() { - return this.get('model').loadMore(); - } }; Ember.keys(queryParams).forEach(function(p) { diff --git a/app/assets/javascripts/discourse/controllers/group-index.js.es6 b/app/assets/javascripts/discourse/controllers/group-index.js.es6 new file mode 100644 index 00000000000..7a5a5bf98ff --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/group-index.js.es6 @@ -0,0 +1,27 @@ +import { fmt } from 'discourse/lib/computed'; + +export default Ember.ArrayController.extend({ + needs: ['group'], + loading: false, + emptyText: fmt('type', 'groups.empty.%@'), + + actions: { + loadMore() { + + if (this.get('loading')) { return; } + this.set('loading', true); + const posts = this.get('model'); + if (posts && posts.length) { + const beforePostId = posts[posts.length-1].get('id'); + const group = this.get('controllers.group.model'); + + const opts = { beforePostId, type: this.get('type') }; + group.findPosts(opts).then(newPosts => { + posts.addObjects(newPosts); + this.set('loading', false); + }); + } + } + } +}); + diff --git a/app/assets/javascripts/discourse/controllers/group/index.js.es6 b/app/assets/javascripts/discourse/controllers/group/index.js.es6 deleted file mode 100644 index 60df6a2cdf1..00000000000 --- a/app/assets/javascripts/discourse/controllers/group/index.js.es6 +++ /dev/null @@ -1,28 +0,0 @@ -/** - Handles displaying posts within a group -**/ -export default Ember.ArrayController.extend({ - needs: ['group'], - loading: false, - - actions: { - loadMore: function() { - - if (this.get('loading')) { return; } - this.set('loading', true); - var posts = this.get('model'), - self = this; - if (posts && posts.length) { - var lastPostId = posts[posts.length-1].get('id'), - group = this.get('controllers.group.model'); - - var opts = {beforePostId: lastPostId, type: this.get('type')}; - group.findPosts(opts).then(function(newPosts) { - posts.addObjects(newPosts); - self.set('loading', false); - }); - } - } - } -}); - diff --git a/app/assets/javascripts/discourse/controllers/group/members.js.es6 b/app/assets/javascripts/discourse/controllers/group/members.js.es6 index 246a5f80cd1..09c4b9a63f3 100644 --- a/app/assets/javascripts/discourse/controllers/group/members.js.es6 +++ b/app/assets/javascripts/discourse/controllers/group/members.js.es6 @@ -1,5 +1,6 @@ import { popupAjaxError } from 'discourse/lib/ajax-error'; import computed from 'ember-addons/ember-computed-decorators'; +import Group from 'discourse/models/group'; export default Ember.Controller.extend({ loading: false, @@ -30,10 +31,7 @@ export default Ember.Controller.extend({ }, loadMore() { - const Group = require('discourse/models/group').default; - if (this.get("loading")) { return; } - // we've reached the end if (this.get("model.members.length") >= this.get("model.user_count")) { return; } this.set("loading", true); diff --git a/app/assets/javascripts/discourse/controllers/group/mentions.js.es6 b/app/assets/javascripts/discourse/controllers/group/mentions.js.es6 deleted file mode 100644 index 81fa5a8ffda..00000000000 --- a/app/assets/javascripts/discourse/controllers/group/mentions.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -import IndexController from 'discourse/controllers/group/index'; - -export default IndexController.extend({type: 'mentions'}); diff --git a/app/assets/javascripts/discourse/controllers/group/topics.js.es6 b/app/assets/javascripts/discourse/controllers/group/topics.js.es6 deleted file mode 100644 index 9423350320d..00000000000 --- a/app/assets/javascripts/discourse/controllers/group/topics.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -import IndexController from 'discourse/controllers/group/index'; - -export default IndexController.extend({type: 'topics'}); diff --git a/app/assets/javascripts/discourse/lib/app-events.js.es6 b/app/assets/javascripts/discourse/lib/app-events.js.es6 index 597c21b83df..59257700fdf 100644 --- a/app/assets/javascripts/discourse/lib/app-events.js.es6 +++ b/app/assets/javascripts/discourse/lib/app-events.js.es6 @@ -1,25 +1 @@ - -var id = 1; -function newKey() { - return "_view_app_event_" + (id++); -} - -function createViewListener(eventName, cb) { - var extension = {}; - extension[newKey()] = function() { - this.appEvents.on(eventName, this, cb); - }.on('didInsertElement'); - - extension[newKey()] = function() { - this.appEvents.off(eventName, this, cb); - }.on('willDestroyElement'); - - return extension; -} - -function listenForViewEvent(viewClass, eventName, cb) { - viewClass.reopen(createViewListener(eventName, cb)); -} - -export { listenForViewEvent, createViewListener }; export default Ember.Object.extend(Ember.Evented); diff --git a/app/assets/javascripts/discourse/lib/click-track.js.es6 b/app/assets/javascripts/discourse/lib/click-track.js.es6 index 799c26ada8b..b25dacd98e3 100644 --- a/app/assets/javascripts/discourse/lib/click-track.js.es6 +++ b/app/assets/javascripts/discourse/lib/click-track.js.es6 @@ -1,4 +1,5 @@ import DiscourseURL from 'discourse/lib/url'; +import { wantsNewWindow } from 'discourse/lib/intercept-click'; export function isValidLink($link) { return ($link.hasClass("track-link") || @@ -52,7 +53,7 @@ export default { } // if they want to open in a new tab, do an AJAX request - if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { + if (wantsNewWindow(e)) { Discourse.ajax("/clicks/track", { data: { url: href, diff --git a/app/assets/javascripts/discourse/lib/intercept-click.js.es6 b/app/assets/javascripts/discourse/lib/intercept-click.js.es6 index 658f55db64b..09367beca23 100644 --- a/app/assets/javascripts/discourse/lib/intercept-click.js.es6 +++ b/app/assets/javascripts/discourse/lib/intercept-click.js.es6 @@ -1,12 +1,16 @@ import DiscourseURL from 'discourse/lib/url'; +export function wantsNewWindow(e) { + return (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey || (e.button && e.button !== 0)); +} + /** Discourse does some server side rendering of HTML, such as the `cooked` contents of posts. The downside of this in an Ember app is the links will not go through the router. This jQuery code intercepts clicks on those links and routes them properly. **/ export default function interceptClick(e) { - if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; } + if (wantsNewWindow(e)) { return; } const $currentTarget = $(e.currentTarget), href = $currentTarget.attr('href'); diff --git a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 index e5ab51cb3db..bf1710d1c10 100644 --- a/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 +++ b/app/assets/javascripts/discourse/mixins/url-refresh.js.es6 @@ -1,12 +1,16 @@ // A Mixin that a view can use to listen for 'url:refresh' when -// it is on screen, and will send an action to the controller to -// refresh its data. +// it is on screen, and will send an action to refresh its data. // // This is useful if you want to get around Ember's default // behavior of not refreshing when navigating to the same place. +export default { + didInsertElement() { + this._super(); + this.appEvents.on('url:refresh', () => this.sendAction('refresh')); + }, -import { createViewListener } from 'discourse/lib/app-events'; - -export default createViewListener('url:refresh', function() { - this.get('controller').send('refresh'); -}); + willDestroyElement() { + this._super(); + this.appEvents.off('url:refresh'); + } +}; diff --git a/app/assets/javascripts/discourse/routes/group-index.js.es6 b/app/assets/javascripts/discourse/routes/group-index.js.es6 index bb8ecaeb03c..a7baf27a150 100644 --- a/app/assets/javascripts/discourse/routes/group-index.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-index.js.es6 @@ -1,14 +1,24 @@ -export default Discourse.Route.extend({ - actions: { - didTransition() { return true; } - }, +export function buildIndex(type) { + return Discourse.Route.extend({ + type, - model() { - return this.modelFor("group").findPosts(); - }, + model() { + return this.modelFor("group").findPosts({ type }); + }, - setupController(controller, model) { - controller.set("model", model); - this.controllerFor("group").set("showing", "posts"); - } -}); + setupController(controller, model) { + this.controllerFor('group-index').setProperties({ model, type }); + this.controllerFor("group").set("showing", type); + }, + + renderTemplate() { + this.render('group-index'); + }, + + actions: { + didTransition() { return true; } + } + }); +} + +export default buildIndex('posts'); diff --git a/app/assets/javascripts/discourse/routes/group-members.js.es6 b/app/assets/javascripts/discourse/routes/group-members.js.es6 index 22e328cacf8..c6e00e80283 100644 --- a/app/assets/javascripts/discourse/routes/group-members.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-members.js.es6 @@ -8,5 +8,4 @@ export default Discourse.Route.extend({ controller.set("model", model); model.findMembers(); } - }); diff --git a/app/assets/javascripts/discourse/routes/group-mentions.js.es6 b/app/assets/javascripts/discourse/routes/group-mentions.js.es6 index 1054fb18d3a..d5c7471f518 100644 --- a/app/assets/javascripts/discourse/routes/group-mentions.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-mentions.js.es6 @@ -1,11 +1,3 @@ -export default Discourse.Route.extend({ +import { buildIndex } from 'discourse/routes/group-index'; - model() { - return this.modelFor("group").findPosts({type: 'mentions'}); - }, - - setupController(controller, model) { - controller.set("model", model); - this.controllerFor("group").set("showing", "mentions"); - } -}); +export default buildIndex('mentions'); diff --git a/app/assets/javascripts/discourse/routes/group-messages.js.es6 b/app/assets/javascripts/discourse/routes/group-messages.js.es6 index 34e077e362e..df27a3f793b 100644 --- a/app/assets/javascripts/discourse/routes/group-messages.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-messages.js.es6 @@ -1,11 +1,3 @@ -export default Discourse.Route.extend({ +import { buildIndex } from 'discourse/routes/group-index'; - model() { - return this.modelFor("group").findPosts({type: 'messages'}); - }, - - setupController(controller, model) { - controller.set("model", model); - this.controllerFor("group").set("showing", "messages"); - } -}); +export default buildIndex('messages'); diff --git a/app/assets/javascripts/discourse/routes/group-topics.js.es6 b/app/assets/javascripts/discourse/routes/group-topics.js.es6 index 397572e77bf..991bb7475a3 100644 --- a/app/assets/javascripts/discourse/routes/group-topics.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-topics.js.es6 @@ -1,11 +1,3 @@ -export default Discourse.Route.extend({ +import { buildIndex } from 'discourse/routes/group-index'; - model() { - return this.modelFor("group").findPosts({type: 'topics'}); - }, - - setupController(controller, model) { - controller.set("model", model); - this.controllerFor("group").set("showing", "topics"); - } -}); +export default buildIndex('topics'); diff --git a/app/assets/javascripts/discourse/templates/components/group-post-stream.js.hbs b/app/assets/javascripts/discourse/templates/components/group-post-stream.js.hbs index 42af3ae4541..9ab4c17c68c 100644 --- a/app/assets/javascripts/discourse/templates/components/group-post-stream.js.hbs +++ b/app/assets/javascripts/discourse/templates/components/group-post-stream.js.hbs @@ -1,7 +1,9 @@ -
- {{#each posts as |post|}} - {{group-post post=post}} - {{else}} -
{{i18n emptyText}}
- {{/each}} -
+{{#load-more selector=".user-stream .item" action="loadMore"}} +
+ {{#each posts as |post|}} + {{group-post post=post}} + {{else}} +
{{i18n emptyText}}
+ {{/each}} +
+{{/load-more}} diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/discovery/categories.hbs index dcd5c6acfd8..7d26d35ba23 100644 --- a/app/assets/javascripts/discourse/templates/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/categories.hbs @@ -1,5 +1,5 @@ {{#if model.categories}} -
+ {{#discovery-categories refresh="refresh"}} @@ -54,6 +54,6 @@ {{/each}}
-
+ {{/discovery-categories}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/discovery/topics.hbs index 9b55d626aea..8bb13926fc1 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/topics.hbs @@ -15,7 +15,7 @@ {{bulk-select-button selected=selected refreshTarget=controller}} -
+{{#discovery-topics-list model=model refresh="refresh" incomingCount=topicTrackingState.incomingCount}} {{#if top}}
{{period-chooser period=period action="changePeriod"}} @@ -32,23 +32,23 @@ {{/if}} {{#if hasTopics}} - {{topic-list - showTopicPostBadges=showTopicPostBadges - showPosters=true - currentUser=currentUser - canBulkSelect=canBulkSelect - changeSort="changeSort" - toggleBulkSelect="toggleBulkSelect" - hideCategory=model.hideCategory - order=order - ascending=ascending - bulkSelectEnabled=bulkSelectEnabled - selected=selected - expandGloballyPinned=expandGloballyPinned - expandAllPinned=expandAllPinned - topics=model.topics}} + {{topic-list + showTopicPostBadges=showTopicPostBadges + showPosters=true + currentUser=currentUser + canBulkSelect=canBulkSelect + changeSort="changeSort" + toggleBulkSelect="toggleBulkSelect" + hideCategory=model.hideCategory + order=order + ascending=ascending + bulkSelectEnabled=bulkSelectEnabled + selected=selected + expandGloballyPinned=expandGloballyPinned + expandAllPinned=expandAllPinned + topics=model.topics}} {{/if}} -
+{{/discovery-topics-list}}
{{/if}} - - - - - {{#if isOwner}} - - {{/if}} - - {{#each model.members as |m|}} + + {{#load-more selector=".group-members tr" action="loadMore"}} +
{{i18n 'last_post'}}{{i18n 'last_seen'}}
- - - + + {{#if isOwner}} - + {{/if}} - {{/each}} -
- {{user-info user=m}} - {{#if m.owner}}{{i18n "groups.owner"}}{{/if}} - - {{bound-date m.last_posted_at}} - - {{bound-date m.last_seen_at}} - {{i18n 'last_post'}}{{i18n 'last_seen'}} - {{#unless m.owner}} - - {{/unless}} -
+ {{#each model.members as |m|}} + + + {{user-info user=m}} + {{#if m.owner}}{{i18n "groups.owner"}}{{/if}} + + + {{bound-date m.last_posted_at}} + + + {{bound-date m.last_seen_at}} + + {{#if isOwner}} + + {{#unless m.owner}} + + {{/unless}} + + {{/if}} + + {{/each}} + + {{/load-more}} {{else}}
{{i18n "groups.empty.users"}}
{{/if}} diff --git a/app/assets/javascripts/discourse/templates/group/mentions.hbs b/app/assets/javascripts/discourse/templates/group/mentions.hbs deleted file mode 100644 index 3fa0965f262..00000000000 --- a/app/assets/javascripts/discourse/templates/group/mentions.hbs +++ /dev/null @@ -1 +0,0 @@ -{{group-post-stream posts=controller emptyText="groups.empty.mentions"}} diff --git a/app/assets/javascripts/discourse/templates/group/messages.hbs b/app/assets/javascripts/discourse/templates/group/messages.hbs deleted file mode 100644 index 9b457e64eb1..00000000000 --- a/app/assets/javascripts/discourse/templates/group/messages.hbs +++ /dev/null @@ -1 +0,0 @@ -{{group-post-stream posts=controller emptyText="groups.empty.messages"}} diff --git a/app/assets/javascripts/discourse/templates/group/topics.hbs b/app/assets/javascripts/discourse/templates/group/topics.hbs deleted file mode 100644 index 2a9a4eed965..00000000000 --- a/app/assets/javascripts/discourse/templates/group/topics.hbs +++ /dev/null @@ -1 +0,0 @@ -{{group-post-stream posts=controller emptyText="groups.empty.topics"}} diff --git a/app/assets/javascripts/discourse/views/discovery-top.js.es6 b/app/assets/javascripts/discourse/views/discovery-top.js.es6 deleted file mode 100644 index 72d1e7167e9..00000000000 --- a/app/assets/javascripts/discourse/views/discovery-top.js.es6 +++ /dev/null @@ -1,4 +0,0 @@ -import UrlRefresh from 'discourse/mixins/url-refresh'; -import ScrollTop from 'discourse/mixins/scroll-top'; - -export default Ember.View.extend(ScrollTop, UrlRefresh); diff --git a/app/assets/javascripts/discourse/views/group-index.js.es6 b/app/assets/javascripts/discourse/views/group-index.js.es6 deleted file mode 100644 index 4e25173395f..00000000000 --- a/app/assets/javascripts/discourse/views/group-index.js.es6 +++ /dev/null @@ -1,6 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; -import LoadMore from "discourse/mixins/load-more"; - -export default Ember.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 deleted file mode 100644 index cae92ca87ed..00000000000 --- a/app/assets/javascripts/discourse/views/group-members.js.es6 +++ /dev/null @@ -1,6 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; -import LoadMore from "discourse/mixins/load-more"; - -export default Ember.View.extend(ScrollTop, LoadMore, { - eyelineSelector: '.group-members tr', -}); diff --git a/app/assets/javascripts/discourse/views/group-mentions.js.es6 b/app/assets/javascripts/discourse/views/group-mentions.js.es6 deleted file mode 100644 index 4e25173395f..00000000000 --- a/app/assets/javascripts/discourse/views/group-mentions.js.es6 +++ /dev/null @@ -1,6 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; -import LoadMore from "discourse/mixins/load-more"; - -export default Ember.View.extend(ScrollTop, LoadMore, { - eyelineSelector: '.user-stream .item', -}); diff --git a/app/assets/javascripts/discourse/views/group-topics.js.es6 b/app/assets/javascripts/discourse/views/group-topics.js.es6 deleted file mode 100644 index 4e25173395f..00000000000 --- a/app/assets/javascripts/discourse/views/group-topics.js.es6 +++ /dev/null @@ -1,6 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; -import LoadMore from "discourse/mixins/load-more"; - -export default Ember.View.extend(ScrollTop, LoadMore, { - eyelineSelector: '.user-stream .item', -}); diff --git a/app/assets/javascripts/discourse/views/share.js.es6 b/app/assets/javascripts/discourse/views/share.js.es6 index c15f26d8359..29ce3f95c69 100644 --- a/app/assets/javascripts/discourse/views/share.js.es6 +++ b/app/assets/javascripts/discourse/views/share.js.es6 @@ -1,3 +1,4 @@ +import { wantsNewWindow } from 'discourse/lib/intercept-click'; export default Ember.View.extend({ templateName: 'share', @@ -95,7 +96,7 @@ export default Ember.View.extend({ $html.on('click.discoure-share-link', '[data-share-url]', function(e) { // if they want to open in a new tab, let it so - if (e.shiftKey || e.metaKey || e.ctrlKey || e.which === 2) { return true; } + if (wantsNewWindow(e)) { return true; } e.preventDefault(); diff --git a/app/assets/javascripts/discourse/views/topic.js.es6 b/app/assets/javascripts/discourse/views/topic.js.es6 index 77fd4dcfe4a..6ef0621a528 100644 --- a/app/assets/javascripts/discourse/views/topic.js.es6 +++ b/app/assets/javascripts/discourse/views/topic.js.es6 @@ -1,7 +1,6 @@ import AddCategoryClass from 'discourse/mixins/add-category-class'; import AddArchetypeClass from 'discourse/mixins/add-archetype-class'; import ClickTrack from 'discourse/lib/click-track'; -import { listenForViewEvent } from 'discourse/lib/app-events'; import { categoryBadgeHTML } from 'discourse/helpers/category-link'; import Scrolling from 'discourse/mixins/scrolling'; @@ -63,6 +62,9 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli return ClickTrack.trackClick(e); }); + this.appEvents.on('post:highlight', postNumber => { + Ember.run.scheduleOnce('afterRender', null, highlight, postNumber); + }); }.on('didInsertElement'), // This view is being removed. Shut down operations @@ -77,6 +79,7 @@ const TopicView = Ember.View.extend(AddCategoryClass, AddArchetypeClass, Scrolli // this happens after route exit, stuff could have trickled in this.appEvents.trigger('header:hide-topic'); + this.appEvents.off('post:highlight'); }.on('willDestroyElement'), @@ -200,8 +203,4 @@ function highlight(postNumber) { }); } -listenForViewEvent(TopicView, 'post:highlight', postNumber => { - Ember.run.scheduleOnce('afterRender', null, highlight, postNumber); -}); - export default TopicView; diff --git a/app/assets/javascripts/discourse/views/user-card.js.es6 b/app/assets/javascripts/discourse/views/user-card.js.es6 index 6e1b42d22bc..584254c7e5e 100644 --- a/app/assets/javascripts/discourse/views/user-card.js.es6 +++ b/app/assets/javascripts/discourse/views/user-card.js.es6 @@ -1,3 +1,4 @@ +import { wantsNewWindow } from 'discourse/lib/intercept-click'; import { setting } from 'discourse/lib/computed'; import CleansUp from 'discourse/mixins/cleans-up'; import afterTransition from 'discourse/lib/after-transition'; @@ -57,7 +58,7 @@ export default Ember.View.extend(CleansUp, { }; $('#main-outlet').on(clickDataExpand, '[data-user-card]', (e) => { - if (e.ctrlKey || e.metaKey) { return; } + if (wantsNewWindow(e)) { return; } const $target = $(e.currentTarget), username = $target.data('user-card'); @@ -65,7 +66,7 @@ export default Ember.View.extend(CleansUp, { }); $('#main-outlet').on(clickMention, 'a.mention', (e) => { - if (e.ctrlKey || e.metaKey) { return; } + if (wantsNewWindow(e)) { return; } const $target = $(e.target), username = $target.text().replace(/^@/, ''); diff --git a/app/assets/javascripts/discourse/widgets/home-logo.js.es6 b/app/assets/javascripts/discourse/widgets/home-logo.js.es6 index 4f95c85a982..a99661e379a 100644 --- a/app/assets/javascripts/discourse/widgets/home-logo.js.es6 +++ b/app/assets/javascripts/discourse/widgets/home-logo.js.es6 @@ -1,7 +1,8 @@ import { createWidget } from 'discourse/widgets/widget'; import { h } from 'virtual-dom'; import { iconNode } from 'discourse/helpers/fa-icon'; -import interceptClick from 'discourse/lib/intercept-click'; +import { wantsNewWindow } from 'discourse/lib/intercept-click'; +import DiscourseURL from 'discourse/lib/url'; export default createWidget('home-logo', { tagName: 'div.title', @@ -40,5 +41,11 @@ export default createWidget('home-logo', { return h('a', { attributes: { href: this.settings.href } }, this.logo()); }, - click: interceptClick + click(e) { + if (wantsNewWindow(e)) { return false; } + e.preventDefault(); + DiscourseURL.routeTo(this.settings.href); + return false; + } + }); diff --git a/app/assets/javascripts/discourse/widgets/link.js.es6 b/app/assets/javascripts/discourse/widgets/link.js.es6 index 587964b23d7..5f1782fd056 100644 --- a/app/assets/javascripts/discourse/widgets/link.js.es6 +++ b/app/assets/javascripts/discourse/widgets/link.js.es6 @@ -1,3 +1,4 @@ +import { wantsNewWindow } from 'discourse/lib/intercept-click'; import { createWidget } from 'discourse/widgets/widget'; import { iconNode } from 'discourse/helpers/fa-icon'; import { h } from 'virtual-dom'; @@ -70,7 +71,7 @@ export default createWidget('link', { }, click(e) { - if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; } + if (wantsNewWindow(e)) { return; } e.preventDefault(); if (this.attrs.action) { diff --git a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 index f152403ee6d..b09284c1571 100644 --- a/app/assets/javascripts/discourse/widgets/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/widgets/notification-item.js.es6 @@ -1,3 +1,4 @@ +import { wantsNewWindow } from 'discourse/lib/intercept-click'; import RawHtml from 'discourse/widgets/raw-html'; import { createWidget } from 'discourse/widgets/widget'; import DiscourseURL from 'discourse/lib/url'; @@ -103,7 +104,7 @@ createWidget('notification-item', { if (document && document.cookie) { document.cookie = `cn=${id}; expires=Fri, 31 Dec 9999 23:59:59 GMT`; } - if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey || e.button !== 0) { return; } + if (wantsNewWindow(e)) { return; } e.preventDefault(); this.sendWidgetEvent('linkClicked');