User:Gauransh Dingwani/common.js

function loadScripts(scripts) { console.log("here") var deferreds = []; $.each(scripts, function (i, script) {		// External script, use $.getScript		if (script.match(/^(https?:|\/\/)/)) {			deferreds.push($.getScript(script));		// Use mw.using, convert callbacks to Deferreds		} else {			var d = $.Deferred;			// TODO: make only one mw.loader.using call, passing an array of module names			mw.loader.using(script, d.resolve, d.reject);			deferreds.push(d);		}	}); return $.when.apply($, deferreds); }

var requires = [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-toolbars', 'oojs-ui-windows', 'oojs-ui.styles.icons-interactions', ];

loadScripts(requires).done(function {

hasContents = $( '.toc').length > 0; numContent = $('.toclevel-1').length;

console.log(hasContents) console.log(numContent)

$(".toclevel-1").each(function {   console.log($(this).children);    console.log($(this).children[0].href);    console.log($(this).children[0].children[0].innerText);    console.log($(this).children[0].children[1].innerText); }); var items = []; $(".toclevel-1").each(function {   var button = new OO.ui.ButtonWidget( { framed: false, flags: [ $(this).children[0].children[1].innerText ],	label: $(this).children[0].children[0].innerText + ' ' + $(this).children[0].children[1].innerText, href: $(this).children[0].href, } ); items.push(button); }); var button = new OO.ui.ButtonMenuSelectWidget( {	icon: 'ellipsis',	label: 'More options',	invisibleLabel: true,	framed: false,	title: 'More options',	menu: {		items: items	} } ) $('#content').append(button.$element) } );

// When using the `clearOnSelect` option, listen to the `choose` event // to avoid getting the null select event. // buttonMenu.getMenu.on( 'choose', function ( menuOption ) { //   console.log( menuOption.getData ); // } ); // });