MediaWiki:PopularPagesModule/code.js

/** * PopularPagesModule * * Adds a module to the right rail featuring a list of popular pages as defined by the community. * * * Can be configured through the "popularPages" global variable. * "loadOnNamespaces": An array of the namespaces the module is loaded on. * "sections": An array of the sections the module will feature. Each section has a header and a list of articles. ** "header": The header of the section. ** "items": An array of the list of articles the section features. *** "title": The name of the page. *** "url": The URL to the page. * Clicks on the links inthe module are tracked through the "ja-popularpages-module" category in Google Analytics. $(function {	if (($.inArray(mw.config.get('wgNamespaceNumber'), popularPages.loadOnNamespaces) > -1) && !mw.config.get('wgIsMainPage')) {		checkRightRail = setInterval(addModulesToRail, 250);	} }); function addModulesToRail { var hasRailLoaded = $("#WikiaRail .module").length > 0; if (hasRailLoaded) { clearInterval(checkRightRail); addPopularPagesModule; } } function addPopularPagesModule { var moduleHtml = $(' '); $.each(popularPages.sections, function(index, value) {		var sectionHtml = $('' + value.header + ' ');		if(index > 0) {			sectionHtml.closest('h2').css('margin-top', '25px');		}		var sectionList = sectionHtml.closest('ol');		$.each(value.items, function(index, value) { var itemHtml = $(''); var link = itemHtml.find('a'); link.attr('href', value.url); link.text(value.title); sectionList.append(itemHtml); });		moduleHtml.append(sectionHtml);	}); $('#WikiaRail .WikiaActivityModule').after(moduleHtml); addClickTrackingToModule; } function addClickTrackingToModule { var track = Wikia.Tracker.buildTrackingFunction({		category: 'ja-popularpages-module',		action: Wikia.Tracker.ACTIONS.CLICK,		trackingMethod: 'analytics'	}); var popularPagesModule = $('#WikiaRail .PopularPagesModule'); popularPagesModule.on('mousedown', 'a', function(e) {		var href = $(this).attr('href');		track({ browserEvent: e,			label: href });	}); }