Browse Source

replace $.Deferred() usage in the default theme with ES6 Promise

sisyphus
Dustin Falgout 8 years ago
parent
commit
f0f2d9ea83
  1. 18
      themes/default/js/greeter.js

18
themes/default/js/greeter.js vendored

@ -245,9 +245,10 @@ class BackgroundManager {
/**
* Determine which background image should be displayed and apply it.
*
* @param {jQuery.Deferred} deferred
* @return {Promise}
*/
initialize( deferred ) {
initialize() {
return new Promise( (resolve, reject) => {
if ( is_empty( _bg_self.current_background ) ) {
_bg_self.random_background = _config._set( 'true', 'background_manager', 'random_background' );
}
@ -256,23 +257,24 @@ class BackgroundManager {
_bg_self.current_background = _config._set( _bg_self.get_random_image(), 'background_manager', 'current_background' );
}
_bg_self.do_background( deferred );
return _bg_self.do_background( resolve );
});
}
/**
* Sets the background image to the value of {@link this.current_background}.
*
* @param {?jQuery.Deferred} deferred
* @param {?Promise.resolve} resolve
*/
do_background( deferred = null ) {
do_background( resolve = null ) {
let background = _bg_self.current_background,
tpl = background.startsWith( 'url(' ) ? background : `url(${background})`;
$( '.header' ).css( 'background-image', tpl );
if ( null !== deferred ) {
deferred.resolve();
if ( null !== resolve ) {
return resolve();
}
}
@ -385,7 +387,7 @@ class Theme {
this.background_manager = new BackgroundManager();
$.Deferred( this.background_manager.initialize ).then( () => this.initialize() );
this.background_manager.initialize().then( () => this.initialize() );
return _self;
}

Loading…
Cancel
Save