Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/preinit/ve.init.mw.ProgressBarWidget.js

raw symbols SCIP
1 /*!
2 * VisualEditor progress bar widget
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 mw.libs.ve = mw.libs.ve || {};
9
10 /**
11 * Progress bar widget
12 *
13 * This widget can be used to show a progress bar
14 * while VE libraries are still loading.
15 *
16 * It has a similar API to OO.ui.ProgressBarWidget, but is designed to
17 * be loaded before any core VE code or dependencies, e.g. OOUI.
18 *
19 * @class
20 * @constructor
21 */
22 mw.libs.ve.ProgressBarWidget = function VeUiMwProgressBarWidget() {
23 this.progressStep = 0;
24 this.progressSteps = [
25 // [ percentage, delay ]
26 [ 30, 3000 ],
27 [ 70, 2000 ],
28 [ 100, 1000 ]
29 ];
30 // Stylesheets might not have processed yet, so manually set starting width to 0
31 this.$bar = $( '<div>' ).addClass( 've-init-mw-progressBarWidget-bar' ).css( 'width', 0 );
32 this.$element = $( '<div>' ).addClass( 've-init-mw-progressBarWidget' ).append( this.$bar );
33 };
34
35 mw.libs.ve.ProgressBarWidget.prototype.setLoadingProgress = function ( target, duration ) {
36 const $bar = this.$bar.stop();
37 $bar.css( 'transition', 'width ' + duration + 'ms ease-in' );
38 setTimeout( () => {
39 $bar.css( 'width', target + '%' );
40 } );
41 };
42
43 mw.libs.ve.ProgressBarWidget.prototype.incrementLoadingProgress = function () {
44 const step = this.progressSteps[ this.progressStep ];
45 if ( step ) {
46 this.setLoadingProgress( step[ 0 ], step[ 1 ] );
47 this.progressStep++;
48 }
49 };
50
51 mw.libs.ve.ProgressBarWidget.prototype.clearLoading = function () {
52 this.progressStep = 0;
53 this.setLoadingProgress( 0, 0 );
54 };