mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 11:41:18 -04:00
commit all random stuff to repo
This commit is contained in:
156
static/candies/scripts/tabs.js
Executable file
156
static/candies/scripts/tabs.js
Executable file
@@ -0,0 +1,156 @@
|
||||
var tabs = {
|
||||
|
||||
// Variables
|
||||
length : 0, // Number of tabs
|
||||
list : new Array(), // List of tabs buttons
|
||||
active : 0, // Number of active tab
|
||||
lastKeyPress : 0, // blbl
|
||||
|
||||
// Functions
|
||||
|
||||
// Enable the tab ( display : inline on the tab )
|
||||
enable : function(n){
|
||||
if(this.list[n].enabled == false){
|
||||
this.list[n].enabled = true;
|
||||
this.list[n].button.css("display", "inline");
|
||||
}
|
||||
},
|
||||
|
||||
// Disable the tab ( display : none on the tab )
|
||||
disable : function(n){
|
||||
if(this.list[n].enabled == true){
|
||||
this.list[n].enabled = false;
|
||||
this.list[n].button.css("display", "none");
|
||||
}
|
||||
},
|
||||
|
||||
// Show the tab ( slideDown/show based on the animSlide variable )
|
||||
show : function(n){
|
||||
this.getTab(this.list[n].button).slideDown(200);
|
||||
},
|
||||
|
||||
// Hide the tab ( slideUp/hide based on the animSlide variable )
|
||||
hide : function(n){
|
||||
if(n == 1){ // If we're hiding the inventory tab, we try to leave all the maps
|
||||
objects.leave();
|
||||
}
|
||||
|
||||
this.getTab(this.list[n].button).slideUp(200);
|
||||
},
|
||||
|
||||
// Select the tab
|
||||
select : function(something){
|
||||
// Remove the class "active" on the last active tab
|
||||
this.list[this.active].button.removeClass("active");
|
||||
|
||||
// Get the new active tab
|
||||
this.active = something;
|
||||
|
||||
// For all tabs
|
||||
for(var i = 0; i < this.length; i++){
|
||||
// If the tab is the new active tab
|
||||
if(i == this.active){
|
||||
// Add the class "active" on the new active tab
|
||||
this.list[i].button.addClass("active");
|
||||
// Show that tab
|
||||
this.show(i);
|
||||
}
|
||||
// Else, hide that tab
|
||||
else
|
||||
this.hide(i);
|
||||
}
|
||||
},
|
||||
|
||||
// Next tab
|
||||
next : function(){
|
||||
var nextI = this.active;
|
||||
|
||||
for(var i = 0; i < this.length; i++){
|
||||
// We search the nextI
|
||||
nextI += 1;
|
||||
if(nextI == this.length)
|
||||
nextI = 0;
|
||||
// We select the next tab if possible
|
||||
if(this.list[nextI].enabled){
|
||||
this.select(nextI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Prev tab
|
||||
prev : function() {
|
||||
var prevI = this.active;
|
||||
|
||||
for(var i = this.length; i > 0; i--){
|
||||
// We search the nextI
|
||||
prevI -= 1;
|
||||
if(prevI == -1)
|
||||
prevI = this.length-1;
|
||||
// We select the next tab if possible
|
||||
if(this.list[prevI].enabled){
|
||||
this.select(prevI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Get the tab attribute
|
||||
getTab : function(something){
|
||||
return $("#"+something.attr("tab"));
|
||||
},
|
||||
|
||||
bindKey : function(){
|
||||
$("body").keydown( function(e) {
|
||||
var currentTime = new Date().getTime();
|
||||
|
||||
// Tabs keys
|
||||
if(currentTime - tabs.lastKeyPress > 50) {
|
||||
if(e.which == 39)
|
||||
tabs.next();
|
||||
else if(e.which == 37)
|
||||
tabs.prev();
|
||||
/*else
|
||||
alert("Code for Key Pressed : " + e.which);*/
|
||||
|
||||
tabs.lastKeyPress = currentTime;
|
||||
}
|
||||
|
||||
// Quest keys
|
||||
if(e.which == 73){
|
||||
hell.goUp();
|
||||
}
|
||||
else if(e.which == 75){
|
||||
hell.goDown();
|
||||
}
|
||||
|
||||
if(e.which == developperComputer.letter){
|
||||
developperComputer.useLetter();
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
//On Load
|
||||
onload : function(){
|
||||
// Get the number of tabs
|
||||
this.length = $("#tabs button").length;
|
||||
|
||||
// Generate the list of tabs buttons
|
||||
for(var i = 0; i < this.length; i++){
|
||||
this.list.push({button:$(".tab-" + i), enabled:true});
|
||||
this.disable(i);
|
||||
}
|
||||
|
||||
// Select the first tab
|
||||
this.select(0);
|
||||
|
||||
// Bind click event on all tabs to do select(that tab)
|
||||
for(var i = 0; i < this.length; i++){
|
||||
this.list[i].button.bind('click', tabs.select.bind(tabs, i));
|
||||
}
|
||||
|
||||
// Bind key
|
||||
this.bindKey();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user