2015-02-17 23:56:44 +00:00
|
|
|
( function () {
|
2015-03-07 01:20:26 +00:00
|
|
|
/*!
|
2013-09-21 03:46:02 +00:00
|
|
|
* TemplateData Generator button fixture
|
|
|
|
* The button will appear on Template namespaces only, above the edit textbox
|
|
|
|
*
|
|
|
|
* @author Moriel Schottlender
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-12-05 11:44:24 +00:00
|
|
|
/* global ve */
|
|
|
|
|
2014-05-20 22:51:46 +00:00
|
|
|
$( function () {
|
2016-12-03 16:18:51 +00:00
|
|
|
var pieces, isDocPage, target,
|
2015-02-18 22:55:17 +00:00
|
|
|
pageName = mw.config.get( 'wgPageName' ),
|
|
|
|
config = {
|
|
|
|
pageName: pageName,
|
2014-10-11 05:22:21 +00:00
|
|
|
isPageSubLevel: false
|
|
|
|
},
|
2015-02-18 22:55:17 +00:00
|
|
|
$textbox = $( '#wpTextbox1' );
|
2013-09-21 03:46:02 +00:00
|
|
|
|
2016-12-03 16:18:51 +00:00
|
|
|
// Check if we're in the proper namespace
|
|
|
|
if ( mw.config.get( 'wgCanonicalNamespace' ) !== 'Template' ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-18 22:55:17 +00:00
|
|
|
|
2016-12-03 16:18:51 +00:00
|
|
|
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 ) {
|
2014-10-11 05:22:21 +00:00
|
|
|
// Prepare the editor
|
2016-12-05 12:37:01 +00:00
|
|
|
target = new mw.TemplateData.TextareaTarget( $textbox, config );
|
2016-12-03 16:18:51 +00:00
|
|
|
$( '#mw-content-text' ).prepend( target.$element );
|
2013-09-21 03:46:02 +00:00
|
|
|
}
|
2016-12-05 11:44:24 +00:00
|
|
|
// Visual editor source mode
|
|
|
|
mw.hook( 've.activationComplete' ).add( function () {
|
|
|
|
var surface = ve.init.target.getSurface();
|
|
|
|
if ( surface.getMode() === 'source' ) {
|
|
|
|
target = new mw.TemplateData.VETarget( surface, config );
|
|
|
|
$( '.ve-init-mw-desktopArticleTarget-originalContent' ).prepend( target.$element );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
mw.hook( 've.deactivate' ).add( function () {
|
|
|
|
if ( target ) {
|
|
|
|
target.destroy();
|
|
|
|
target = null;
|
|
|
|
}
|
|
|
|
} );
|
2013-09-21 03:46:02 +00:00
|
|
|
|
|
|
|
} );
|
|
|
|
|
2015-02-17 23:56:44 +00:00
|
|
|
}() );
|