| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
function ResizingDragBar( config ) { |
| 9 |
config = Object.assign( {}, { |
| 10 |
isEW: true, |
| 11 |
classes: [ 'ext-WikiEditor-ResizingDragBar' ] |
| 12 |
}, config ); |
| 13 |
ResizingDragBar.super.call( this, config ); |
| 14 |
|
| 15 |
var classNameDir = 'ext-WikiEditor-ResizingDragBar-' + ( config.isEW ? 'ew' : 'ns' ); |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
this.$element.addClass( classNameDir ); |
| 20 |
|
| 21 |
var resizingDragBar = this; |
| 22 |
|
| 23 |
var rtlFactor = config.isEW && OO.ui.Element.static.getDir( document ) === 'rtl' ? -1 : 1; |
| 24 |
this.$element.on( 'mousedown', function ( eventMousedown ) { |
| 25 |
if ( eventMousedown.button !== ResizingDragBar.static.MAIN_MOUSE_BUTTON ) { |
| 26 |
|
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$( document ).on( 'selectstart.' + classNameDir, false ); |
| 31 |
|
| 32 |
var xOrY = config.isEW ? 'pageX' : 'pageY'; |
| 33 |
var widthOrHeight = config.isEW ? 'width' : 'height'; |
| 34 |
var lastOffset = eventMousedown[ xOrY ]; |
| 35 |
|
| 36 |
$( document ).on( 'mousemove.' + classNameDir, function ( eventMousemove ) { |
| 37 |
|
| 38 |
var startSize = resizingDragBar.getResizedPane()[ widthOrHeight ](); |
| 39 |
|
| 40 |
var newOffset = eventMousemove[ xOrY ]; |
| 41 |
|
| 42 |
var change = rtlFactor * ( lastOffset - newOffset ); |
| 43 |
|
| 44 |
var newSize = Math.max( startSize - change, ResizingDragBar.static.MIN_PANE_SIZE ); |
| 45 |
resizingDragBar.getResizedPane().css( widthOrHeight, newSize ); |
| 46 |
|
| 47 |
lastOffset = newOffset; |
| 48 |
|
| 49 |
mw.hook( 'ext.WikiEditor.realtimepreview.resize' ).fire( resizingDragBar ); |
| 50 |
} ); |
| 51 |
} ); |
| 52 |
|
| 53 |
this.$element.append( $( '<span>' ) ); |
| 54 |
|
| 55 |
$( document ).on( 'mouseup', function () { |
| 56 |
$( document ).off( 'mousemove.' + classNameDir ); |
| 57 |
$( document ).off( 'selectstart.' + classNameDir, false ); |
| 58 |
} ); |
| 59 |
} |
| 60 |
|
| 61 |
OO.inheritClass( ResizingDragBar, OO.ui.Element ); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
ResizingDragBar.static.MAIN_MOUSE_BUTTON = 0; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
ResizingDragBar.static.MIN_PANE_SIZE = 248; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ResizingDragBar.prototype.getResizedPane = function () { |
| 84 |
return this.$element.prev(); |
| 85 |
}; |
| 86 |
|
| 87 |
module.exports = ResizingDragBar; |