salix/front/core/components/spinner/spinner.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../../module';
import Component from '../../lib/component';
2019-10-18 19:36:30 +00:00
import './style.scss';
2017-02-21 10:36:43 +00:00
/**
* A spinner to inform the user about loading process.
*/
export default class Spinner extends Component {
constructor($element, $scope) {
2019-10-18 19:36:30 +00:00
super($element, $scope);
2017-02-21 10:36:43 +00:00
this._enable = false;
this.spinner = $element[0].firstChild;
}
/**
2019-10-18 19:36:30 +00:00
* Activates/deactivates the spinner.
2017-05-17 19:23:47 +00:00
*
* @param {Boolean} value %true to enable, %false to disable
2017-02-21 10:36:43 +00:00
*/
set enable(value) {
if (value)
this.start();
else
this.stop();
}
/**
* Returns the current spinner state.
2017-05-17 19:23:47 +00:00
*
2017-02-21 10:36:43 +00:00
* @return {Boolean} %true if it's enabled, %false otherwise
*/
get enable() {
return this._enable;
}
/**
* Activates the spinner.
*/
start() {
2019-10-18 19:36:30 +00:00
this.spinner.style.display = 'block';
2017-02-21 10:36:43 +00:00
this._enable = true;
}
/**
* Deactivates the spinner.
*/
stop() {
2019-10-18 19:36:30 +00:00
this.spinner.style.display = 'none';
2017-02-21 10:36:43 +00:00
this._enable = false;
}
}
Spinner.$inject = ['$element', '$scope'];
export const component = {
2017-05-31 08:28:39 +00:00
template: require('./spinner.html'),
2017-02-21 10:36:43 +00:00
bindings: {
enable: '='
},
controller: Spinner
};
2018-02-10 15:18:01 +00:00
ngModule.component('vnSpinner', component);