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

From Team Fortress Wiki
Jump to: navigation, search
m
m
 
(3 intermediate revisions by the same user not shown)
Line 33: Line 33:
 
});
 
});
 
mainMenu.append('<li>\
 
mainMenu.append('<li>\
<h3><span>'+th.children('h3').text()+' <img src="/w/images/d/d9/User_Lexar_black-arrow.png" /></span></h3>\
+
<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>\
 
<ul>\
 
'+listBuilder+'\
 
'+listBuilder+'\
Line 43: Line 43:
 
},
 
},
 
closeMenus:function(classless){
 
closeMenus:function(classless){
classless.removeClass('down out gone open');
+
for(i=0;i < classless.length;i++) {
 +
classless[i].removeClass('down out gone open');
 +
}
 
},
 
},
 
menuButtonClick:function(mainMenu,th) {
 
menuButtonClick:function(mainMenu,th) {
Line 74: Line 76:
 
ResponsiveJS.menuButtonClick(mainMenu,$(this));
 
ResponsiveJS.menuButtonClick(mainMenu,$(this));
 
 
ResponsiveJS.closeMenus($(pageMenu,pageList,accountMenu,accountList,menuSearch,openSearch));
+
ResponsiveJS.closeMenus([pageMenu,pageList,accountMenu,accountList,menuSearch,openSearch]);
 
 
 
//pageMenu.removeClass('down out gone open')
 
//pageMenu.removeClass('down out gone open')
Line 104: Line 106:
 
accountMenu.delay(400).show(0);
 
accountMenu.delay(400).show(0);
 
}
 
}
pageMenu.removeClass('down');
+
pageList.removeClass('down');
+
ResponsiveJS.closeMenus([pageList,accountList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
accountMenu.removeClass('down');
+
accountList.removeClass('down');
 
mainMenu.removeClass('down');
 
mainMenu.find('ul').removeClass('open');
 
 
mobileMenuButton.removeClass('active');
 
mobileMenuButton.removeClass('active');
mainMenu.find('li h3').removeClass('down');
 
 
});
 
});
 
pageMenu.click(function(){
 
pageMenu.click(function(){
 
ResponsiveJS.openMenu(pageList,$(this));
 
ResponsiveJS.openMenu(pageList,$(this));
 
 
accountMenu.removeClass('down');
+
ResponsiveJS.closeMenus([accountMenu,accountList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
accountList.removeClass('down');
+
mainMenu.removeClass('down');
 
mainMenu.find('ul').removeClass('open');
 
 
mobileMenuButton.removeClass('active');
 
mobileMenuButton.removeClass('active');
mainMenu.find('li h3').removeClass('down');
 
 
});
 
});
 
accountMenu.click(function(){
 
accountMenu.click(function(){
 
ResponsiveJS.openMenu(accountList,$(this));
 
ResponsiveJS.openMenu(accountList,$(this));
 
 
pageMenu.removeClass('down');
+
ResponsiveJS.closeMenus([pageMenu,pageList,mainMenu,mainMenu.find('ul'),mainMenu.find('li h3')]);
pageList.removeClass('down');
+
mainMenu.removeClass('down');
 
mainMenu.find('ul').removeClass('open');
 
 
mobileMenuButton.removeClass('active');
 
mobileMenuButton.removeClass('active');
mainMenu.find('li h3').removeClass('down');
 
 
});
 
});
 
},
 
},

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