mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
e01ffa3620
no issue - review use of Ember core hooks and add a call to `this._super` if missing - fix a few occurrences of using the wrong component lifecycle hooks that could result in multiple/duplicate event handlers being attached `_super` should always be called when overriding Ember's base hooks so that core functionality or app functionality added through extensions, mixins or addons is not lost. This is important as it guards against issues arising from later refactorings or core changes. As example of lost functionality, there were a number of routes that extended from `AuthenticatedRoute` but then overrode the `beforeModel` hook without calling `_super` which meant that the route was no longer treated as authenticated.
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
const {Component, computed, observer, run} = Ember;
|
|
const {equal} = computed;
|
|
|
|
export default Component.extend({
|
|
tagName: 'button',
|
|
buttonText: '',
|
|
submitting: false,
|
|
showSpinner: false,
|
|
showSpinnerTimeout: null,
|
|
autoWidth: true,
|
|
|
|
// Disable Button when isLoading equals true
|
|
attributeBindings: ['disabled', 'type', 'tabindex'],
|
|
|
|
// Must be set on the controller
|
|
disabled: equal('showSpinner', true),
|
|
|
|
click() {
|
|
if (this.get('action')) {
|
|
this.sendAction('action');
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
toggleSpinner: observer('submitting', function () {
|
|
let submitting = this.get('submitting');
|
|
let timeout = this.get('showSpinnerTimeout');
|
|
|
|
if (submitting) {
|
|
this.set('showSpinner', true);
|
|
this.set('showSpinnerTimeout', run.later(this, function () {
|
|
if (!this.get('submitting')) {
|
|
this.set('showSpinner', false);
|
|
}
|
|
this.set('showSpinnerTimeout', null);
|
|
}, 1000));
|
|
} else if (!submitting && timeout === null) {
|
|
this.set('showSpinner', false);
|
|
}
|
|
}),
|
|
|
|
setSize: observer('showSpinner', function () {
|
|
if (this.get('showSpinner') && this.get('autoWidth')) {
|
|
this.$().width(this.$().width());
|
|
this.$().height(this.$().height());
|
|
} else {
|
|
this.$().width('');
|
|
this.$().height('');
|
|
}
|
|
}),
|
|
|
|
willDestroy() {
|
|
this._super(...arguments);
|
|
run.cancel(this.get('showSpinnerTimeout'));
|
|
}
|
|
});
|