Welcome to the DFO World Wiki. With many major updates since the release of DFO, many items are missing. Visit Item Database Project to learn more.
Please remember to click "show preview" before saving the page.
Thanks for the updated logo snafuPop!

MediaWiki:Gadget-editDropdown.js

From DFO World Wiki
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/**
 ** @description
 **   adds a method to mw.libs that allows adding collapsed menu items to the edit-tab
 **   a drop-down will be added to the edit-tab while first usage
 **   it works like the p-cactions menu in vector
 **   If the skin is not vector, the items will be added to the p-tb (toolbox)
 ** @example
     mw.loader.using('ext.gadget.editDropdown', function() {
		mw.libs.commons.ui.addEditLink(
			'//tools.wmflabs.org', 
			"Wikimedia Tool Labs", 
			'p-Toollink', 
			"Wikimedia Tool Labs. Driven by Wikimedia Foundation"
		);
     });
 **
 ** @compatability
 **  Works in recent browsers; Menu not visible in IE6/7 and therefore they go to the toolbox
 **
 ** @author
 **  Rainer Rillke, 2012
 **
 ** @license
 **  GPL v.3
**/

/*global jQuery:false, mediaWiki:false*/
/*jshint curly:false */
(function($, mw) {
	'use strict';
	var isInit = false;
	
	if (!mw.libs.commons) mw.libs.commons = {};
	if (!mw.libs.commons.ui) mw.libs.commons.ui = {};

	mw.libs.commons.ui.isEditLink = function() {
		return false;
	};
	
	mw.libs.commons.ui.addEditLink = function(href, text, id, tooltip, accesskey, nextnode, altPortletId) {
		if (!altPortletId) altPortletId = 'p-tb';

		var addToToolbox = function() {
			return mw.util.addPortletLink(altPortletId, href, text, id, tooltip, accesskey, nextnode);
		};
		if (mw.libs.commons.ui.isEditLink()) {
			if (!isInit) prepareVector();
			if (!isInit) {
				return addToToolbox();
			}
			return mw.util.addPortletLink('p-edit', href, text, id, tooltip, accesskey);
		} else {
			return addToToolbox();
		}
	};
	
	var prepareVector = function() {
		var $caEdit = $('#ca-edit'),
			$editMenu = $('<div>', { 'class': 'vectorMenu editMenu', id: 'p-edit' }),
			$ul = $('#p-cactions').find('menu ul').clone().text(''),
			isRTL = $('body').hasClass('rtl');
			
		// Check whether there is an edit-tab
		if (0 === $caEdit.length) return;
		
		// Generate an alternative heading (non-CSS browsers)
		$('<h3>').append($('<span>').text($caEdit.text()), $('<a>', { href: '#' })).appendTo($editMenu);

		// Create the drop-down and append it to our menu
		$('<div>', { 'class': 'menu' }).append($ul).appendTo($editMenu);
		
		// Finally add our menu to the edit-button
		var addMethod = isRTL ? 'prepend' : 'append';
		$caEdit.children('span:first')[addMethod]($editMenu);
		
		// If we are on file pages, prefill the menu with the "upload a new version"-link
		var $reUpload = $('#mw-imagepage-reupload-link');
		if ($reUpload.length) {
			mw.util.addPortletLink(
				'p-edit', 
				$reUpload.find('a').attr('href'), 
				$reUpload.find('a').first().text(), 
				'p-reupload'
			);
		}
		isInit = true;
	};
	
})(jQuery, mediaWiki);