diff options
Diffstat (limited to 'vendor/oojs/oojs-ui/src/elements/PendingElement.js')
-rw-r--r-- | vendor/oojs/oojs-ui/src/elements/PendingElement.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/vendor/oojs/oojs-ui/src/elements/PendingElement.js b/vendor/oojs/oojs-ui/src/elements/PendingElement.js new file mode 100644 index 00000000..c5f71d54 --- /dev/null +++ b/vendor/oojs/oojs-ui/src/elements/PendingElement.js @@ -0,0 +1,84 @@ +/** + * Element that can be marked as pending. + * + * @abstract + * @class + * + * @constructor + * @param {Object} [config] Configuration options + * @cfg {jQuery} [$pending] Element to mark as pending, defaults to this.$element + */ +OO.ui.PendingElement = function OoUiPendingElement( config ) { + // Configuration initialization + config = config || {}; + + // Properties + this.pending = 0; + this.$pending = null; + + // Initialisation + this.setPendingElement( config.$pending || this.$element ); +}; + +/* Setup */ + +OO.initClass( OO.ui.PendingElement ); + +/* Methods */ + +/** + * Set the pending element (and clean up any existing one). + * + * @param {jQuery} $pending The element to set to pending. + */ +OO.ui.PendingElement.prototype.setPendingElement = function ( $pending ) { + if ( this.$pending ) { + this.$pending.removeClass( 'oo-ui-pendingElement-pending' ); + } + + this.$pending = $pending; + if ( this.pending > 0 ) { + this.$pending.addClass( 'oo-ui-pendingElement-pending' ); + } +}; + +/** + * Check if input is pending. + * + * @return {boolean} + */ +OO.ui.PendingElement.prototype.isPending = function () { + return !!this.pending; +}; + +/** + * Increase the pending stack. + * + * @chainable + */ +OO.ui.PendingElement.prototype.pushPending = function () { + if ( this.pending === 0 ) { + this.$pending.addClass( 'oo-ui-pendingElement-pending' ); + this.updateThemeClasses(); + } + this.pending++; + + return this; +}; + +/** + * Reduce the pending stack. + * + * Clamped at zero. + * + * @chainable + */ +OO.ui.PendingElement.prototype.popPending = function () { + if ( this.pending === 1 ) { + this.$pending.removeClass( 'oo-ui-pendingElement-pending' ); + this.updateThemeClasses(); + } + this.pending = Math.max( 0, this.pending - 1 ); + + return this; +}; |