2010-09-15 03:08:35 +00:00
|
|
|
/* Publish module for wikiEditor */
|
2012-07-03 05:52:27 +00:00
|
|
|
( function ( $ ) {
|
|
|
|
|
|
|
|
$.wikiEditor.modules.publish = {
|
2010-09-15 03:08:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compatability map
|
|
|
|
*/
|
2012-07-03 05:52:27 +00:00
|
|
|
browsers: {
|
2010-09-15 03:08:35 +00:00
|
|
|
// Left-to-right languages
|
2012-07-03 05:52:27 +00:00
|
|
|
ltr: {
|
|
|
|
msie: [['>=', 7]],
|
|
|
|
firefox: [['>=', 3]],
|
|
|
|
opera: [['>=', 9.6]],
|
|
|
|
safari: [['>=', 4]]
|
2010-09-15 03:08:35 +00:00
|
|
|
},
|
|
|
|
// Right-to-left languages
|
2012-07-03 05:52:27 +00:00
|
|
|
rtl: {
|
|
|
|
msie: [['>=', 8]],
|
|
|
|
firefox: [['>=', 3]],
|
|
|
|
opera: [['>=', 9.6]],
|
|
|
|
safari: [['>=', 4]]
|
2010-09-15 03:08:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2012-07-03 05:52:27 +00:00
|
|
|
create: function ( context, config ) {
|
2010-09-15 03:08:35 +00:00
|
|
|
// Build the dialog behind the Publish button
|
|
|
|
var dialogID = 'wikiEditor-' + context.instance + '-dialog';
|
|
|
|
$.wikiEditor.modules.dialogs.fn.create(
|
|
|
|
context,
|
|
|
|
{
|
|
|
|
previewsave: {
|
|
|
|
id: dialogID,
|
|
|
|
titleMsg: 'wikieditor-publish-dialog-title',
|
|
|
|
html: '\
|
|
|
|
<div class="wikiEditor-publish-dialog-copywarn"></div>\
|
|
|
|
<div class="wikiEditor-publish-dialog-editoptions">\
|
|
|
|
<form id="wikieditor-' + context.instance + '-publish-dialog-form">\
|
|
|
|
<div class="wikiEditor-publish-dialog-summary">\
|
|
|
|
<label for="wikiEditor-' + context.instance + '-dialog-summary"\
|
|
|
|
rel="wikieditor-publish-dialog-summary"></label>\
|
|
|
|
<br />\
|
|
|
|
<input type="text" id="wikiEditor-' + context.instance + '-dialog-summary"\
|
|
|
|
style="width: 100%;" />\
|
|
|
|
</div>\
|
|
|
|
<div class="wikiEditor-publish-dialog-options">\
|
|
|
|
<input type="checkbox"\
|
|
|
|
id="wikiEditor-' + context.instance + '-dialog-minor" />\
|
|
|
|
<label for="wikiEditor-' + context.instance + '-dialog-minor"\
|
|
|
|
rel="wikieditor-publish-dialog-minor"></label>\
|
|
|
|
<input type="checkbox"\
|
|
|
|
id="wikiEditor-' + context.instance + '-dialog-watch" />\
|
|
|
|
<label for="wikiEditor-' + context.instance + '-dialog-watch"\
|
|
|
|
rel="wikieditor-publish-dialog-watch"></label>\
|
|
|
|
</div>\
|
|
|
|
</form>\
|
|
|
|
</div>',
|
2012-07-03 05:52:27 +00:00
|
|
|
init: function () {
|
|
|
|
var i;
|
|
|
|
|
|
|
|
$(this).find( '[rel]' ).each( function () {
|
2010-10-27 00:16:32 +00:00
|
|
|
$(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) );
|
2010-09-15 03:08:35 +00:00
|
|
|
});
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2010-09-15 03:08:35 +00:00
|
|
|
/* REALLY DIRTY HACK! */
|
|
|
|
// Reformat the copyright warning stuff
|
|
|
|
var copyWarnHTML = $( '#editpage-copywarn p' ).html();
|
|
|
|
// TODO: internationalize by splitting on other characters that end statements
|
|
|
|
var copyWarnStatements = copyWarnHTML.split( '. ' );
|
|
|
|
var newCopyWarnHTML = '<ul>';
|
2012-07-03 05:52:27 +00:00
|
|
|
for ( i = 0; i < copyWarnStatements.length; i++ ) {
|
|
|
|
if ( copyWarnStatements[i] !== '' ) {
|
2011-06-06 23:18:13 +00:00
|
|
|
var copyWarnStatement = $.trim( copyWarnStatements[i] ).replace( /\.*$/, '' );
|
2010-09-15 03:08:35 +00:00
|
|
|
newCopyWarnHTML += '<li>' + copyWarnStatement + '.</li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newCopyWarnHTML += '</ul>';
|
|
|
|
// No list if there's only one element
|
2011-09-13 08:56:32 +00:00
|
|
|
$(this).find( '.wikiEditor-publish-dialog-copywarn' ).html(
|
2010-09-15 03:08:35 +00:00
|
|
|
copyWarnStatements.length > 1 ? newCopyWarnHTML : copyWarnHTML
|
|
|
|
);
|
|
|
|
/* END OF REALLY DIRTY HACK */
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-07-03 05:52:27 +00:00
|
|
|
if ( $( '#wpMinoredit' ).length === 0 )
|
2010-09-15 03:08:35 +00:00
|
|
|
$( '#wikiEditor-' + context.instance + '-dialog-minor' ).hide();
|
|
|
|
else if ( $( '#wpMinoredit' ).is( ':checked' ) )
|
|
|
|
$( '#wikiEditor-' + context.instance + '-dialog-minor' )
|
2012-07-03 05:52:27 +00:00
|
|
|
.prop( 'checked', true );
|
|
|
|
if ( $( '#wpWatchthis' ).length === 0 )
|
2010-09-15 03:08:35 +00:00
|
|
|
$( '#wikiEditor-' + context.instance + '-dialog-watch' ).hide();
|
|
|
|
else if ( $( '#wpWatchthis' ).is( ':checked' ) )
|
|
|
|
$( '#wikiEditor-' + context.instance + '-dialog-watch' )
|
2012-07-03 05:52:27 +00:00
|
|
|
.prop( 'checked', true );
|
2011-09-13 08:56:32 +00:00
|
|
|
|
2012-07-03 05:52:27 +00:00
|
|
|
$(this).find( 'form' ).submit( function ( e ) {
|
2010-09-15 03:08:35 +00:00
|
|
|
$(this).closest( '.ui-dialog' ).find( 'button:first' ).click();
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
},
|
2013-01-21 18:01:52 +00:00
|
|
|
immediateCreate: true,
|
2010-09-15 03:08:35 +00:00
|
|
|
dialog: {
|
|
|
|
buttons: {
|
2012-07-03 05:52:27 +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' : '';
|
2012-07-03 05:52:27 +00:00
|
|
|
$( '#wpMinoredit' ).prop( 'checked', minorChecked );
|
|
|
|
$( '#wpWatchthis' ).prop( '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();
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
'wikieditor-publish-dialog-goback': function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
$(this).dialog( 'close' );
|
|
|
|
}
|
|
|
|
},
|
2012-07-03 05:52:27 +00:00
|
|
|
open: function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
$( '#wikiEditor-' + context.instance + '-dialog-summary' ).focus();
|
|
|
|
},
|
|
|
|
width: 500
|
|
|
|
},
|
|
|
|
resizeme: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2012-07-03 05:52:27 +00:00
|
|
|
|
2010-09-15 03:08:35 +00:00
|
|
|
context.fn.addButton( {
|
|
|
|
'captionMsg': 'wikieditor-publish-button-publish',
|
2012-07-03 05:52:27 +00:00
|
|
|
'action': function () {
|
2010-09-15 03:08:35 +00:00
|
|
|
$( '#' + dialogID ).dialog( 'open' );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
2012-07-03 05:52:27 +00:00
|
|
|
|
2010-09-15 03:08:35 +00:00
|
|
|
context.fn.addButton( {
|
|
|
|
'captionMsg': 'wikieditor-publish-button-cancel',
|
2013-01-21 18:01:52 +00:00
|
|
|
'action': function () {
|
|
|
|
window.location.href = $( '#mw-editform-cancel' ).attr( 'href' );
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-15 03:08:35 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 05:52:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}( jQuery ) );
|