MediaWiki:Common.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(JavaScript herschrijven (deel 1))
Regel 62: Regel 62:
 
}
 
}
  
// <source lang='javascript'>
+
jQuery(function($) {
 
+
   if (mw.config.get('wgPageName') == mw.config.get('wgMainPageTitle')
function protectionTemplates() {
+
    || mw.config.get('wgCanonicalNamespace') == "Special"  
   if (wgPageName == wgMainPageTitle || wgCanonicalNamespace == "Special" || typeof(wgRestrictionEdit) == "undefined") {
+
    || typeof(mw.config.get('wgRestrictionEdit')) == "undefined"
     // The current page is the main page, a special page or new. Nothing to do there!
+
  ) {
 +
     // Hoofdpagina, speciale pagina of niet beschermbaar
 
     return false;
 
     return false;
 
   }
 
   }
  
  var content = document.getElementById('content'); 
+
   if ($('#bodyContent')['length'] == 0) {
   if (content == null || document.getElementsByTagName('h1')[0] == null) {
+
     // Kan geen tekst vinden
     // There is no 'content' element and/or no h1 element. So quit.
 
 
     return false;
 
     return false;
 
   }
 
   }
  
   // Determine template.
+
   // Juiste beveligingssjabloon uitzoeken.
   if (wgRestrictionEdit[0] != null && wgRestrictionEdit[0] == 'sysop') {
+
   if (mw.config.get('wgRestrictionEdit')[0] != null && mw.config.get('wgRestrictionEdit')[0] == 'sysop') {
     // Editing is limited to sysops.
+
     // Alleen moderatoren kunnen bewerken
 
     var templateTitle = 'Beveiligd';
 
     var templateTitle = 'Beveiligd';
 
     var nodeId = 'templ_Beveiligd';
 
     var nodeId = 'templ_Beveiligd';
   } else if (wgRestrictionEdit[0] != null && wgRestrictionEdit[0] == 'autoconfirmed') {
+
   } else if (mw.config.get('wgRestrictionEdit')[0] != null && mw.config.get('wgRestrictionEdit') == 'autoconfirmed') {
     // Editing is limited to autoconfirmed users. Effectief nutteloos op deze wiki, dus geen sjabloon
+
     // Alleen automatisch bevestigde gebruikers kunnen bewerken. Effectief nutteloos op deze wiki, dus geen sjabloon
 
     return false;
 
     return false;
   } else if (wgRestrictionMove[0] != null) {
+
   } else if (mw.config.get('wgRestrictionMove')[0] != null) {
     // Moving the page is limited.
+
     // Het verplaatsen van de pagina is beveiligd.
 
     var templateTitle = 'TitelBeveiligd';
 
     var templateTitle = 'TitelBeveiligd';
 
     var nodeId = 'templ_TitelBeveiligd';
 
     var nodeId = 'templ_TitelBeveiligd';
 
   } else {
 
   } else {
     // The page is not protected.
+
     // De pagina is niet beveiligd.
 
     return false;
 
     return false;
 
   }
 
   }
  
 
   // Get template from API.
 
   // Get template from API.
   var request = sajax_init_object();
+
   $.getJSON(
  request.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=parse&text={{' + encodeURIComponent(templateTitle) + '}}&title=' + encodeURIComponent(wgPageName), true);
+
    mw.util.wikiScript('api'),  
  request.onreadystatechange =
+
    {
     function () {
+
      format: 'json',
       if (request.readyState != 4) return;
+
      action: 'parse',
      if (request.status == 200 && request.responseText && request.responseText.charAt(0) == '{') {
+
      text: '{{' + encodeURIComponent(templateTitle) + '}}',
        var json = eval ('(' + request.responseText + ')');
+
      contentmodel: 'wikitext'
        if (json.parse.text['*']) {
+
    },
          var divContent = json.parse.text['*'];
+
     function(obj) {
        }
+
       $('.mw-indicators').before(obj['parse']['text']['*']);
      }
+
     }
 
+
   );
      if (divContent != null) {
 
        // We retrieved the template. Add it to the page.
 
        var divNode = document.createElement('div');
 
        divNode.id = nodeId;
 
        divNode.className = 'Titel_item3';
 
        divNode.innerHTML = divContent;
 
        content.insertBefore(divNode, document.getElementsByTagName('h1')[0]);
 
      }
 
      if( $('#awardtemplate').length ) { $('#protectedtext').hide() }
 
     };
 
  request.setRequestHeader ('Pragma', 'cache=yes');
 
  request.setRequestHeader ('Cache-Control', 'no-transform');
 
   request.send (null);
 
}
 
 
addOnloadHook(protectionTemplates);
 
  
 +
});
  
 
//Voeg automatisch beschrijvingsjabloon in op [[Speciaal:Upload]]
 
//Voeg automatisch beschrijvingsjabloon in op [[Speciaal:Upload]]

Versie van 14 jul 2016 19:02

