MediaWiki:Gadget-templateGallery.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
 // <nowiki>
 /* global window: false */
 /* jshint bitwise:true, curly:true, eqeqeq:true, latedef:true,
  laxbreak:true,
  nocomma:true, strict:true, undef:true, unused:true */
 (function(mw,$){
 'use strict';

 varGALLERY={
 classLink:'dewiki-gallery-link',
 classNav:'dewiki-gallery-nav',
 classText:'dewiki-gallery-text',
 classWrapPrefix:'dewiki-gallery-unit-',
 selectorGallery:'div.dewiki-gallery',
 selectorUnits:'div.dewiki-gallery-units figure',
 textNext:'▶',
 textPrev:'◀',
 unitCount:0
 };

 functionclickEvent($gallery,hideUnit,showUnit){
 // get element to hide and to show
 var$hideUnit=$gallery.find('.'+GALLERY.classWrapPrefix+hideUnit);
 var$showUnit=$gallery.find('.'+GALLERY.classWrapPrefix+showUnit);

 // only do something if both units exist to avoid unwanted results
 if($hideUnit.length&&$showUnit.length){
 $hideUnit.hide();
 $showUnit.show();
 }
 }

 functioncreateNav($gallery,$wrapper,unitIndex){
 // create texts for navigation
 vartexts=[];
 for(vari=0;i<3;i++){
 texts[i]='('+(unitIndex+i)+'/'+GALLERY.unitCount+')';
 }

 // navigation wrapper element
 var$nav=$('<div>')
 .addClass(GALLERY.classNav)
 .prependTo($wrapper);

 // link to previous unit
 if(unitIndex>0){
 var$prev=$('<span>')
 .addClass(GALLERY.classLink)
 .attr('role','button')
 .attr('title',texts[0])
 .text(GALLERY.textPrev)
 .appendTo($nav)
 .on('click',function(){
 clickEvent($gallery,unitIndex,unitIndex-1);
 });
 }

 // current unit without link
 var$curr=$('<span>')
 .addClass(GALLERY.classText)
 .text(texts[1])
 .appendTo($nav);

 // link to next unit
 if(unitIndex+1<GALLERY.unitCount){
 var$next=$('<span>')
 .addClass(GALLERY.classLink)
 .attr('role','button')
 .attr('title',texts[2])
 .text(GALLERY.textNext)
 .appendTo($nav)
 .on('click',function(){
 clickEvent($gallery,unitIndex,unitIndex+1);
 });
 }
 }

 functionprocessUnits($gallery,$unit,unitIndex){
 // create wrapper div of every unit
 varwrapperClass=GALLERY.classWrapPrefix+unitIndex;
 var$wrapper=$('<div>')
 .addClass(wrapperClass);

 $wrapper.appendTo($gallery);
 $wrapper.append($unit);

 // create navigation area
 createNav($gallery,$wrapper,unitIndex);

 // only show the first unit initially
 if(unitIndex>0){
 $wrapper.hide();
 }
 }

 functionprocessGallery($gallery){
 // get units (images) in gallery
 var$units=$gallery.find(GALLERY.selectorUnits);

 // if no images in gallery, return
 GALLERY.unitCount=$units.length;
 if(!GALLERY.unitCount){
 return;
 }

 $units.each(function(unitIndex){
 processUnits($gallery,$(this),unitIndex);
 });
 }

 functioninit($content){
 // don't execute in printable version
 if(document.URL.match(/printable/g)){
 return;
 }

 // get galleries on page
 var$galleries=$content.find(GALLERY.selectorGallery);

 $galleries.each(function(){
 processGallery($(this));
 });

 }

 // when content ready
 $(mw.hook('wikipage.content').add(function($content){
 init($content);
 }));

 }(window.mediaWiki,window.jQuery));
 // </nowiki>
Abgerufen von „https://de.wikipedia.org/w/index.php?title=MediaWiki:Gadget-templateGallery.js&oldid=244114868"