import Ember from 'ember';

export default Ember.Component.extend({
    tagName: 'section',
    classNames: ['gh-view', 'content-view-container'],

    previewIsHidden: false,

    resizeService: Ember.inject.service(),

    calculatePreviewIsHidden: function () {
        if (this.$('.content-preview').length) {
            this.set('previewIsHidden', !this.$('.content-preview').is(':visible'));
        }
    },

    didInsertElement: function () {
        this._super(...arguments);
        this.calculatePreviewIsHidden();
        this.get('resizeService').on('debouncedDidResize',
            Ember.run.bind(this, this.calculatePreviewIsHidden));
    }
});

import Ember from 'ember';

export default Ember.Component.extend({
    tagName: 'section',
    classNames: ['gh-view', 'content-view-container'],

    previewIsHidden: false,

    resizeService: Ember.inject.service(),

    _resizeListener: null,

    calculatePreviewIsHidden: function () {
        if (this.$('.content-preview').length) {
            this.set('previewIsHidden', !this.$('.content-preview').is(':visible'));
        }
    },

    didInsertElement: function () {
        this._super(...arguments);
        this._resizeListener = Ember.run.bind(this, this.calculatePreviewIsHidden);
        this.get('resizeService').on('debouncedDidResize', this._resizeListener);
        this.calculatePreviewIsHidden();
    },

    willDestroy: function () {
        this.get('resizeService').off('debouncedDidResize', this._resizeListener);
    }
});

Fix teardown of resize handler in content management screen
Fix teardown of resize handler in content management screen

refs #5659 ([comment](https://github.com/TryGhost/Ghost/issues/5659#issuecomment-137114898))
- cleans up resize handler on willDestroy hook of gh-content-view-container
