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.MenuOptionWidget( { // framed: false, // flags: [ // 	$(this).children[0].children[1].innerText // ],	label: $(this).children[0].children[0].innerText + ' ' + $(this).children[0].children[1].innerText, data: $(this).children[0].href, } ); // button.on( 'click', function { // 			alert( 'You clicked the button!' ); // 		} ); items.push(button); });

var button = new OO.ui.ButtonMenuSelectWidget( {	icon: 'ellipsis',	label: 'More options',	invisibleLabel: true,	framed: false,	title: 'More options',	classes: ['button-select'],	align: 'backwards',	menu: {		items: items	} } ) $('#content').append(button.$element) button.getMenu.on( 'choose', function ( menuOption ) {   console.log( menuOption.getData );	var url = menuOption.getData;    // history.push(menuOption.getData);    // history.pushState({urlPath:url},"",url)    $(".button-select").css({ "position": "fixed" } );    console.log($(".button-select"));    console.log($('.toclevel-1').length);    console.log($('#content'));    window.location.href = url;    // $(' .newClass { position: fixed; top: 170px; left: 140px; background-color: cadetblue; border-radius: 5px; z-index: 1000; } ').appendTo('.button-select'); } ); } );

// 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 ); // } ); // });