2015-08-17 17:00:26 -07:00
/ * *
2018-11-23 12:29:20 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2015-08-17 17:00:26 -07:00
( function ( $ , Drupal ) {
Drupal . theme . progressBar = function ( id ) {
2018-11-23 12:29:20 +00:00
return '<div id="' + id + '" class="progress" aria-live="polite">' + '<div class="progress__label"> </div>' + '<div class="progress__track"><div class="progress__bar"></div></div>' + '<div class="progress__percentage"></div>' + '<div class="progress__description"> </div>' + '</div>' ;
2015-08-17 17:00:26 -07:00
} ;
Drupal . ProgressBar = function ( id , updateCallback , method , errorCallback ) {
this . id = id ;
this . method = method || 'GET' ;
this . updateCallback = updateCallback ;
this . errorCallback = errorCallback ;
this . element = $ ( Drupal . theme ( 'progressBar' , id ) ) ;
} ;
2018-11-23 12:29:20 +00:00
$ . extend ( Drupal . ProgressBar . prototype , {
setProgress : function setProgress ( percentage , message , label ) {
2015-08-17 17:00:26 -07:00
if ( percentage >= 0 && percentage <= 100 ) {
$ ( this . element ) . find ( 'div.progress__bar' ) . css ( 'width' , percentage + '%' ) ;
$ ( this . element ) . find ( 'div.progress__percentage' ) . html ( percentage + '%' ) ;
}
$ ( 'div.progress__description' , this . element ) . html ( message ) ;
$ ( 'div.progress__label' , this . element ) . html ( label ) ;
if ( this . updateCallback ) {
this . updateCallback ( percentage , message , this ) ;
}
} ,
2018-11-23 12:29:20 +00:00
startMonitoring : function startMonitoring ( uri , delay ) {
2015-08-17 17:00:26 -07:00
this . delay = delay ;
this . uri = uri ;
this . sendPing ( ) ;
} ,
2018-11-23 12:29:20 +00:00
stopMonitoring : function stopMonitoring ( ) {
2015-08-17 17:00:26 -07:00
clearTimeout ( this . timer ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
this . uri = null ;
} ,
2018-11-23 12:29:20 +00:00
sendPing : function sendPing ( ) {
2015-08-17 17:00:26 -07:00
if ( this . timer ) {
clearTimeout ( this . timer ) ;
}
if ( this . uri ) {
var pb = this ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
var uri = this . uri ;
if ( uri . indexOf ( '?' ) === - 1 ) {
uri += '?' ;
2018-11-23 12:29:20 +00:00
} else {
2015-08-17 17:00:26 -07:00
uri += '&' ;
}
uri += '_format=json' ;
$ . ajax ( {
type : this . method ,
url : uri ,
data : '' ,
2015-11-17 13:42:33 -08:00
dataType : 'json' ,
2018-11-23 12:29:20 +00:00
success : function success ( progress ) {
2015-08-17 17:00:26 -07:00
if ( progress . status === 0 ) {
pb . displayError ( progress . data ) ;
return ;
}
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
pb . setProgress ( progress . percentage , progress . message , progress . label ) ;
2018-11-23 12:29:20 +00:00
pb . timer = setTimeout ( function ( ) {
pb . sendPing ( ) ;
} , pb . delay ) ;
2015-08-17 17:00:26 -07:00
} ,
2018-11-23 12:29:20 +00:00
error : function error ( xmlhttp ) {
2015-08-17 17:00:26 -07:00
var e = new Drupal . AjaxError ( xmlhttp , pb . uri ) ;
pb . displayError ( '<pre>' + e . message + '</pre>' ) ;
}
} ) ;
}
} ,
2018-11-23 12:29:20 +00:00
displayError : function displayError ( string ) {
2015-08-17 17:00:26 -07:00
var error = $ ( '<div class="messages messages--error"></div>' ) . html ( string ) ;
$ ( this . element ) . before ( error ) . hide ( ) ;
if ( this . errorCallback ) {
this . errorCallback ( this ) ;
}
}
} ) ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Drupal ) ;