/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers 

<pre>*/

//Als het goed is wordt de scrollbalk nu niet weergegeven, maar word het suggestievakje wat groter...
os_max_lines_per_suggest = 10;

/**********************************/
/* Pas op: Dit is een woordenboek */
/*                         script */
/* Sumurai8; contact: OP          */
/* Maakt 'tooltips' mogelijk      */
/* Zie Sjabloon:Wbwoord           */
/*     Sjabloon:Wbbetekenis       */
/**********************************/

var Wbq = ""
var Wbx = ""
var Wby = ""
var Wbz = ""
var WbK = "x" //keep it?

function enableTips() {
  for(var counter=1;counter<99;counter++) {
    Wbx = document.getElementById('woordenboek'+counter)
    Wbq = document.getElementById('woordenboekX'+counter)
    if(!Wbx) {
      break;
    }
    Wbq.style.display = "none"
    Wbx.style.display = ""
    Wbx.onmouseover = showWbTip
    Wbx.onmouseout = hideWbTip
    Wbx.onclick = keepWbTip
  }
}

addOnloadHook(enableTips)

function showWbTip() {
  if (WbK == "x") {
    Wbz = this.id
    Wbz = Wbz.substring(11,Wbz.length)
    Wby = document.getElementById('wbcontent'+Wbz)
    Wby.style.display = ""
  }
}

function hideWbTip() {
  if (WbK == "x") {
    Wby.style.display = "none"
  }
}

function keepWbTip() {
  if (WbK == "x") {
    WbK = "v"
  }
  else {
    WbK = "x"
  }
}

jQuery(function($) {
  if (mw.config.get('wgPageName') == mw.config.get('wgMainPageTitle') 
    || mw.config.get('wgCanonicalNamespace') == "Special" 
    || typeof(mw.config.get('wgRestrictionEdit')) == "undefined"
  ) {
    // Hoofdpagina, speciale pagina of niet beschermbaar
    return false;
  }

  if ($('#bodyContent')['length'] == 0) {
    // Kan geen tekst vinden
    return false;
  }

  // Juiste beveligingssjabloon uitzoeken.
  if (mw.config.get('wgRestrictionEdit')[0] != null && mw.config.get('wgRestrictionEdit')[0] == 'sysop') {
    // Alleen moderatoren kunnen bewerken
    var templateTitle = 'Beveiligd';
    var nodeId = 'templ_Beveiligd';
  } else if (mw.config.get('wgRestrictionEdit')[0] != null && mw.config.get('wgRestrictionEdit') == 'autoconfirmed') {
    // Alleen automatisch bevestigde gebruikers kunnen bewerken. Effectief nutteloos op deze wiki, dus geen sjabloon
    return false;
  } else if (mw.config.get('wgRestrictionMove')[0] != null) {
    // Het verplaatsen van de pagina is beveiligd.
    var templateTitle = 'TitelBeveiligd';
    var nodeId = 'templ_TitelBeveiligd';
  } else {
    // De pagina is niet beveiligd.
    return false;
  }

  // Get template from API.
  $.getJSON(
    mw.util.wikiScript('api'), 
    {
      format: 'json',
      action: 'parse',
      text: '{{' + encodeURIComponent(templateTitle) + '}}',
      contentmodel: 'wikitext'
    },
    function(obj) {
      $('.mw-indicators').before(obj['parse']['text']['*']);
    }
  );

});

//Voeg automatisch beschrijvingsjabloon in op [[Speciaal:Upload]]
addOnloadHook( function() {
  $('.uploadTemplate').addClass('opvallend');
  if($('#wpDestFile').val() == "") {
    $('#wpUploadDescription').val('{{Afbeelding|\n|Wat staat er precies op de afbeelding?=\n|Waar heb je de afbeelding vandaan?=\n|Schrijf de complete link van de vindplaats op=\n|Wie heeft de afbeelding gemaakt?=\n|Heb je toestemming om de afbeelding te uploaden?=\n|Welke licentie?=\n}}');
    $('.uploadTemplate').hide();
  }
} );


