Skip to content
Snippets Groups Projects
Commit 62130fc3 authored by CupCakeArmy's avatar CupCakeArmy
Browse files

Added Custom Menu Feature

parent 559ca9b1
No related branches found
No related tags found
No related merge requests found
...@@ -2,98 +2,115 @@ ...@@ -2,98 +2,115 @@
// Library for all tool actions // Library for all tool actions
var tools = { var tools = {
//Log Function & Utility Vars //Log Function & Utility Vars
alertNum: 0, alertNum: 0,
alertType: { alertType: {
's': 'alert-success', 's': 'alert-success',
'i': 'alert-info', 'i': 'alert-info',
'w': 'alert-warning', 'w': 'alert-warning',
'e': 'alert-danger' 'e': 'alert-danger'
}, },
log: function(msg, type, timeout){ log: function(msg, type, timeout) {
timeout = timeout || 5000; timeout = timeout || 5000;
tools.alertNum++; tools.alertNum++;
$('.alertCont').append('<div id="alertBox'+tools.alertNum+'" class="alert '+tools.alertType[type]+' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+msg+'</div>'); $('.alertCont').append('<div id="alertBox' + tools.alertNum + '" class="alert ' + tools.alertType[type] + ' alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' + msg + '</div>');
setTimeout(function(){ setTimeout(function() {
$('#alertBox'+tools.alertNum).alert('close'); $('#alertBox' + tools.alertNum).alert('close');
}, timeout); }, timeout);
console.log(msg); console.log(msg);
}, },
// Ajax loading gunction and getting the tools // Ajax loading gunction and getting the tools
curTool: '', curTool: '',
getTool: function(tool) { getTool: function(tool) {
//Setting home if no other tool is selected //Setting home if no other tool is selected
if(window.location.hash == '' || window.location.hash == null) if (window.location.hash == '' || window.location.hash == null)
window.location.hash = 'home'; window.location.hash = 'home';
// If tool is specfied, get it // If tool is specfied, get it
var nextTool = (tool && typeof tool != 'object')? tool : window.location.hash.slice(1); var nextTool = (tool && typeof tool != 'object') ? tool : window.location.hash.slice(1);
if(tools.curTool == nextTool) if (tools.curTool == nextTool)
return; return;
tools.curTool = nextTool; tools.curTool = nextTool;
window.location.hash = tools.curTool; window.location.hash = tools.curTool;
$('#wheel-logo').css('transform', 'rotate(360deg)'); $('#wheel-logo').css('transform', 'rotate(360deg)');
$('#main-content').fadeOut(100,function() { $('#main-content').fadeOut(100, function() {
$.ajax({ $.ajax({
url: 'tools/' + tools.curTool + '.tool', url: 'tools/' + tools.curTool + '.tool',
dataType: 'html', dataType: 'html',
error: function() { error: function() {
tools.log('Tool not found', 'e'); tools.log('Tool not found', 'e');
} }
}).done(function(data){ }).done(function(data) {
$('#main-content').html(data); $('#main-content').html(data);
tools.ui.resizeTool(); tools.ui.resizeTool();
$('#main-content').fadeIn(250,function() { $('#main-content').fadeIn(250, function() {
$('#wheel-logo').css('transform', 'rotate(0deg)'); $('#wheel-logo').css('transform', 'rotate(0deg)');
}); });
}); });
}); });
}, },
// UI Stuff // UI Stuff
ui: { ui: {
//Toggle the sidemenu //Toggle the sidemenu
toggleSideMenu: function(){ toggleSideMenu: function() {
$('.wrapper-main').toggleClass('toggled'); $('.wrapper-main').toggleClass('toggled');
}, },
login: function(){ login: function() {
$('.loginPanel').css({'top':'-100%'}); $('.loginPanel').css({
}, 'top': '-100%'
logout: function(){ });
$('.loginPanel').css({'top':'0%'}); },
}, logout: function() {
resizeTool: function(){ $('.loginPanel').css({
console.log('Resizing'); 'top': '0%'
$('tools-full-height').height( $(window).height() - $('.navbar-main').height() ); });
} },
}, resizeTool: function() {
$('tools-full-height').height($(window).height() - $('.navbar-main').height());
// Memory to store stuff },
memStore: function(type, name, val){ menuId: 0,
window[type].setItem(name, val); menu: function(attr) {
}, var custMenu = $('.cust-menu');
memGet: function(type, name){ custMenu.html('');
return window[type].getItem(name); tools.ui.menuId++;
}, for (var cur in attr) {
mem: { if (attr[cur].link == '' || attr[cur].link === undefined)
local: { attr[cur].link = 'javascript:void(0);';
set: function(name, val){ custMenu.append('<li><a href="' + attr[cur].link + '" id="cust-menu-link-' + tools.ui.menuId + '">' + cur + '</a></li>');
tools.memStore('localStorage', tools.curTool+name, val); if (typeof(attr[cur].callback) == 'function')
}, $('#cust-menu-link-' + tools.ui.menuId).click(attr[cur].callback);
get: function(name){ }
return tools.memGet('localStorage', tools.curTool+name);
}, }
}, },
session: {
set: function(name, val){ // Memory to store stuff
tools.memStore('sessionStorage', tools.curTool+name, val); memStore: function(type, name, val) {
}, window[type].setItem(name, val);
get: function(name){ },
return tools.memGet('sessionStorage', tools.curTool+name); memGet: function(type, name) {
}, return window[type].getItem(name);
} },
} mem: {
local: {
set: function(name, val) {
tools.memStore('localStorage', tools.curTool + name, val);
},
get: function(name) {
return tools.memGet('localStorage', tools.curTool + name);
},
},
session: {
set: function(name, val) {
tools.memStore('sessionStorage', tools.curTool + name, val);
},
get: function(name) {
return tools.memGet('sessionStorage', tools.curTool + name);
},
}
}
} }
/* /*
...@@ -103,36 +120,33 @@ var tools = { ...@@ -103,36 +120,33 @@ var tools = {
//Binding tool change whenever the hash is changed //Binding tool change whenever the hash is changed
window.onhashchange = tools.getTool; window.onhashchange = tools.getTool;
// Login function // Login function
function loginFunc(){ function loginFunc() {
$('.loginPanel input').attr('readonly', 1); $('.loginPanel input').attr('readonly', 1);
amivcore.login($('#loginUsername').val(),$('#loginPassword').val(), function(ret){ amivcore.login($('#loginUsername').val(), $('#loginPassword').val(), function(ret) {
if(ret !== true) if (ret !== true)
tools.log('Wrong Credentials', 'w'); tools.log('Wrong Credentials', 'w');
$('.loginPanel input').removeAttr('readonly'); $('.loginPanel input').removeAttr('readonly');
}); });
} }
// Binding the buttons // Binding the buttons
$('.toggleSidebarBtn').click(tools.ui.toggleSideMenu); $('.toggleSidebarBtn').click(tools.ui.toggleSideMenu);
$('.loginAction').click(loginFunc); $('.loginAction').click(loginFunc);
$('.logoutAction').click(amivcore.logout); $('.logoutAction').click(amivcore.logout);
$('.loginPanel').keypress(function(e){ $('.loginPanel').keypress(function(e) {
if(e.which == 13){ if (e.which == 13) {
e.preventDefault(); e.preventDefault();
loginFunc(); loginFunc();
} }
}) })
window.onresize = tools.ui.resizeTools; amivcore.on('ready', function() {
tools.getTool();
amivcore.on('ready', function(){ });
tools.getTool(); amivcore.on('login', function() {
tools.ui.login();
}); });
amivcore.on('login', function(){ amivcore.on('logout', function() {
tools.ui.login(); tools.ui.logout();
}); });
amivcore.on('logout', function(){
tools.ui.logout();
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment