Difference between revisions of "User:Lexar/Main Page/Template:Benjas/Page.js"

From Team Fortress Wiki
Jump to: navigation, search
m (just gotta test first.)
m
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
$('head').prepend('<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>');
+
var ResponsiveJS = {
$('#mw-content-text').addClass('main-area');
+
populateAccount:function(accountList){
 
+
$('#mw-head #p-personal > ul > li').each(function(){
var mobileMenu = $('#mobile-menu'), mobileMenuButton = $('#mobile-menu .mobile-menu-button'), pageMenu = $('#mobile-menu #page-menu'),
+
var th = $(this);
accountMenu = $('#mobile-menu #account-menu'), accountList = $('#mobile-menu #account-list'), pageList = $('#mobile-menu #tab-menu'),
+
accountList.append('<li><span>' + th.html() + '</span></li>');
menuSearch = $('#mobile-menu #p-search'), openSearch = $('#mobile-menu #search-expand'), mainMenu = $('#mobile-menu #mobile-ul-main');
+
});
 
+
$('#mw-head #p-personal > ul > li').each(function(){
+
$('#mw-head #p-personal > ul > li').each(function(){
var th = $(this);
+
var th = $(this);
accountList.append('<li><span>' + th.html() + '</span></li>');
+
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" id="main-menu-no-hover" /><img src="/w/images/3/34/User_Lexar_white-arrow.png" id="main-menu-hover" /></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);

Latest revision as of 12:00, 3 November 2014

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" id="main-menu-no-hover" /><img src="/w/images/3/34/User_Lexar_white-arrow.png" id="main-menu-hover" /></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);