User:Lexar/Main Page/Template:Benjas/Page.js

From Team Fortress Wiki
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var ResponsiveJS = {
	populateAccount:function(accountList){
		$('#mw-head #p-personal > ul > li').each(function(){
			var th = $(this);
			accountList.append('<li><span>' + th.html() + '</span></li>');
		});
		
		$('#mw-head #p-personal > ul > li').each(function(){
			var th = $(this);
			accountList.append('<li><span>' + th.html() + '</span></li>');
		});
	},
	populatePage:function(pageList){
		$('#left-navigation ul li').each(function(){
			var th = $(this);
			pageList.append('<li'+(th.hasClass('selected')?' class="selected"':'')+'>'+th.html()+'</li>');
		});
		$($('#right-navigation #p-cactions .menu ul li').get().reverse()).each(function(){
			var th = $(this);
			pageList.append('<li class="f-right'+(th.hasClass('selected')?' selected':'')+'">'+th.html()+'</li>');
		});
		$($('#right-navigation #p-views ul li').get().reverse()).each(function(){
			var th = $(this);
			pageList.append('<li class="f-right'+(th.hasClass('selected')?' selected':'')+'">'+th.html()+'</li>');
		});	
	},
	populateNav:function(mainMenu){
		$('#mw-panel .portal:not(#p-Languages)').each(function(){
			var th = $(this), listBuilder = '';
			th.find('div ul li').each(function(){
				var thi = $(this);
				listBuilder += '<li>'+thi.html()+'</li>';
			});
			mainMenu.append('<li>\
			<h3><span>'+th.children('h3').text()+' <img src="/w/images/d/d9/User_Lexar_black-arrow.png" /></span></h3>\
			<ul>\
			'+listBuilder+'\
			<li class="clearing"></li>\
			</ul>\
			<div class="clearing"></div>\
			</li>');
		});
	},
	closeMenus:function(classless){
		for(i=0;i < classless.length;i++) {
			classless[i].removeClass('down out gone open');
		}
	},
	menuButtonClick:function(mainMenu,th) {
		th.toggleClass('active');
		mainMenu.toggleClass('down');
		
		mainMenu.find('ul').removeClass('open');
		mainMenu.find('li h3').removeClass('down');
	},
	openSearchBar:function(menuSearch,th) {
		menuSearch.toggleClass('out');
		$('#simpleSearch').css('width',(($('#mobile-menu').width()*65)/100)+'px');
		th.toggleClass('out');
	},
	openMenu:function(Menu,th) {
		Menu.toggleClass('down');
		th.toggleClass('down');
	},
	menu:function(){
		var mobileMenu = $(this), mobileMenuButton = mobileMenu.find('.mobile-menu-button'), pageMenu = mobileMenu.find('#page-menu'),
		accountMenu = mobileMenu.find('#account-menu'), accountList = mobileMenu.find('#account-list'), pageList = mobileMenu.find('#tab-menu'),
		menuSearch = mobileMenu.find('#p-search'), openSearch = mobileMenu.find('#search-expand'), mainMenu = mobileMenu.find('#mobile-ul-main');
		
		ResponsiveJS.populateAccount(accountList);
		ResponsiveJS.populatePage(pageList);
		$('#right-navigation #p-search #searchform').clone().appendTo(menuSearch);
		ResponsiveJS.populateNav(mainMenu);
		
		mobileMenuButton.click(function(){
			ResponsiveJS.menuButtonClick(mainMenu,$(this));
			
			ResponsiveJS.closeMenus([pageMenu,pageList,accountMenu,accountList,menuSearch,openSearch]);
			
			//pageMenu.removeClass('down out gone open')
			pageMenu.delay(400).show(0);
			//pageList.removeClass('down out gone open');
			//accountMenu.removeClass('down out gone open')
			accountMenu.delay(400).show(0);
			//accountList.removeClass('down out gone open');
			//menuSearch.removeClass('down out gone open');
			//openSearch.removeClass('down out gone open');
		});
		
		$(document).on('click','#mobile-ul-main li h3',function(){
			$('#mobile-ul-main ul').removeClass('open');
			$('#mobile-ul-main li h3').removeClass('down');
			$(this).toggleClass('down').next('ul').addClass('open');
		});
		
		openSearch.click(function(){
			ResponsiveJS.openSearchBar(menuSearch,$(this));
			pageMenu.toggleClass('gone');
			accountMenu.toggleClass('gone');
			if(pageMenu.hasClass('gone')) {
				pageMenu.hide();
				accountMenu.hide();
			}
			else {
				pageMenu.delay(400).show(0);
				accountMenu.delay(400).show(0);
			}
			
			ResponsiveJS.closeMenus([pageList,accountList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
			
			mobileMenuButton.removeClass('active');
		});
		pageMenu.click(function(){
		 	ResponsiveJS.openMenu(pageList,$(this));
		 	
		 	ResponsiveJS.closeMenus([accountMenu,accountList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
		 	
			mobileMenuButton.removeClass('active');
		});
		accountMenu.click(function(){
		 	ResponsiveJS.openMenu(accountList,$(this));
		 	
			ResponsiveJS.closeMenus([pageMenu,pageList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
			
			mobileMenuButton.removeClass('active');
		});
	},
	init:function() {
		$('head').prepend('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>');
		$('#mw-content-text').addClass('main-area');
		$('#right-navigation ul li').addClass('collapsible');
		$('#mobile-menu').each(ResponsiveJS.menu);
	}
};
$(ResponsiveJS.init);