mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
ea3bf21a84
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
33 lines
838 B
JavaScript
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);
|
|
});
|
|
}
|
|
|
|
});
|