diff --git a/app/assets/javascripts/admin/views/admin_customize_view.js b/app/assets/javascripts/admin/views/admin_customize_view.js index cb8dbce98..a030d4324 100644 --- a/app/assets/javascripts/admin/views/admin_customize_view.js +++ b/app/assets/javascripts/admin/views/admin_customize_view.js @@ -34,9 +34,9 @@ Discourse.AdminCustomizeView = Discourse.View.extend({ }, didInsertElement: function() { - var _this = this; + var controller = this.get('controller'); return Mousetrap.bindGlobal(['meta+s', 'ctrl+s'], function() { - _this.get('controller').save(); + controller.save(); return false; }); }, diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index 305a4ccb6..954d8ad1b 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -39,14 +39,21 @@ Discourse = Ember.Application.createWithMixins({ even though our path formats are slightly different than what ember prefers. */ resolver: Ember.DefaultResolver.extend({ + resolveTemplate: function(parsedName) { var resolvedTemplate = this._super(parsedName); if (resolvedTemplate) { return resolvedTemplate; } + var decamelized = parsedName.fullNameWithoutType.decamelize(); + + // See if we can find it with slashes instead of underscores + var slashed = decamelized.replace("_", "/"); + resolvedTemplate = Ember.TEMPLATES[slashed]; + if (resolvedTemplate) { return resolvedTemplate; } + // If we can't find a template, check to see if it's similar to how discourse // lays out templates like: adminEmail => admin/templates/email if (parsedName.fullNameWithoutType.indexOf('admin') === 0) { - var decamelized = parsedName.fullNameWithoutType.decamelize(); decamelized = decamelized.replace(/^admin\_/, 'admin/templates/'); decamelized = decamelized.replace(/^admin\./, 'admin/templates/'); decamelized = decamelized.replace(/\./, '_'); diff --git a/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js b/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js index 6e90145a2..ea12526f7 100644 --- a/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js +++ b/app/assets/javascripts/discourse/views/buttons/dropdown_button_view.js @@ -14,7 +14,7 @@ Discourse.DropdownButtonView = Discourse.View.extend({ // If there's a click handler, call it if (this.clicked) { var dropDownButtonView = this; - this.$('ul li').on('click', function(e) { + this.$('ul li').on('click.dropdown-button', function(e) { e.preventDefault(); dropDownButtonView.clicked($(e.currentTarget).data('id')); return false; @@ -23,7 +23,7 @@ Discourse.DropdownButtonView = Discourse.View.extend({ }, willDestroyElement: function(e) { - this.$('ul li').off('click'); + this.$('ul li').off('click.dropdown-button'); }, textChanged: function() { diff --git a/app/assets/javascripts/discourse/views/combobox_view.js b/app/assets/javascripts/discourse/views/combobox_view.js index f1f5fc695..97488bfd2 100644 --- a/app/assets/javascripts/discourse/views/combobox_view.js +++ b/app/assets/javascripts/discourse/views/combobox_view.js @@ -12,28 +12,31 @@ Discourse.ComboboxView = Discourse.View.extend({ valueAttribute: 'id', render: function(buffer) { - var _ref, - _this = this; // Add none option if required if (this.get('none')) { buffer.push(""); } - var selected = (_ref = this.get('value')) ? _ref.toString() : void 0; + var selected = this.get('value'); + if (selected) { selected = selected.toString(); } if (this.get('content')) { + + var comboboxView = this; return this.get('content').each(function(o) { - var data, selectedText, val, _ref1; - val = (_ref1 = o[_this.get('valueAttribute')]) ? _ref1.toString() : void 0; - selectedText = val === selected ? "selected" : ""; - data = ""; - if (_this.dataAttributes) { - _this.dataAttributes.forEach(function(a) { + var val = o[comboboxView.get('valueAttribute')]; + if (val) { val = val.toString(); } + + var selectedText = (val === selected) ? "selected" : ""; + + var data = ""; + if (comboboxView.dataAttributes) { + comboboxView.dataAttributes.forEach(function(a) { data += "data-" + a + "=\"" + (o.get(a)) + "\" "; }); } - return buffer.push(""); + buffer.push(""); }); } }, @@ -42,7 +45,7 @@ Discourse.ComboboxView = Discourse.View.extend({ var $combo = this.$(); var val = this.get('value'); if (val) { - $combo.val(this.get('value').toString()); + $combo.val(val.toString()); } else { $combo.val(null); } @@ -50,9 +53,9 @@ Discourse.ComboboxView = Discourse.View.extend({ }.observes('value'), didInsertElement: function() { - var $elem, - _this = this; - $elem = this.$(); + var $elem = this.$(); + var comboboxView = this; + $elem.chosen({ template: this.template, disable_search_threshold: 5 }); if (this.overrideWidths) { // The Chosen plugin hard-codes the widths in style attrs. :< @@ -69,7 +72,7 @@ Discourse.ComboboxView = Discourse.View.extend({ } $elem.change(function(e) { - _this.set('value', $(e.target).val()); + comboboxView.set('value', $(e.target).val()); }); } diff --git a/app/assets/javascripts/discourse/views/embedded_post_view.js b/app/assets/javascripts/discourse/views/embedded_post_view.js index c4e133626..765759e4c 100644 --- a/app/assets/javascripts/discourse/views/embedded_post_view.js +++ b/app/assets/javascripts/discourse/views/embedded_post_view.js @@ -12,7 +12,7 @@ Discourse.EmbeddedPostView = Discourse.View.extend({ didInsertElement: function() { var postView = this.get('postView') || this.get('parentView.postView'); - return postView.get('screenTrack').track(this.get('elementId'), this.get('post.post_number')); + postView.get('screenTrack').track(this.get('elementId'), this.get('post.post_number')); } }); diff --git a/app/assets/javascripts/discourse/views/header_view.js b/app/assets/javascripts/discourse/views/header_view.js index 98fd51277..fde91cffc 100644 --- a/app/assets/javascripts/discourse/views/header_view.js +++ b/app/assets/javascripts/discourse/views/header_view.js @@ -108,38 +108,41 @@ Discourse.HeaderView = Discourse.View.extend({ willDestroyElement: function() { $(window).unbind('scroll.discourse-dock'); - return $(document).unbind('touchmove.discourse-dock'); + $(document).unbind('touchmove.discourse-dock'); + this.$('a.unread-private-messages, a.unread-notifications, a[data-notifications]').off('click.notifications'); + this.$('a[data-dropdown]').off('click.dropdown'); }, didInsertElement: function() { - var _this = this; - this.$('a[data-dropdown]').on('click', function(e) { - return _this.showDropdown($(e.currentTarget)); + + var headerView = this; + this.$('a[data-dropdown]').on('click.dropdown', function(e) { + return headerView.showDropdown($(e.currentTarget)); }); - this.$('a.unread-private-messages, a.unread-notifications, a[data-notifications]').on('click', function(e) { - return _this.showNotifications(e); + this.$('a.unread-private-messages, a.unread-notifications, a[data-notifications]').on('click.notifications', function(e) { + return headerView.showNotifications(e); }); $(window).bind('scroll.discourse-dock', function() { - return _this.examineDockHeader(); + headerView.examineDockHeader(); }); $(document).bind('touchmove.discourse-dock', function() { - return _this.examineDockHeader(); + headerView.examineDockHeader(); }); this.examineDockHeader(); // Delegate ESC to the composer - return $('body').on('keydown.header', function(e) { + $('body').on('keydown.header', function(e) { // Hide dropdowns if (e.which === 27) { - _this.$('li').removeClass('active'); - _this.$('.d-dropdown').fadeOut('fast'); + headerView.$('li').removeClass('active'); + headerView.$('.d-dropdown').fadeOut('fast'); } - if (_this.get('editingTopic')) { + if (headerView.get('editingTopic')) { if (e.which === 13) { - _this.finishedEdit(); + headerView.finishedEdit(); } if (e.which === 27) { - return _this.cancelEdit(); + return headerView.cancelEdit(); } } }); diff --git a/app/assets/javascripts/discourse/views/list/list_categories_view.js b/app/assets/javascripts/discourse/views/list/list_categories_view.js deleted file mode 100644 index c4a5d537d..000000000 --- a/app/assets/javascripts/discourse/views/list/list_categories_view.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - This view handles the rendering of a category list - - @class ListCategoriesView - @extends Discourse.View - @namespace Discourse - @module Discourse -**/ -Discourse.ListCategoriesView = Discourse.View.extend({ - - templateName: 'list/categories', - - didInsertElement: function() { - return Discourse.set('title', Em.String.i18n("category.list")); - } - -}); - - diff --git a/app/assets/javascripts/discourse/views/list/list_topics_view.js b/app/assets/javascripts/discourse/views/list/list_topics_view.js index c6ab8d4f5..1e2a623ef 100644 --- a/app/assets/javascripts/discourse/views/list/list_topics_view.js +++ b/app/assets/javascripts/discourse/views/list/list_topics_view.js @@ -14,6 +14,7 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, { listBinding: 'controller.model', loadedMore: false, currentTopicId: null, + topicTrackingState: function() { return Discourse.TopicTrackingState.current(); }.property(), diff --git a/app/assets/javascripts/discourse/views/list/topic_list_item_view.js b/app/assets/javascripts/discourse/views/list/topic_list_item_view.js index 0c4a6c9d2..8a2dcd9d6 100644 --- a/app/assets/javascripts/discourse/views/list/topic_list_item_view.js +++ b/app/assets/javascripts/discourse/views/list/topic_list_item_view.js @@ -12,9 +12,9 @@ Discourse.TopicListItemView = Discourse.View.extend({ classNameBindings: ['content.archived', ':topic-list-item', 'content.hasExcerpt:has-excerpt'], attributeBindings: ['data-topic-id'], - 'data-topic-id': (function() { + 'data-topic-id': function() { return this.get('content.id'); - }).property('content.id'), + }.property('content.id'), init: function() { this._super(); @@ -22,10 +22,9 @@ Discourse.TopicListItemView = Discourse.View.extend({ }, highlight: function() { - var $topic, originalCol; - $topic = this.$(); - originalCol = $topic.css('backgroundColor'); - return $topic.css({ + var $topic = this.$(); + var originalCol = $topic.css('backgroundColor'); + $topic.css({ backgroundColor: "#ffffcc" }).animate({ backgroundColor: originalCol diff --git a/app/assets/javascripts/discourse/views/pagedown_editor.js b/app/assets/javascripts/discourse/views/pagedown_editor.js index a1b405e5f..3199ef665 100644 --- a/app/assets/javascripts/discourse/views/pagedown_editor.js +++ b/app/assets/javascripts/discourse/views/pagedown_editor.js @@ -26,7 +26,7 @@ Discourse.PagedownEditor = Discourse.ContainerView.extend({ didInsertElement: function() { $('#wmd-input').data('init', true); this.set('editor', Discourse.Markdown.createEditor()); - return this.get('editor').run(); + this.get('editor').run(); }, observeValue: function() { diff --git a/app/assets/javascripts/discourse/views/post_view.js b/app/assets/javascripts/discourse/views/post_view.js index bb6be7f66..7cbf4e252 100644 --- a/app/assets/javascripts/discourse/views/post_view.js +++ b/app/assets/javascripts/discourse/views/post_view.js @@ -243,10 +243,9 @@ Discourse.PostView = Discourse.View.extend({ Discourse.Lightbox.apply($post); // If we're scrolling upwards, adjust the scroll position accordingly - var scrollTo; - if (scrollTo = this.get('post.scrollTo')) { - var newSize = ($(document).height() - scrollTo.height) + scrollTo.top; - $('body').scrollTop(newSize); + var scrollTo = this.get('post.scrollTo'); + if (scrollTo) { + $('body').scrollTop(($(document).height() - scrollTo.height) + scrollTo.top); $('section.divider').addClass('fade'); } diff --git a/app/assets/javascripts/discourse/views/quote_button_view.js b/app/assets/javascripts/discourse/views/quote_button_view.js index 64a73acaa..bd1cee19c 100644 --- a/app/assets/javascripts/discourse/views/quote_button_view.js +++ b/app/assets/javascripts/discourse/views/quote_button_view.js @@ -18,9 +18,7 @@ Discourse.QuoteButtonView = Discourse.View.extend({ @property visible **/ - visible: function() { - return this.present('controller.buffer'); - }.property('controller.buffer'), + visible: Em.computed.notEmpty('controller.buffer'), /** Renders the pop-up quote button. @@ -45,23 +43,23 @@ Discourse.QuoteButtonView = Discourse.View.extend({ view = this; $(document) - .on("mousedown.quote-button", function(e) { - view.set('isMouseDown', true); - if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return; - // deselects only when the user left-click - // this also allow anyone to `extend` their selection using a shift+click - if (e.which === 1 && !e.shiftKey) controller.deselectText(); - }) - .on('mouseup.quote-button', function(e) { - view.selectText(e.target, controller); - view.set('isMouseDown', false); - }) - .on('selectionchange', function() { - // there is no need to handle this event when the mouse is down - if (view.get('isMouseDown')) return; - // `selection.anchorNode` is used as a target - view.selectText(window.getSelection().anchorNode, controller); - }); + .on("mousedown.quote-button", function(e) { + view.set('isMouseDown', true); + if ($(e.target).hasClass('quote-button') || $(e.target).hasClass('create')) return; + // deselects only when the user left-click + // this also allow anyone to `extend` their selection using a shift+click + if (e.which === 1 && !e.shiftKey) controller.deselectText(); + }) + .on('mouseup.quote-button', function(e) { + view.selectText(e.target, controller); + view.set('isMouseDown', false); + }) + .on('selectionchange', function() { + // there is no need to handle this event when the mouse is down + if (view.get('isMouseDown')) return; + // `selection.anchorNode` is used as a target + view.selectText(window.getSelection().anchorNode, controller); + }); }, /** @@ -86,9 +84,9 @@ Discourse.QuoteButtonView = Discourse.View.extend({ **/ willDestroyElement: function() { $(document) - .off("mousedown.quote-button") - .off("mouseup.quote-button") - .off("selectionchange"); + .off("mousedown.quote-button") + .off("mouseup.quote-button") + .off("selectionchange"); }, /** diff --git a/app/assets/javascripts/discourse/views/share_view.js b/app/assets/javascripts/discourse/views/share_view.js index 9bda689a9..0d9f17cc8 100644 --- a/app/assets/javascripts/discourse/views/share_view.js +++ b/app/assets/javascripts/discourse/views/share_view.js @@ -11,17 +11,17 @@ Discourse.ShareView = Discourse.View.extend({ elementId: 'share-link', classNameBindings: ['hasLink'], - title: (function() { + title: function() { if (this.get('controller.type') === 'topic') return Em.String.i18n('share.topic'); return Em.String.i18n('share.post'); - }).property('controller.type'), + }.property('controller.type'), - hasLink: (function() { + hasLink: function() { if (this.present('controller.link')) return 'visible'; return null; - }).property('controller.link'), + }.property('controller.link'), - linkChanged: (function() { + linkChanged: function() { if (this.present('controller.link')) { var $linkInput = $('#share-link input'); $linkInput.val(this.get('controller.link')); @@ -31,36 +31,35 @@ Discourse.ShareView = Discourse.View.extend({ $linkInput.select().focus(); }, 160); } - }).observes('controller.link'), + }.observes('controller.link'), didInsertElement: function() { - var _this = this; + + var shareView = this; $('html').on('mousedown.outside-share-link', function(e) { // Use mousedown instead of click so this event is handled before routing occurs when a // link is clicked (which is a click event) while the share dialog is showing. - if (_this.$().has(e.target).length !== 0) { - return; - } - _this.get('controller').close(); + if (shareView.$().has(e.target).length !== 0) { return; } + shareView.get('controller').close(); return true; }); + $('html').on('click.discoure-share-link', '[data-share-url]', function(e) { - var $currentTarget, url; e.preventDefault(); - $currentTarget = $(e.currentTarget); - url = $currentTarget.data('share-url'); - /* Relative urls - */ + var $currentTarget = $(e.currentTarget); + var url = $currentTarget.data('share-url'); + // Relative urls if (url.indexOf("/") === 0) { url = window.location.protocol + "//" + window.location.host + url; } - _this.get('controller').shareLink(e, url); + shareView.get('controller').shareLink(e, url); return false; }); + $('html').on('keydown.share-view', function(e){ if (e.keyCode === 27) { - _this.get('controller').close(); + shareView.get('controller').close(); } }); }, diff --git a/app/assets/javascripts/discourse/views/user_selector_view.js b/app/assets/javascripts/discourse/views/user_selector_view.js index bc1609181..61ac73e9c 100644 --- a/app/assets/javascripts/discourse/views/user_selector_view.js +++ b/app/assets/javascripts/discourse/views/user_selector_view.js @@ -1,22 +1,21 @@ Discourse.UserSelector = Discourse.TextField.extend({ didInsertElement: function(){ - var _this = this; + var userSelectorView = this; var selected = []; var transformTemplate = Handlebars.compile("{{avatar this imageSize=\"tiny\"}} {{this.username}}"); - var template = Discourse.UserSelector.templateFunction(); $(this.get('element')).val(this.get('usernames')).autocomplete({ - template: template, + template: Discourse.UserSelector.templateFunction(), dataSource: function(term) { var exclude = selected; - if (_this.get('excludeCurrentUser')){ + if (userSelectorView.get('excludeCurrentUser')){ exclude = exclude.concat([Discourse.User.current('username')]); } return Discourse.UserSearch.search({ term: term, - topicId: _this.get('topicId'), + topicId: userSelectorView.get('topicId'), exclude: exclude }); }, @@ -29,7 +28,7 @@ Discourse.UserSelector = Discourse.TextField.extend({ return i; } }); - _this.set('usernames', items.join(",")); + userSelectorView.set('usernames', items.join(",")); selected = items; }, @@ -40,7 +39,6 @@ Discourse.UserSelector = Discourse.TextField.extend({ } }); - } });