//Automatische suggestie voor een al bestaand artikel over dit onderwerp in het enkelvoud
addOnloadHook( function() {
  if( $('.mw-newarticletext').length ) {
    var titles = [];
    if( wgTitle.split(" ").length > 1 ) {
      return false;
    }
    //Werken -> Werk
    if( wgTitle.substring( wgTitle.length - 2 ) == "en" ) {
      titles.push( wgTitle.substring( 0, wgTitle.length - 2 ) );
    }
    //Musicals -> Musical
    if( wgTitle.substring( wgTitle.length - 1 ) == "s" ) {
      titles.push( wgTitle.substring( 0, wgTitle.length - 1 ) );
    }
    //Fora -> Forum
    if( wgTitle.substring( wgTitle.length - 1 ) == "a" ) {
      titles.push( wgTitle.substring( 0, wgTitle.length - 1 ) + "um" );
    }
    //Technici -> Technicus
    if( wgTitle.substring( wgTitle.length - 1 ) == "i" ) {
      titles.push( wgTitle.substring( 0, wgTitle.length - 1 ) + "us" );
    }
    if( titles.length ) {
      $('.mw-newarticletext').append( $('<div></div>').addClass("mw-articleAlert") );
      $.get("http://wikikids.wiki.kennisnet.nl/api.php?action=query&prop=info&inprop=url&format=json&titles="+titles.join("|"), function( data ) { 
        for(page in data['query']['pages']) {
          if( data['query']['pages'][page]['missing'] != "" && data['query']['pages'][page]['redirect'] != "" ) {
            $('.mw-articleAlert').html('<b>Let op:</b> Er bestaat mogelijk al een artikel over dit onderwerp op deze pagina: <a href="'+data['query']['pages'][page]['fullurl']+'">'+data['query']['pages'][page]['title']+'</a>. Controleer dit eerst!').addClass("errorbox");
          }
        }
      } );
    }
  }
} );


//[Bugfix] Prepend de volledige url als de titel begint met een / en de relatieve url dus faalt
addOnloadHook( function() {
  if( wgPageName[0] == "/" ) {
    $('#editform').attr('action', '?action=submit');
    $('a[href^="/' + wgPageName + '"]').attr('href', function(i, oldval) { return '//wikikids.wiki.kennisnet.nl' + oldval } );
  }
} );

// ============================================================
	// BEGIN Dynamisch inklapbare div
 
	// set up the words in your language
	var UitklapDivHide = 'Inklappen';
	var UitklapDivShow = 'Uitklappen';
 
	// shows and hides content of Uitklap divs
	// Parameters:
	// indexUitklapDiv: the index of Uitklap div to be toggled
	var toggleUitklapDiv = window.toggleUitklapDiv = function(indexUitklapDiv) {
		var UitklapToggle = document.getElementById('UitklapToggle' + indexUitklapDiv);
		var UitklapFrame = document.getElementById('UitklapFrame' + indexUitklapDiv);
		var UitklapChild;
 
		if (!UitklapFrame || !UitklapToggle) {
			return false;
		}
 
		// if shown now
		if (UitklapToggle.firstChild.data === UitklapDivHide) {
			for (
				UitklapChild = UitklapFrame.firstChild;
				UitklapChild !== null;
				UitklapChild = UitklapChild.nextSibling
			) {
				if (UitklapChild.className === 'UitklapContent') {
					UitklapChild.style.display = 'none';
				}
				if (UitklapChild.className === 'UitklapToggle') {
					UitklapChild.firstChild.data = UitklapDivShow;
				}
			}
 
		// if hidden now
		} else if (UitklapToggle.firstChild.data === UitklapDivShow) {
			for (
				UitklapChild = UitklapFrame.firstChild;
				UitklapChild !== null;
				UitklapChild = UitklapChild.nextSibling
			) {
				if (UitklapChild.className === 'UitklapContent') {
					UitklapChild.style.display = 'block';
				}
				if (UitklapChild.className === 'UitklapToggle') {
					UitklapChild.firstChild.data = UitklapDivHide;
				}
			}
		}
	};
 
	// adds show/hide-button to navigation bars
	function createUitklapDivToggleButton() {
		var indexUitklapDiv = 0;
		var i, u, UitklapFrame;
		// iterate over all < div >-elements
		for (i = 0; (UitklapFrame = document.getElementsByTagName('div')[i]); i++) {
			// if found a navigation bar
			if (UitklapFrame.className === 'UitklapFrame' || UitklapFrame.className === 'UitklapFrameNoClear') {
 
				indexUitklapDiv++;
				var UitklapToggle = document.createElement('a');
				UitklapToggle.className = 'UitklapToggle';
				UitklapToggle.setAttribute('id', 'UitklapToggle' + indexUitklapDiv);
				$(UitklapToggle).data('mwUitklapFrameIndex', indexUitklapDiv).click(function (e) {
					toggleUitklapDiv($(this).data('mwUitklapFrameIndex'));
					e.preventDefault();
				});
 
				var UitklapToggleText = document.createTextNode(UitklapDivHide);
				UitklapToggle.appendChild(UitklapToggleText);
 
				// add NavToggle-Button as first div-element
				// in < div class="UitklapFrame" >
				UitklapFrame.insertBefore(UitklapToggle, UitklapFrame.firstChild);
				UitklapFrame.setAttribute('id', 'UitklapFrame' + indexUitklapDiv);
			}
		}
		for (u = 1; u <= indexUitklapDiv; u++) {
			toggleUitklapDiv(u);
		}
	}
 
	$(createUitklapDivToggleButton);
 
	// EIND Dynamisch inklapbare div
	// ============================================================

/*</pre>*/
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=MediaWiki:Common.js&oldid=453353"