MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Waterlands
Zur Navigation springen Zur Suche springen
K
K
Zeile 1: Zeile 1:
 
/* Das folgende JavaScript wird für alle Benutzer geladen. */
 
/* Das folgende JavaScript wird für alle Benutzer geladen. */
 +
 +
/* Zusätzliche Toolbarbuttons */
 +
var customizeToolbar = function () {
 +
     
 +
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 +
        'section': 'advanced',
 +
        'groups': {
 +
            'code': {
 +
'label': 'Code' // or use labelMsg for a localized label, see above
 +
                }
 +
            }
 +
        }
 +
    );
 +
 +
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 +
'section': 'advanced',
 +
'group': 'code',
 +
'tools': {
 +
'preformat': {
 +
label: 'Spoiler',
 +
type: 'button',
 +
icon: '/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");
 
spoilerButtons = document.getElementsByClassName("showSpoilerButton");
  

Version vom 17. August 2020, 18:15 Uhr

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

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

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'section': 'advanced',
		'group': 'code',
		'tools': {
			'preformat': {
				label: 'Spoiler',
				type: 'button',
				icon: '/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";
	}
}