From ac89b3eb7e4f3078df8120ca96557c979450739c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 13 Aug 2014 16:46:41 -0400 Subject: [PATCH] ES6: `grouped-each` helper and moved event dispatcher to an initializer --- .../discourse/ember/event_dispatcher.js | 33 ---------------- .../{grouped_each.js => grouped-each.js.es6} | 10 ++++- .../initializers/ember-events.js.es6 | 38 +++++++++++++++++++ .../components/basic-topic-list.js.handlebars | 4 +- .../private-message-map.js.handlebars | 8 ++-- .../components/topic-map.js.handlebars | 8 ++-- .../components/basic-topic-list.js.handlebars | 4 +- .../templates/user/stream.js.handlebars | 12 +++--- 8 files changed, 64 insertions(+), 53 deletions(-) delete mode 100644 app/assets/javascripts/discourse/ember/event_dispatcher.js rename app/assets/javascripts/discourse/helpers/{grouped_each.js => grouped-each.js.es6} (91%) create mode 100644 app/assets/javascripts/discourse/initializers/ember-events.js.es6 diff --git a/app/assets/javascripts/discourse/ember/event_dispatcher.js b/app/assets/javascripts/discourse/ember/event_dispatcher.js deleted file mode 100644 index 7e5cea6fc71..00000000000 --- a/app/assets/javascripts/discourse/ember/event_dispatcher.js +++ /dev/null @@ -1,33 +0,0 @@ -/* - Discourse is not interested in watching `mouseMove` or `touchMove` events on an Ember views, - so we remove them from the events the EventDispatcher watches for. -*/ -Ember.EventDispatcher.reopen({ - events: { - touchstart : 'touchStart', - touchend : 'touchEnd', - touchcancel : 'touchCancel', - keydown : 'keyDown', - keyup : 'keyUp', - keypress : 'keyPress', - mousedown : 'mouseDown', - mouseup : 'mouseUp', - contextmenu : 'contextMenu', - click : 'click', - dblclick : 'doubleClick', - focusin : 'focusIn', - focusout : 'focusOut', - mouseenter : 'mouseEnter', - mouseleave : 'mouseLeave', - submit : 'submit', - input : 'input', - change : 'change', - dragstart : 'dragStart', - drag : 'drag', - dragenter : 'dragEnter', - dragleave : 'dragLeave', - dragover : 'dragOver', - drop : 'drop', - dragend : 'dragEnd' - } -}); diff --git a/app/assets/javascripts/discourse/helpers/grouped_each.js b/app/assets/javascripts/discourse/helpers/grouped-each.js.es6 similarity index 91% rename from app/assets/javascripts/discourse/helpers/grouped_each.js rename to app/assets/javascripts/discourse/helpers/grouped-each.js.es6 index d730ede8f43..b8d80ff400a 100644 --- a/app/assets/javascripts/discourse/helpers/grouped_each.js +++ b/app/assets/javascripts/discourse/helpers/grouped-each.js.es6 @@ -108,8 +108,7 @@ DiscourseGroupedEach.prototype = { } }; - -Ember.Handlebars.registerHelper('groupedEach', function(path, options) { +function groupedEachHelper(path, options) { if (arguments.length === 4) { Ember.assert("If you pass more than one argument to the groupedEach helper, it must be in the form #groupedEach foo in bar", arguments[1] === "in"); @@ -130,4 +129,11 @@ Ember.Handlebars.registerHelper('groupedEach', function(path, options) { options.hash.dataSourceBinding = path; options.data.insideGroup = true; new DiscourseGroupedEach(this, path, options).render(); +} + +Ember.Handlebars.registerHelper('groupedEach', function() { + Em.warn("The `groupedEach` helper is deprecated. Use `grouped-each` instead."); + return groupedEachHelper.apply(this, Array.prototype.slice.apply(arguments)); }); + +Ember.Handlebars.registerHelper('grouped-each', groupedEachHelper); diff --git a/app/assets/javascripts/discourse/initializers/ember-events.js.es6 b/app/assets/javascripts/discourse/initializers/ember-events.js.es6 new file mode 100644 index 00000000000..32302a2133d --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/ember-events.js.es6 @@ -0,0 +1,38 @@ +export default { + name: "ember-events", + + initialize: function () { + + // By default Ember listens to too many events. This tells it the only events + // we're interested in. + Ember.EventDispatcher.reopen({ + events: { + touchstart : 'touchStart', + touchend : 'touchEnd', + touchcancel : 'touchCancel', + keydown : 'keyDown', + keyup : 'keyUp', + keypress : 'keyPress', + mousedown : 'mouseDown', + mouseup : 'mouseUp', + contextmenu : 'contextMenu', + click : 'click', + dblclick : 'doubleClick', + focusin : 'focusIn', + focusout : 'focusOut', + mouseenter : 'mouseEnter', + mouseleave : 'mouseLeave', + submit : 'submit', + input : 'input', + change : 'change', + dragstart : 'dragStart', + drag : 'drag', + dragenter : 'dragEnter', + dragleave : 'dragLeave', + dragover : 'dragOver', + drop : 'drop', + dragend : 'dragEnd' + } + }); + } +}; diff --git a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars index c002ab2bb2f..1ac50166b70 100644 --- a/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/basic-topic-list.js.handlebars @@ -17,7 +17,7 @@ - {{#groupedEach topic in topics}} + {{#grouped-each topic in topics}} {{topic-status topic=topic}} @@ -69,7 +69,7 @@ {{/if}} - {{/groupedEach}} + {{/grouped-each}} diff --git a/app/assets/javascripts/discourse/templates/components/private-message-map.js.handlebars b/app/assets/javascripts/discourse/templates/components/private-message-map.js.handlebars index 03d3dab1f22..f238ba7b080 100644 --- a/app/assets/javascripts/discourse/templates/components/private-message-map.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/private-message-map.js.handlebars @@ -1,11 +1,11 @@

{{i18n private_message_info.title}}

- {{#groupedEach details.allowed_groups}} + {{#grouped-each details.allowed_groups}}
#{{unbound name}}
- {{/groupedEach}} - {{#groupedEach details.allowed_users}} + {{/grouped-each}} + {{#grouped-each details.allowed_users}}
{{#link-to 'user' this}} {{avatar this imageSize="small"}} @@ -17,7 +17,7 @@ {{/if}}
- {{/groupedEach}} + {{/grouped-each}}
{{#if details.can_invite_to}}
diff --git a/app/assets/javascripts/discourse/templates/components/topic-map.js.handlebars b/app/assets/javascripts/discourse/templates/components/topic-map.js.handlebars index 0408299ffdb..54be67b17be 100644 --- a/app/assets/javascripts/discourse/templates/components/topic-map.js.handlebars +++ b/app/assets/javascripts/discourse/templates/components/topic-map.js.handlebars @@ -45,21 +45,21 @@ {{/if}}
  • - {{#groupedEach participant in details.fewParticipants}}{{topic-participant participant=participant}}{{/groupedEach}} + {{#grouped-each participant in details.fewParticipants}}{{topic-participant participant=participant}}{{/grouped-each}}
  • {{#unless mapCollapsed}}
    - {{#groupedEach participant in details.participants}}{{topic-participant participant=participant}}{{/groupedEach}} + {{#grouped-each participant in details.participants}}{{topic-participant participant=participant}}{{/grouped-each}}
    {{#if infoLinks}}