From 6cb3039b71c30ad9db03847f512b898d9a5224b5 Mon Sep 17 00:00:00 2001 From: Harry Hackett Date: Wed, 11 Mar 2015 20:15:45 +1300 Subject: [PATCH] Create fav.js --- js/options/fav.js | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 js/options/fav.js diff --git a/js/options/fav.js b/js/options/fav.js new file mode 100644 index 00000000..f8d12bf3 --- /dev/null +++ b/js/options/fav.js @@ -0,0 +1,94 @@ +//Setting global variables +var favorites = JSON.parse(localStorage.favorites); +Options.add_tab('fav-tab','star',_("Favorites")); + +//Creating functions +var generateList = function(){ + var favStor = []; + for(var i=1; i div:nth-child("+i+")").html()); + } + return JSON.stringify(favStor); +} //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(); +} //This removes a board from favorites, localStorage.favorites and the page +function addBoard(){ + $("#sortable").append("
"+($("#plusBox").val())+"
"); + $("#minusList").append("
-
"); + favorites.push($("#plusBox").val()); + localStorage.favorites = JSON.stringify(favorites); + $("#space").remove(); + $("#plusBox").remove(); //Refreshing the last 3 elements to move the box down + $("#plus").remove(); + $("#submitFavorites").remove(); + $("

").appendTo(Options.get_tab('fav-tab').content); + $("").appendTo(Options.get_tab('fav-tab').content); + $("#plusBox").keydown(function( event ) { + if(event.keyCode == 13){ + $("#plus").click(); + } + }); //Adding enter to submit + document.getElementById("plusBox").value = ""; //Removing text from textbox + $("#plusBox").focus(); //Moving cursor into text box again after refresh + $("
+
").css({ + cursor: "pointer", + color: "#0000FF" + }).appendTo(Options.get_tab('fav-tab').content); //Adding the plus to the tab + $("").css({ + height: 25, bottom: 5, + width: "calc(100% - 10px)", + left: 5, right: 5 + }).appendTo(Options.get_tab('fav-tab').content); //Adding button to the tab +} //This adds the text inside the textbox to favorites, localStorage.favorites and the page + +//Making as many functions and variables non-global +$(document).ready(function(){ + +//Pregenerating list of boards +var favList = ['
']; +for(var i=0; i'; +} +favList += '
'; + +//Creating list of minus symbols to remove unwanted boards +var minusList = ['
']; +for(var i=0; i-
'; +} +minusList += ""; + +//Help message so people understand how sorting boards works +$("Drag the boards to sort them.

").appendTo(Options.get_tab('fav-tab').content); + +//Adding list of boards and minus symbols to remove boards with +$(favList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of favorite boards to the tab +$(minusList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of minus symbols to the tab + +//Adding spacing and text box to right boards into +$("

").appendTo(Options.get_tab('fav-tab').content); +$("").appendTo(Options.get_tab('fav-tab').content); +$("#plusBox").keydown(function( event ) { + if(event.keyCode == 13){ + $("#plus").click(); + } +}); + +//Adding plus symbol to use to add board +$("
+
").css({ + cursor: "pointer", + color: "#0000FF" +}).appendTo(Options.get_tab('fav-tab').content); //Adding the plus button +$("").css({ + height: 25, bottom: 5, + width: "calc(100% - 10px)", + left: 5, right: 5 +}).appendTo(Options.get_tab('fav-tab').content); //Adding submit button to the tab + +$("#sortable").sortable(); //Making boards with sortable id use the sortable jquery function + +});