Difference between revisions 259992 and 272474 on ptwikibooks

// Copied from http://tools.wmflabs.org/meta/scripts/pathoschild.util.js
// See https://meta.wikimedia.org/wiki/TemplateScript
/*


A small library of self-contained helper methods used to create Pathoschild's MediaWiki user scripts.

For more information, see <https://github.com/Pathoschild/Wikimedia-contrib#readme>.


(contracted; show full)			 * Add a navigation menu portlet to the sidebar.
			 * @param {string} id The unique portlet ID.
			 * @param {string} name The display name displayed in the portlet header.
			 */
			AddPortlet: function (id, name) {
				// copy the portlet structure for the current skin
				var $sidebar = $('#p-tb').clone().attr('id', id);
				$sidebar.find('h
5').text(name);
				$sidebar.find('ul').empty();

				// if this is Vector, apply the collapsible magic (derived from the woefully-not-reusable https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/Vector.git;a=blob;f=modules/ext.vector.collapsibleNav.js )
				var vectorModules = mw.config.get('wgVectorEnabledModules');
				if (vectorModules && vectorModules.collapsiblenav) {
					var collapsed = $.cookie('vector-nav-' + id) === 'false';
					$sidebar
						.toggleClass('collapsed', collapsed)
						.toggleClass('expanded', !collapsed1, h2, h3, h4, h5').first().text(name);
						$sidebar.find('div:first').toggle(!collapsed);
				}

				// add to sidebarul').empty();
				$('#p-tb').parent().append($sidebar);

				return $sidebar;
			},

			/**
			 * Add a link to a navigation sidebar menu.
			 * @param {string} portletID The unique navigation portlet ID.
			 * @param {string} text The link text.
			 * @param {string|function} target The link URI or callback.
			 * @return
			 */
			AddPortletLink: function (portletID, text, target) {
				var isCallback = $.isFunction(target);
				var uri = isCallback ? '#' : target;
				var $link = $(mw.util.addPortletLink(portletID, uri, text));
				if (isCallback)
					$link.click(function (e) { e.preventDefault(); target(e); });

				return $link;
			}
		}
	};
}());