| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.WhitespacePreservingTextInputWidget = function VeUiWhitespacePreservingTextInputWidget( config ) { |
| 19 |
|
| 20 |
config = config || {}; |
| 21 |
|
| 22 |
|
| 23 |
ve.ui.WhitespacePreservingTextInputWidget.super.call( this, config ); |
| 24 |
|
| 25 |
this.limit = config.limit; |
| 26 |
|
| 27 |
this.setWhitespace( [ '', '' ] ); |
| 28 |
this.setValueAndWhitespace( config.valueAndWhitespace || '' ); |
| 29 |
|
| 30 |
this.$element.addClass( 've-ui-whitespacePreservingTextInputWidget' ); |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
OO.inheritClass( ve.ui.WhitespacePreservingTextInputWidget, OO.ui.MultilineTextInputWidget ); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
ve.ui.WhitespacePreservingTextInputWidget.prototype.setValueAndWhitespace = function ( value ) { |
| 45 |
const leftValue = this.limit ? value.slice( 0, this.limit ) : value; |
| 46 |
this.whitespace[ 0 ] = leftValue.match( /^\s*/ )[ 0 ]; |
| 47 |
value = value.slice( this.whitespace[ 0 ].length ); |
| 48 |
|
| 49 |
const rightValue = this.limit ? value.slice( -this.limit ) : value; |
| 50 |
this.whitespace[ 1 ] = rightValue.match( /\s*$/ )[ 0 ]; |
| 51 |
value = value.slice( 0, value.length - this.whitespace[ 1 ].length ); |
| 52 |
|
| 53 |
this.setValue( value ); |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ui.WhitespacePreservingTextInputWidget.prototype.setWhitespace = function ( whitespace ) { |
| 62 |
this.whitespace = whitespace; |
| 63 |
}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
ve.ui.WhitespacePreservingTextInputWidget.prototype.getValueAndWhitespace = function () { |
| 71 |
if ( !this.whitespace ) { |
| 72 |
|
| 73 |
return this.value; |
| 74 |
} |
| 75 |
return this.whitespace[ 0 ] + this.value + this.whitespace[ 1 ]; |
| 76 |
}; |