mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
58 lines
1.6 KiB
JavaScript
58 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() {
|
|
run.cancel(this.get('showSpinnerTimeout'));
|
|
}
|
|
});
|