mediawiki-extensions-Templa.../modules/ext.templateDataGenerator.editPage.js
Ed Sanders a586d54e93 Abstract out editor manipulation form UI
Create target classes with get/setWikitext methods.

Also refactor some of the window manager code.

Bug: T152230
Change-Id: I7dcc137d79e029b69467ca282d8c52683e022598
2016-12-05 17:01:15 +00:00

52 lines
1.2 KiB
JavaScript

( function () {
/*!
* TemplateData Generator button fixture
* The button will appear on Template namespaces only, above the edit textbox
*
* @author Moriel Schottlender
*/
'use strict';
$( function () {
var pieces, isDocPage, target,
pageName = mw.config.get( 'wgPageName' ),
config = {
pageName: pageName,
isPageSubLevel: false
},
$textbox = $( '#wpTextbox1' );
// Check if we're in the proper namespace
if ( mw.config.get( 'wgCanonicalNamespace' ) !== 'Template' ) {
return;
}
pieces = pageName.split( '/' );
isDocPage = pieces.length > 1 && pieces[ pieces.length - 1 ] === 'doc';
config = {
pageName: pageName,
isPageSubLevel: pieces.length > 1,
parentPage: pageName,
isDocPage: isDocPage
};
// Only if we are in a doc page do we set the parent page to
// the one above. Otherwise, all parent pages are current pages
if ( isDocPage ) {
pieces.pop();
config.parentPage = pieces.join( '/' );
}
// Textbox wikitext editor
if ( $textbox.length ) {
// Prepare the editor
target = new mw.TemplateData.TextareaTarget( $textbox ),
mw.libs.tdgUi.init( target, config );
$( '#mw-content-text' ).prepend( target.$element );
}
} );
}() );