$(function(){
$(".input-group-btn .dropdown-menu li a").click(function(){
var selText = $(this).html();
//working version - for single button //
//$('.btn:first-child').html(selText+'<span class="caret"></sphttp://bootsnipp.com/user/snippets/Ov3q#an>');
//working version - for multiple buttons //
$(this).parents('.input-group-btn').find('.dropdown-toggle').html(selText+'<span class="caret"></span>');
});
});
function save_settings()
{
localStorage.setItem("navbar_name" , $( "#navbar_name" ).val());
localStorage.setItem("btn_theme", $( "#btn_theme" ).val());
localStorage.setItem("theme_name", $( "#theme_name" ).val());
localStorage.setItem("display_label",$('input[name="display_label"]:checked').val());
apply_preferences_to_page();
}
function load_settings()
{
var navbar_name = localStorage.getItem( "navbar_name" );
var btn_theme = localStorage.getItem( "btn_theme" );
var theme_name = localStorage.getItem( "theme_name" );
var display_label = localStorage.getItem( "display_label" );
$("#navbar_name").val(navbar_name);
$("#btn_theme").val(btn_theme);
$("#theme_name").val(theme_name);
$('input[name=display_label][value=display_label]').prop('checked', 'checked');
apply_preferences_to_page();
}
function apply_preferences_to_page()
{
var nav_theme = localStorage.getItem("nav_theme");
var btn_theme = localStorage.getItem("btn_theme");
var theme_name = localStorage.getItem("theme_name");
var display_label = localStorage.getItem("display_label");
$("#wrapper").attr("class",theme_name);
$("nav").attr("class", "navbar "+nav_theme);
$("div.navbar-btn button.btn").attr("class","btn "+btn_theme);
$('link[title="theme"]').attr('href','http://netdna.bootstrapcdn.com/bootswatch/3.1.0/'+theme_name+'/bootstrap.min.css');
$(".current-theme").html(theme_name);
$(".label-icon").attr("class","label-icon "+display_label);
display_preferences();
}
function display_preferences()
{
//the variable that will hold the results
var dataLog = "";
var i = 0;
//how many items are in the database starting with zero
var logLength = localStorage.length-1;
dataLog = "<thead><tr class='active'><th>Item Name</th><th>Item Data</th></tr></thead><tbody>"
//now we are going to loop through each item in the database
for (i = 0; i <= logLength; i++) {
//lets setup some variables for the key and values
var itemKey = localStorage.key(i);
var itemData = localStorage.getItem(itemKey);
//now that we have the item, lets add it to the table
dataLog += '<tr><td>'+itemKey+'</td><td>'+itemData+'</td></tr>';
}
//if there were no items in the database
if (dataLog == "")
dataLog = '<li class="empty">Log Currently Empty</li>';
//update the ul with the list items
$("#theLog").html(dataLog);
}
$(function()
{
load_settings();
$('form#preferences').submit(function(event){
event.preventDefault();
save_settings();
});
});