2015-03-15 12:56:28 +01:00
|
|
|
$(document).ready(function(){
|
2015-03-11 08:15:45 +01:00
|
|
|
//Creating functions
|
|
|
|
var generateList = function(){
|
|
|
|
var favStor = [];
|
|
|
|
for(var i=1; i<favorites.length+1; i++){
|
|
|
|
favStor.push($("#sortable > div:nth-child("+i+")").html());
|
|
|
|
}
|
2015-03-15 12:56:28 +01:00
|
|
|
return favStor;
|
2015-03-11 08:15:45 +01:00
|
|
|
} //This will generate a list of boards based off of the list on the screen
|
|
|
|
function removeBoard(boardNumber){
|
|
|
|
favorites.splice(boardNumber, 1);
|
|
|
|
localStorage.favorites = JSON.stringify(favorites);
|
|
|
|
$("#sortable > div:nth-child("+(boardNumber+1)+")").remove();
|
|
|
|
$("#minusList > div:nth-child("+(favorites.length+1)+")").remove();
|
2015-03-15 12:56:28 +01:00
|
|
|
add_favorites();
|
2015-03-11 08:15:45 +01:00
|
|
|
} //This removes a board from favorites, localStorage.favorites and the page
|
|
|
|
function addBoard(){
|
|
|
|
$("#sortable").append("<div>"+($("#plusBox").val())+"</div>");
|
2015-03-15 12:56:28 +01:00
|
|
|
$("#minusList").append( $('<div data-board="'+favorites.length+'" style="cursor: pointer; margin-right: 5px">-</div>').on('click', function(e){removeBoard($(this).data('board'));}) );
|
2015-03-11 08:15:45 +01:00
|
|
|
favorites.push($("#plusBox").val());
|
|
|
|
localStorage.favorites = JSON.stringify(favorites);
|
2015-03-15 12:56:28 +01:00
|
|
|
$("#plusBox").val(""); //Removing text from textbox
|
|
|
|
add_favorites();
|
2015-03-11 08:15:45 +01:00
|
|
|
} //This adds the text inside the textbox to favorites, localStorage.favorites and the page
|
|
|
|
|
2015-03-15 12:56:28 +01:00
|
|
|
var favorites = JSON.parse(localStorage.favorites);
|
|
|
|
Options.add_tab('fav-tab','star',_("Favorites"));
|
2015-03-11 08:15:45 +01:00
|
|
|
|
|
|
|
//Pregenerating list of boards
|
2015-03-15 12:56:28 +01:00
|
|
|
var favList = $('<div id="sortable" style="cursor: pointer; display: inline-block">');
|
2015-03-11 08:15:45 +01:00
|
|
|
for(var i=0; i<favorites.length; i++){
|
2015-03-15 12:56:28 +01:00
|
|
|
favList.append( $('<div>'+favorites[i]+'</div>') );
|
2015-03-11 08:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Creating list of minus symbols to remove unwanted boards
|
2015-03-15 12:56:28 +01:00
|
|
|
var minusList = $('<div id="minusList" style="color: #0000FF; display: inline-block">');
|
2015-03-11 08:15:45 +01:00
|
|
|
for(var i=0; i<favorites.length; i++){
|
2015-03-15 12:56:28 +01:00
|
|
|
minusList.append( $('<div data-board="'+i+'" style="cursor: pointer; margin-right: 5px">-</div>').on('click', function(e){removeBoard($(this).data('board'));}) );
|
2015-03-11 08:15:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Help message so people understand how sorting boards works
|
2015-03-15 12:56:28 +01:00
|
|
|
$("<span>"+_("Drag the boards to sort them.")+"</span><br><br>").appendTo(Options.get_tab('fav-tab').content);
|
2015-03-11 08:15:45 +01:00
|
|
|
|
|
|
|
//Adding list of boards and minus symbols to remove boards with
|
|
|
|
$(minusList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of minus symbols to the tab
|
2015-03-15 12:56:28 +01:00
|
|
|
$(favList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of favorite boards to the tab
|
2015-03-11 08:15:45 +01:00
|
|
|
|
|
|
|
//Adding spacing and text box to right boards into
|
2015-03-15 12:56:28 +01:00
|
|
|
var addDiv = $("<div id='favs-add-board'>");
|
|
|
|
|
|
|
|
var plusBox = $("<input id=\"plusBox\" type=\"text\">").appendTo(addDiv);
|
|
|
|
plusBox.keydown(function( event ) {
|
2015-03-11 08:15:45 +01:00
|
|
|
if(event.keyCode == 13){
|
|
|
|
$("#plus").click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//Adding plus symbol to use to add board
|
2015-03-15 12:56:28 +01:00
|
|
|
$("<div id=\"plus\">+</div>").css({
|
2015-03-11 08:15:45 +01:00
|
|
|
cursor: "pointer",
|
|
|
|
color: "#0000FF"
|
2015-03-15 12:56:28 +01:00
|
|
|
}).on('click', function(e){addBoard()}).appendTo(addDiv);
|
2015-03-11 08:15:45 +01:00
|
|
|
|
2015-03-15 12:56:28 +01:00
|
|
|
addDiv.appendTo(Options.get_tab('fav-tab').content); //Adding the plus button
|
2015-03-11 08:15:45 +01:00
|
|
|
|
2015-03-15 12:56:28 +01:00
|
|
|
favList.sortable(); //Making boards with sortable id use the sortable jquery function
|
|
|
|
favList.on('sortstop', function() {
|
|
|
|
favorites = generateList();
|
|
|
|
localStorage.favorites = JSON.stringify(favorites);
|
|
|
|
add_favorites();
|
|
|
|
});
|
2015-03-11 08:15:45 +01:00
|
|
|
});
|