MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Waterlands
Zur Navigation springen Zur Suche springen
K
K
Zeile 38: Zeile 38:
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
 
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
 
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
 
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
$( document ).ready(function() {
+
mw.loader.using( 'user.options' ).then( function () {
customizeToolbar();
+
// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
});
+
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
 +
$.when(
 +
mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
 +
).then( customizeToolbar );
 +
}
 +
} );
 
}
 
}
  

Version vom 17. August 2020, 18:43 Uhr

/* Das folgende JavaScript wird für alle Benutzer geladen. */

/* Zusätzliche Toolbarbuttons */
var customizeToolbar = function () {
       
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'groups': {
            'templates': {
				'label': 'Vorlagen' // or use labelMsg for a localized label, see above
                }
            }
        }
    );

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'templates',
		'tools': {
			'spoiler': {
				label: 'Spoiler',
				type: 'button',
				icon: 'https://waterlands.boxofcare.de/images/buttons/spoiler.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "{{Spoiler|",
						periMsg: 'Spoilerinhalt',
						post: "}}"
					}
				}
			}
		}
	});

};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor.toolbar' ), $.ready
			).then( customizeToolbar );
		}
	} );
}


/* Spoiler-Funktionen */
spoilerButtons = document.getElementsByClassName("showSpoilerButton");

for(var i = 0; i < spoilerButtons.length; i++) {
	spoilerButtons[i].addEventListener("click", toggleSpoiler);
}

function toggleSpoiler(e) {
	var button = e.target;
	var container = e.target.parentElement;
	var innerSpoiler = container.querySelector(".spoilerInner");
	if(innerSpoiler.classList.contains("spoilerHidden")) {
		innerSpoiler.classList.remove("spoilerHidden");
		button.innerText = "Zuklappen";
	} else {
		innerSpoiler.classList.add("spoilerHidden");
		button.innerText = "Aufklappen";
	}
}