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 mybutton = new OO.ui.ButtonWidget( {	framed: false,	icon: 'collapse',	label: 'scroll to top',	invisibleLabel: true,	title: 'Icon only',	id: 'mybtn', } ) $("#mybtn").css({"display": "none", "position": "fixed", "bottom": "80px", "right": "80px", "background-color": "lightslategray", "border-radius": "50px", "z-index": "1000"}); $('#content').append(mybutton.$element)

// When the user scrolls down 20px from the top of the document, show the button window.onscroll = function {scrollFunction};

function scrollFunction { console.log("scrolling") if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { console.log("display block") $("#mybtn").css({"display": "block","position": "fixed", "bottom": "80px", "right": "80px", "background-color": "lightslategray", "border-radius": "50px", "z-index": "1000"}); } else { $("#mybtn").css({"display": "none", "position": "fixed", "bottom": "80px", "right": "80px", "background-color": "lightslategray", "border-radius": "50px", "z-index": "1000"}); } }

// When the user clicks on the button, scroll to the top of the document function topFunction { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; }

mybutton.on( 'click', function {			topFunction;		} );

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: 'Contents',	invisibleLabel: true,	framed: false,	title: 'Contents',	classes: ['button-select'],	menu: {		items: items	} } ) $('#content').append(button.$element) // $(' .newClass { position: fixed; top: 170px; left: 140px; background-color: cadetblue; border-radius: 5px; z-index: 1000; } ').appendTo('.button-select'); // $(".button-select").css({ "position": "fixed" }; {"top": "170px"}; {"left": "140px"}; {"background-color": "cadetblue"};{ "border-radius": "5px"}; {"z-index": "1000"}); $(".button-select").css({ "position": "fixed", "top": "170px", "left": "140px", "background-color": "lightslategray", "border-radius": "50px", "z-index": "1000"}); 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; } ); } );

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