Ghost/ghost/admin/app/mixins/active-link-wrapper.js
Kevin Ansfield ea3bf21a84 Fix posts navigation slowdown when lots of posts are loaded
refs #6274
- adds `active-link-wrapper` mixin that tracks the `active` state of child links and adds/removes a `.active` class on the mixed-in element
- removes the passed-in `active` attribute on `gh-posts-list-item` component that forced every item in the content list to be re-rendered each time the currently selected post changed
2016-01-04 16:55:36 +00:00

33 lines
838 B
JavaScript

// logic borrowed from https://github.com/alexspeller/ember-cli-active-link-wrapper/blob/master/addon/components/active-link.js
import Ember from 'ember';
const {computed, run} = Ember;
const emberA = Ember.A;
export default Ember.Mixin.create({
classNameBindings: ['active'],
childLinkViews: [],
active: computed('childLinkViews.@each.active', function () {
return emberA(this.get('childLinkViews')).isAny('active');
}),
didRender() {
this._super(...arguments);
run.schedule('afterRender', this, function () {
let childLinkElements = this.$('a.ember-view');
let childLinkViews = childLinkElements.toArray().map((view) =>
this._viewRegistry[view.id]
);
this.set('childLinkViews', childLinkViews);
});
}
});