MediaWiki:Gadget-Prosesize.js: Difference between revisions

Content deleted Content added
fix
fix
Line 1:
// rewrite of [[User:Dr_pda/prosesize.js]]
// TODO: check functionality in edit mode/preview mode/submit mode
( function () {
function sizeFormatter( size ) {
Line 26 ⟶ 25:
// Get size of text in edit box
// eslint-disable-next-line no-jquery/no-global-selector
appendResult( $( '#wpTextbox1' ).htmltextSelection( 'getContents' ).length );
} else if ( mw.config.get( 'wgIsArticle' ) ) {
// Get revision size from API
Line 90 ⟶ 89:
var proseValue, refValue, refHtmlValue, proseHtmlValue;
// eslint-disable-next-line no-jquery/no-global-selector
var bodyContentparserOutput = $( '.mw-parser-output' );
// eslint-disable-next-line no-jquery/no-global-selector
var prevStats = $( '#document-size-stats' );
Line 110 ⟶ 109:
.prop( 'id', 'document-size' )
.append( header, output );
if ( bodyContentparserOutput.length === 0 ) {
return;
}
Line 117 ⟶ 116:
prevStats.remove();
prevHeader.remove();
bodyContentparserOutput.children( 'p' ).removeClass( 'prosesize-highlight' );
} else {
// Calculate prose size and size of reference markers ([1] etc)
bodyContentparserOutput.children( 'p' ).each( function () {
$( this ).addClass( 'prosesize-highlight' );
proseSize += getLength( this );
Line 130 ⟶ 129:
 
// Calculate size of references (i.e. output of <references/>)
bodyContentparserOutput.find( 'ol.references' ).each( function () {
refSize = getLength( this );
refSizeHtml = this.innerHTML.length;
Line 140 ⟶ 139:
proseHtmlValue = sizeElement( 'prose-size-html', 'Prose size (including all HTML code):', proseSizeHtml - refmarkSizeHtml );
output.append( proseHtmlValue, refHtmlValue, proseValue, refValue );
bodyContentparserOutput.prepend( combined );
getFileSize( proseHtmlValue );
getRevisionSize( proseValue );
Line 155 ⟶ 154:
* show the approppiate response upon clicking the portlet link
*/
var func, $portlet, notEnabled = false;
if (
if ( mw.config.get( 'wgAction' ) === 'edit' || ( mw.config.get( 'wgAction' ) === 'submit' && document.getElementById( 'wikiDiff' ) ) ) {
mw.config.get( 'wgAction' ) === 'edit' ||
if ( mw.config.get( 'wgAction' ) === 'edit' || ( mw.config.get( 'wgAction' ) === 'submit' && document.getElementById( 'wikiDiff' ) ) ) {
) {
notEnabled = true;
func = function () {
mw.notify( 'You need to preview the text for the prose size script to work in edit mode.' );
};
$portlet.addClass( 'prosesize-portlet-link-edit-mode' );
} else if ( [ 'view', 'submit', 'historysubmit', 'purge' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
func = main;
Line 166 ⟶ 168:
if ( func ) {
$portlet = $( mw.util.addPortletLink( 'p-tb', '#', 'Page size', 't-page-size', 'Calculate page and prose size' ) );
if ( notEnabled ) {
$portlet.addClass( 'prosesize-portlet-link-edit-mode' );
}
$portlet.on( 'click', function ( e ) {
e.preventDefault();
if ( window.ve && ve.init && ve.init.target && ve.init.target.active ) {
func();
mw.notify( 'Prosesize does not work with the Visual Editor.' );
} else {
func();
}
} );
}