2010-09-15 03:08:35 +00:00
|
|
|
/* Publish module for wikiEditor */
|
2013-11-07 00:38:43 +00:00
|
|
|
/*jshint onevar:false */
|
|
|
|
( function ( $, mw ) { $.wikiEditor.modules.previewDialog = {
|
2010-09-15 03:08:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatability map
|
|
|
|
*/
|
|
|
|
'browsers': {
|
|
|
|
// Left-to-right languages
|
|
|
|
'ltr': {
|
|
|
|
'msie': [['>=', 7]],
|
|
|
|
'firefox': [['>=', 3]],
|
|
|
|
'opera': [['>=', 9.6]],
|
|
|
|
'safari': [['>=', 4]]
|
|
|
|
},
|
|
|
|
// Right-to-left languages
|
|
|
|
'rtl': {
|
|
|
|
'msie': [['>=', 8]],
|
|
|
|
'firefox': [['>=', 3]],
|
|
|
|
'opera': [['>=', 9.6]],
|
|
|
|
'safari': [['>=', 4]]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Internally used functions
|
|
|
|
*/
|
|
|
|
fn: {
|
|
|
|
/**
|
|
|
|
* Creates a publish module within a wikiEditor
|
|
|
|
* @param context Context object of editor to create module in
|
|
|
|
* @param config Configuration object to create module from
|
|
|
|
*/
|
2014-04-30 10:59:01 +00:00
|
|
|
create: function ( context ) {
|
2010-09-15 03:08:35 +00:00
|
|
|
// Build the dialog behind the Publish button
|
|
|
|
var dialogID = 'wikiEditor-' + context.instance + '-preview-dialog';
|
|
|
|
$.wikiEditor.modules.dialogs.fn.create(
|
|
|
|
context,
|
|
|
|
{
|
|
|
|
preview: {
|
|
|
|
id: dialogID,
|
|
|
|
titleMsg: 'wikieditor-preview-tab',
|
|
|
|
html: '\
|
|
|
|
<div class="wikiEditor-ui-loading"><span></span></div>\
|
|
|
|
<div class="wikiEditor-preview-dialog-contents"></div>\
|
|
|
|
',
|
2014-04-30 10:59:01 +00:00
|
|
|
init: function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
dialog: {
|
|
|
|
buttons: {
|
2014-04-30 10:59:01 +00:00
|
|
|
'wikieditor-publish-dialog-publish': function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
var minorChecked = $( '#wikiEditor-' + context.instance +
|
|
|
|
'-dialog-minor' ).is( ':checked' ) ?
|
|
|
|
'checked' : '';
|
|
|
|
var watchChecked = $( '#wikiEditor-' + context.instance +
|
|
|
|
'-dialog-watch' ).is( ':checked' ) ?
|
|
|
|
'checked' : '';
|
|
|
|
$( '#wpMinoredit' ).attr( 'checked', minorChecked );
|
|
|
|
$( '#wpWatchthis' ).attr( 'checked', watchChecked );
|
2011-06-06 23:18:13 +00:00
|
|
|
$( '#wpSummary' ).val( $( '#wikiEditor-' + context.instance +
|
2010-09-15 03:08:35 +00:00
|
|
|
'-dialog-summary' ).val() );
|
|
|
|
$( '#editform' ).submit();
|
|
|
|
},
|
2014-04-30 10:59:01 +00:00
|
|
|
'wikieditor-publish-dialog-goback': function () {
|
|
|
|
$( this ).dialog( 'close' );
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
resizable: false,
|
|
|
|
height: $( 'body' ).height() - 100,
|
|
|
|
width: $( 'body' ).width() - 300,
|
|
|
|
position: ['center', 'top'],
|
2014-04-30 10:59:01 +00:00
|
|
|
open: function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
// Gets the latest copy of the wikitext
|
|
|
|
var wikitext = context.fn.getContents();
|
|
|
|
var $dialog = $( '#' + dialogID );
|
|
|
|
$dialog
|
|
|
|
.css( 'position', 'relative' )
|
|
|
|
.css( 'height', $( 'body' ).height() - 200 )
|
|
|
|
.parent()
|
|
|
|
.css( 'top', '25px' );
|
|
|
|
// $dialog.dialog( 'option', 'width', $( 'body' ).width() - 300 );
|
|
|
|
// Aborts when nothing has changed since the last preview
|
2013-11-07 00:38:43 +00:00
|
|
|
if ( context.modules.preview.previewText === wikitext ) {
|
2010-09-15 03:08:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 03:08:35 +00:00
|
|
|
$dialog.find( '.wikiEditor-preview-dialog-contents' ).empty();
|
|
|
|
$dialog.find( '.wikiEditor-ui-loading' ).show();
|
|
|
|
$.post(
|
2011-06-26 19:25:27 +00:00
|
|
|
mw.util.wikiScript( 'api' ),
|
2010-09-15 03:08:35 +00:00
|
|
|
{
|
|
|
|
'action': 'parse',
|
2011-06-26 19:25:27 +00:00
|
|
|
'title': mw.config.get( 'wgPageName' ),
|
2010-09-15 03:08:35 +00:00
|
|
|
'text': wikitext,
|
|
|
|
'prop': 'text',
|
|
|
|
'pst': '',
|
|
|
|
'format': 'json'
|
|
|
|
},
|
2014-04-30 10:59:01 +00:00
|
|
|
function ( data ) {
|
2010-09-15 03:08:35 +00:00
|
|
|
if (
|
2013-11-07 00:38:43 +00:00
|
|
|
typeof data.parse === 'undefined' ||
|
|
|
|
typeof data.parse.text === 'undefined' ||
|
|
|
|
typeof data.parse.text['*'] === 'undefined'
|
2010-09-15 03:08:35 +00:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context.modules.preview.previewText = wikitext;
|
|
|
|
$dialog.find( '.wikiEditor-ui-loading' ).hide();
|
|
|
|
$dialog.find( '.wikiEditor-preview-dialog-contents' )
|
2011-06-26 19:25:27 +00:00
|
|
|
.html( '<h1 class="firstHeading" id="firstHeading">' +
|
|
|
|
mw.config.get( 'wgTitle' ) + '</h1>' +
|
2010-09-15 03:08:35 +00:00
|
|
|
data.parse.text['*'] )
|
2014-04-30 10:59:01 +00:00
|
|
|
.find( 'a:not([href^=#])' ).click( function () { return false; } );
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
'json'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resizeme: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
context.fn.addButton( {
|
|
|
|
'captionMsg': 'wikieditor-preview-tab',
|
2014-04-30 10:59:01 +00:00
|
|
|
'action': function () {
|
|
|
|
context.$textarea.wikiEditor( 'openDialog', 'preview' );
|
2010-09-15 03:08:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-07 00:38:43 +00:00
|
|
|
}; } )( jQuery, mediaWiki );
|