ES6: `grouped-each` helper and moved event dispatcher to an initializer

This commit is contained in:
Robin Ward 2014-08-13 16:46:41 -04:00
parent 5df04de1cc
commit ac89b3eb7e
8 changed files with 64 additions and 53 deletions

View File

@ -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'
}
});

View File

@ -108,8 +108,7 @@ DiscourseGroupedEach.prototype = {
} }
}; };
function groupedEachHelper(path, options) {
Ember.Handlebars.registerHelper('groupedEach', function(path, options) {
if (arguments.length === 4) { 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"); 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.hash.dataSourceBinding = path;
options.data.insideGroup = true; options.data.insideGroup = true;
new DiscourseGroupedEach(this, path, options).render(); 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);

View File

@ -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'
}
});
}
};

View File

@ -17,7 +17,7 @@
</thead> </thead>
<tbody> <tbody>
{{#groupedEach topic in topics}} {{#grouped-each topic in topics}}
<tr {{bind-attr class="archived"}}> <tr {{bind-attr class="archived"}}>
<td class='main-link'> <td class='main-link'>
{{topic-status topic=topic}} {{topic-status topic=topic}}
@ -69,7 +69,7 @@
<td class="activity"></td> <td class="activity"></td>
{{/if}} {{/if}}
</tr> </tr>
{{/groupedEach}} {{/grouped-each}}
</tbody> </tbody>
</table> </table>

View File

@ -1,11 +1,11 @@
<h3><i class='fa fa-envelope'></i> {{i18n private_message_info.title}}</h3> <h3><i class='fa fa-envelope'></i> {{i18n private_message_info.title}}</h3>
<div class='participants clearfix'> <div class='participants clearfix'>
{{#groupedEach details.allowed_groups}} {{#grouped-each details.allowed_groups}}
<div class='user group'> <div class='user group'>
#{{unbound name}} #{{unbound name}}
</div> </div>
{{/groupedEach}} {{/grouped-each}}
{{#groupedEach details.allowed_users}} {{#grouped-each details.allowed_users}}
<div class='user'> <div class='user'>
{{#link-to 'user' this}} {{#link-to 'user' this}}
{{avatar this imageSize="small"}} {{avatar this imageSize="small"}}
@ -17,7 +17,7 @@
<a class='remove-invited' {{action removeAllowedUser this}}><i class="fa fa-times"></i></a> <a class='remove-invited' {{action removeAllowedUser this}}><i class="fa fa-times"></i></a>
{{/if}} {{/if}}
</div> </div>
{{/groupedEach}} {{/grouped-each}}
</div> </div>
{{#if details.can_invite_to}} {{#if details.can_invite_to}}
<div class='controls'> <div class='controls'>

View File

@ -45,21 +45,21 @@
</li> </li>
{{/if}} {{/if}}
<li {{bind-attr class=":avatars mapCollapsed::hidden"}}> <li {{bind-attr class=":avatars mapCollapsed::hidden"}}>
{{#groupedEach participant in details.fewParticipants}}{{topic-participant participant=participant}}{{/groupedEach}} {{#grouped-each participant in details.fewParticipants}}{{topic-participant participant=participant}}{{/grouped-each}}
</li> </li>
</ul> </ul>
</section> </section>
{{#unless mapCollapsed}} {{#unless mapCollapsed}}
<section class='avatars clearfix'> <section class='avatars clearfix'>
{{#groupedEach participant in details.participants}}{{topic-participant participant=participant}}{{/groupedEach}} {{#grouped-each participant in details.participants}}{{topic-participant participant=participant}}{{/grouped-each}}
</section> </section>
{{#if infoLinks}} {{#if infoLinks}}
<section class='links'> <section class='links'>
<table class='topic-links'> <table class='topic-links'>
{{#groupedEach infoLinks}} {{#grouped-each infoLinks}}
<tr> <tr>
<td> <td>
<span class='badge badge-notification clicks' title='{{i18n topic_map.clicks count=clicks}}'>{{clicks}}</span> <span class='badge badge-notification clicks' title='{{i18n topic_map.clicks count=clicks}}'>{{clicks}}</span>
@ -71,7 +71,7 @@
{{link-domain this}} {{link-domain this}}
</td> </td>
</tr> </tr>
{{/groupedEach}} {{/grouped-each}}
</table> </table>
{{#if showAllLinksControls}} {{#if showAllLinksControls}}

View File

@ -1,7 +1,7 @@
{{#if loaded}} {{#if loaded}}
{{#if topics}} {{#if topics}}
<table class="topic-list"> <table class="topic-list">
{{#groupedEach topic in topics}} {{#grouped-each topic in topics}}
<tr {{bind-attr class="archived"}}> <tr {{bind-attr class="archived"}}>
<td> <td>
<div class='main-link clearfix'> <div class='main-link clearfix'>
@ -59,7 +59,7 @@
</div> </div>
</td> </td>
</tr> </tr>
{{/groupedEach}} {{/grouped-each}}
</table> </table>
{{else}} {{else}}
<div class='alert alert-info'> <div class='alert alert-info'>

View File

@ -1,4 +1,4 @@
{{#groupedEach model.content}} {{#grouped-each model.content}}
<div {{bind-attr class=":item hidden deleted moderator_action"}}> <div {{bind-attr class=":item hidden deleted moderator_action"}}>
<div class='clearfix info'> <div class='clearfix info'>
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a> <a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
@ -10,10 +10,10 @@
<span class="type">{{unbound descriptionHtml}}</span> <span class="type">{{unbound descriptionHtml}}</span>
</div> </div>
<p class='excerpt'>{{{unbound excerpt}}}</p> <p class='excerpt'>{{{unbound excerpt}}}</p>
{{#groupedEach children}} {{#grouped-each children}}
<div class='child-actions'> <div class='child-actions'>
<i class="icon {{unbound icon}}"></i> <i class="icon {{unbound icon}}"></i>
{{#groupedEach items}} {{#grouped-each items}}
{{#if bookmarkType}} {{#if bookmarkType}}
<button class="btn btn-default remove-bookmark" {{action removeBookmark this}}> <button class="btn btn-default remove-bookmark" {{action removeBookmark this}}>
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
@ -22,11 +22,11 @@
{{/if}} {{/if}}
<a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a> <a href="{{unbound userUrl}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="tiny" extraClasses="actor" ignoreTitle="true"}}</div></a>
{{#if edit_reason}} &mdash; <span class="edit-reason">{{unbound edit_reason}}</span>{{/if}} {{#if edit_reason}} &mdash; <span class="edit-reason">{{unbound edit_reason}}</span>{{/if}}
{{/groupedEach}} {{/grouped-each}}
</div> </div>
{{/groupedEach}} {{/grouped-each}}
</div> </div>
{{/groupedEach}} {{/grouped-each}}
{{#if loading}} {{#if loading}}
<div class='spinner'>{{i18n loading}}</div> <div class='spinner'>{{i18n loading}}</div>
{{/if}} {{/if}}