2019-02-06 01:06:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor progress bar widget
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2019-02-06 01:06:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
mw.libs.ve = mw.libs.ve || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Progress bar widget
|
|
|
|
*
|
|
|
|
* This widget can be used to show a progress bar
|
|
|
|
* while VE libraries are still loading.
|
|
|
|
*
|
|
|
|
* It has a similar API to OO.ui.ProgressBarWidget, but is designed to
|
|
|
|
* be loaded before any core VE code or dependencies, e.g. OOUI.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
mw.libs.ve.ProgressBarWidget = function VeUiMwProgressBarWidget() {
|
|
|
|
this.progressStep = 0;
|
|
|
|
this.progressSteps = [
|
|
|
|
// [ percentage, delay ]
|
|
|
|
[ 30, 3000 ],
|
|
|
|
[ 70, 2000 ],
|
|
|
|
[ 100, 1000 ]
|
|
|
|
];
|
|
|
|
// Stylesheets might not have processed yet, so manually set starting width to 0
|
|
|
|
this.$bar = $( '<div>' ).addClass( 've-init-mw-progressBarWidget-bar' ).css( 'width', 0 );
|
|
|
|
this.$element = $( '<div>' ).addClass( 've-init-mw-progressBarWidget' ).append( this.$bar );
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.libs.ve.ProgressBarWidget.prototype.setLoadingProgress = function ( target, duration ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const $bar = this.$bar.stop();
|
2019-02-06 01:06:10 +00:00
|
|
|
$bar.css( 'transition', 'width ' + duration + 'ms ease-in' );
|
2024-04-30 16:44:25 +00:00
|
|
|
setTimeout( () => {
|
2019-02-06 01:06:10 +00:00
|
|
|
$bar.css( 'width', target + '%' );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.libs.ve.ProgressBarWidget.prototype.incrementLoadingProgress = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const step = this.progressSteps[ this.progressStep ];
|
2019-02-06 01:06:10 +00:00
|
|
|
if ( step ) {
|
|
|
|
this.setLoadingProgress( step[ 0 ], step[ 1 ] );
|
|
|
|
this.progressStep++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.libs.ve.ProgressBarWidget.prototype.clearLoading = function () {
|
|
|
|
this.progressStep = 0;
|
|
|
|
this.setLoadingProgress( 0, 0 );
|
|
|
|
};
|