MediaWiki:Gadget-BosOzet.js

Vikipedi, özgür ansiklopedi

Not: Sayfayı kaydettikten sonra değişiklikleri görebilmek için tarayıcınızın önbelleğinizi temizlemeniz gerekir. Google Chrome, Firefox, Microsoft Edge ve Safari: ⇧ Shift tuşuna basılı tutun ve Yeniden Yükle araç çubuğu düğmesine tıklayın. Ayrıntılar ve diğer tarayıcılara yönelik yönergeler için Vikipedi:Önbelleğinizi atlayın sayfasını inceleyin.

/* http://de.wikipedia.org/wiki/MediaWiki:Gadget-highlightemptysummary.js User:Umherirrender */

switch ( mw.config.get( 'wgUserLanguage' ) ) {
case 'tr':
	mw.messages.set( {
		'summary-empty': 'Lütfen bir değişiklik özeti yazınız.',
		'summary-empty-button': 'Renli alana bir değiiklik özeti yazınız.'
	} );
	break;
case 'en':
default:
	mw.messages.set( {
		'summary-empty': 'Please enter an edit summary here.',
		'summary-empty-button': 'Please write an edit summary into the colored text field.'
	} );
	break;
};
/*
 * Özet yazılması durumunda, renk vurgusu dinamik olarak kaybolur
 */
$( function() {
 var wgAction = mw.config.get( 'wgAction' );
 if( wgAction !== 'edit' && wgAction !== 'submit' ) {
  return;
 }
 var wgNamespaceNumber = mw.config.get( 'wgNamespaceNumber' );
 if ( wgNamespaceNumber === 0  /* ANR        */
   || wgNamespaceNumber === 6  /* Datei:     */
   || wgNamespaceNumber === 8  /* MediaWiki: */
   || wgNamespaceNumber === 10 /* Vorlage:   */
   || wgNamespaceNumber === 12 /* Hilfe:     */
   || wgNamespaceNumber === 14 /* Kategori: */
 ) {
  var wpSummary = $( '#wpSummary' );
  var wpSave = $( '#wpSave' );
  var wpTextbox1 = $( '#wpTextbox1' );
  if( wpSummary.length && wpSave.length ) {
   // save the old titles
   mw.messages.set( {
    'summary-empty-old': wpSummary.attr( 'title' ),
    'summary-empty-button-old': wpSave.attr( 'title' )
   } );

   // store the current highlight state and change only when necessary
   var summaryIsHighlighted = undefined;
   var allowHighlighting = false; //highlight only under condition

   // bind the events - mouseenter and mouseleave for drag&drop
   wpSummary.on( 'change keyup keydown mouseenter mouseleave', function() {
    if( !allowHighlighting ) {
     return;
    }
    var summaryNeedsHighlighting = wpSummary.val().match( /^\s*(?:\/\*.*\*\/)?\s*$/ )
                                  // keep the chance to use autosummary for redirects
                                  && !wpTextbox1.val().match( /^\s*#(?:WEITERLEITUNG|REDIRECT)/i );
    if( summaryIsHighlighted === summaryNeedsHighlighting ) {
     //need no change
     return;
    }
    // current highlighting need change (add or remove the css class)
    summaryIsHighlighted = summaryNeedsHighlighting;
    if( summaryNeedsHighlighting ) {
     wpSummary.addClass( 'summary-empty' );
     wpSave.addClass( 'summary-empty-button' );
     // set the hint, this removed the hint to accesskeys, but that is hard to do
     wpSummary.attr( 'title', mw.messages.get( 'summary-empty' ) );
     wpSave.attr( 'title', mw.messages.get( 'summary-empty-button' ) );
    } else {
     wpSummary.removeClass( 'summary-empty' );
     wpSave.removeClass( 'summary-empty-button' );
     // restore old titles
     wpSummary.attr( 'title', mw.messages.get( 'summary-empty-old' ) );
     wpSave.attr( 'title', mw.messages.get( 'summary-empty-button-old' ) );
    }
   });
   // highlight after text changes
   wpTextbox1.change( function() {
    allowHighlighting = true;
    wpSummary.change();
   });
   // highlight also, when in preview or show changes
   if( wgAction === 'submit' ) {
    allowHighlighting = true;
    wpSummary.change();
   }
  }
 }
});