mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
Merge pull request #5742 from kevinansfield/spin-button-minimum-timeout
Set a minimum spin time of 1 second for gh-spin-button
This commit is contained in:
commit
dd8da3bad7
@ -5,13 +5,14 @@ export default Ember.Component.extend({
|
|||||||
buttonText: '',
|
buttonText: '',
|
||||||
submitting: false,
|
submitting: false,
|
||||||
showSpinner: false,
|
showSpinner: false,
|
||||||
|
showSpinnerTimeout: null,
|
||||||
autoWidth: true,
|
autoWidth: true,
|
||||||
|
|
||||||
// Disable Button when isLoading equals true
|
// Disable Button when isLoading equals true
|
||||||
attributeBindings: ['disabled', 'type', 'tabindex'],
|
attributeBindings: ['disabled', 'type', 'tabindex'],
|
||||||
|
|
||||||
// Must be set on the controller
|
// Must be set on the controller
|
||||||
disabled: Ember.computed.equal('submitting', true),
|
disabled: Ember.computed.equal('showSpinner', true),
|
||||||
|
|
||||||
click: function () {
|
click: function () {
|
||||||
if (this.get('action')) {
|
if (this.get('action')) {
|
||||||
@ -21,14 +22,34 @@ export default Ember.Component.extend({
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
setSize: Ember.observer('submitting', function () {
|
toggleSpinner: Ember.observer('submitting', function () {
|
||||||
if (this.get('submitting') && this.get('autoWidth')) {
|
var submitting = this.get('submitting'),
|
||||||
|
timeout = this.get('showSpinnerTimeout');
|
||||||
|
|
||||||
|
if (submitting) {
|
||||||
|
this.set('showSpinner', true);
|
||||||
|
this.set('showSpinnerTimeout', Ember.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: Ember.observer('showSpinner', function () {
|
||||||
|
if (this.get('showSpinner') && this.get('autoWidth')) {
|
||||||
this.$().width(this.$().width());
|
this.$().width(this.$().width());
|
||||||
this.$().height(this.$().height());
|
this.$().height(this.$().height());
|
||||||
} else {
|
} else {
|
||||||
this.$().width('');
|
this.$().width('');
|
||||||
this.$().height('');
|
this.$().height('');
|
||||||
}
|
}
|
||||||
this.set('showSpinner', this.get('submitting'));
|
}),
|
||||||
})
|
|
||||||
|
willDestroy: function () {
|
||||||
|
Ember.run.cancel(this.get('showSpinnerTimeout'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user