| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
ve.ui.MWWikitextSurface = function VeUiMWWikitextSurface() { |
| 17 |
|
| 18 |
ve.ui.MWWikitextSurface.super.apply( this, arguments ); |
| 19 |
|
| 20 |
|
| 21 |
this.$element.addClass( 've-ui-mwWikitextSurface' ); |
| 22 |
|
| 23 |
this.getView().$element.add( this.$placeholder ) |
| 24 |
.removeClass( 've-ui-surface-source-font' ) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
.addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) ); |
| 30 |
|
| 31 |
|
| 32 |
this.$textbox = $( '#wpTextbox1' ); |
| 33 |
if ( !this.$textbox.length ) { |
| 34 |
this.$textbox = $( '<textarea>' ) |
| 35 |
.attr( 'id', 'wpTextbox1' ) |
| 36 |
.addClass( 've-dummyTextbox' ); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
this.$element.append( |
| 41 |
$( '<div>' ) |
| 42 |
.addClass( 've-dummyTextbox-wrapper oo-ui-element-hidden' ) |
| 43 |
.append( this.$textbox ) |
| 44 |
); |
| 45 |
} else { |
| 46 |
|
| 47 |
this.$textbox.textSelection( 'unregister' ); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
const surface = this; |
| 55 |
|
| 56 |
this.$textbox.textSelection( 'register', { |
| 57 |
getContents: function () { |
| 58 |
return surface.getDom(); |
| 59 |
}, |
| 60 |
setContents: function ( content ) { |
| 61 |
surface.getModel().getLinearFragment( new ve.Range( 0 ), true ).expandLinearSelection( 'root' ).insertContent( content ); |
| 62 |
return this; |
| 63 |
}, |
| 64 |
getSelection: function () { |
| 65 |
const range = surface.getModel().getSelection().getCoveringRange(); |
| 66 |
if ( !range ) { |
| 67 |
return ''; |
| 68 |
} |
| 69 |
return surface.getModel().getDocument().data.getSourceText( range ); |
| 70 |
}, |
| 71 |
setSelection: function ( options ) { |
| 72 |
surface.getModel().setLinearSelection( |
| 73 |
surface.getModel().getRangeFromSourceOffsets( options.start, options.end ) |
| 74 |
); |
| 75 |
return this; |
| 76 |
}, |
| 77 |
getCaretPosition: function ( options ) { |
| 78 |
const range = surface.getModel().getSelection().getCoveringRange(), |
| 79 |
surfaceModel = surface.getModel(), |
| 80 |
caretPos = range ? surfaceModel.getSourceOffsetFromOffset( range.start ) : 0; |
| 81 |
|
| 82 |
return options.startAndEnd ? |
| 83 |
[ caretPos, range ? surfaceModel.getSourceOffsetFromOffset( range.end ) : 0 ] : |
| 84 |
caretPos; |
| 85 |
}, |
| 86 |
replaceSelection: function ( value ) { |
| 87 |
surface.getModel().getFragment().insertContent( value ); |
| 88 |
return this; |
| 89 |
}, |
| 90 |
|
| 91 |
scrollToCaretPosition: function () { |
| 92 |
surface.scrollSelectionIntoView(); |
| 93 |
return this; |
| 94 |
} |
| 95 |
} ); |
| 96 |
|
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
OO.inheritClass( ve.ui.MWWikitextSurface, ve.ui.MWSurface ); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.MWWikitextSurface.prototype.createModel = function ( doc ) { |
| 109 |
return new ve.dm.MWWikitextSurface( doc ); |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
ve.ui.MWWikitextSurface.prototype.createView = function ( model ) { |
| 116 |
return new ve.ce.MWWikitextSurface( model, this ); |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
ve.ui.MWWikitextSurface.prototype.destroy = function () { |
| 123 |
this.$textbox.textSelection( 'unregister' ); |
| 124 |
|
| 125 |
return ve.ui.MWWikitextSurface.super.prototype.destroy.apply( this, arguments ); |
| 126 |
}; |