| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
mw.libs.ve = mw.libs.ve || {}; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
mw.libs.ve.MWTempWikitextEditorWidget = function VeUiMwTempWikitextEditorWidget( config ) { |
| 26 |
const conf = mw.config.get( 'wgVisualEditor' ), |
| 27 |
dir = conf.pageLanguageDir, |
| 28 |
lang = conf.pageLanguageCode; |
| 29 |
|
| 30 |
this.$element = $( '<textarea>' ) |
| 31 |
.addClass( 've-init-mw-tempWikitextEditorWidget ' ) |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
.addClass( 'mw-editfont-' + mw.user.options.get( 'editfont' ) ) |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
.addClass( 'mw-content-' + dir ) |
| 41 |
.attr( { |
| 42 |
lang: lang, |
| 43 |
dir: dir |
| 44 |
} ) |
| 45 |
.val( config.value ); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
mw.libs.ve.MWTempWikitextEditorWidget.prototype.moveCursorToStart = function () { |
| 55 |
|
| 56 |
this.$element[ 0 ].setSelectionRange( 0, 0 ); |
| 57 |
this.focus(); |
| 58 |
return this; |
| 59 |
}; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
mw.libs.ve.MWTempWikitextEditorWidget.prototype.adjustSize = function () { |
| 68 |
|
| 69 |
this.$element.height( this.$element[ 0 ].scrollHeight ); |
| 70 |
return this; |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
mw.libs.ve.MWTempWikitextEditorWidget.prototype.focus = function () { |
| 80 |
this.$element[ 0 ].focus(); |
| 81 |
return this; |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
mw.libs.ve.MWTempWikitextEditorWidget.prototype.getValue = function () { |
| 88 |
return this.$element.val(); |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
mw.libs.ve.MWTempWikitextEditorWidget.prototype.getRange = function () { |
| 97 |
const input = this.$element[ 0 ], |
| 98 |
start = input.selectionStart, |
| 99 |
end = input.selectionEnd, |
| 100 |
isBackwards = input.selectionDirection === 'backward'; |
| 101 |
|
| 102 |
return { |
| 103 |
from: isBackwards ? end : start, |
| 104 |
to: isBackwards ? start : end |
| 105 |
}; |
| 106 |
}; |