From 86d99b332b4ac83e5211ebf26d5c52ae3a8a1e2c Mon Sep 17 00:00:00 2001 From: Fredrick Brennan Date: Sun, 15 Mar 2015 19:56:28 +0800 Subject: [PATCH] Make js/options/favs.js actually usable I pretty much had to rework this completely to get it into a usable state Reference ctrlcctrlv/infinity#424 --- inc/instance-config.php | 3 +- js/options/fav.js | 76 +++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/inc/instance-config.php b/inc/instance-config.php index 4d463751..a2dad456 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -116,6 +116,7 @@ $config['additional_javascript'][] = 'js/auto-reload.js'; $config['additional_javascript'][] = 'js/options/user-css.js'; $config['additional_javascript'][] = 'js/options/user-js.js'; + $config['additional_javascript'][] = 'js/options/fav.js'; $config['additional_javascript'][] = 'js/forced-anon.js'; $config['additional_javascript'][] = 'js/toggle-locked-threads.js'; $config['additional_javascript'][] = 'js/toggle-images.js'; @@ -152,7 +153,7 @@ $config['additional_javascript'][] = 'js/wPaint/plugins/file/wPaint.menu.main.file.min.js'; $config['additional_javascript'][] = 'js/wpaint.js'; // Code tags (fix because we no longer have different scripts for each board) - $config['additional_javascript'][] = 'js/code_tags/run_prettify.js'; + //$config['additional_javascript'][] = 'js/code_tags/run_prettify.js'; //$config['font_awesome_css'] = '/netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css'; diff --git a/js/options/fav.js b/js/options/fav.js index f8d12bf3..17ccb337 100644 --- a/js/options/fav.js +++ b/js/options/fav.js @@ -1,94 +1,72 @@ -//Setting global variables -var favorites = JSON.parse(localStorage.favorites); -Options.add_tab('fav-tab','star',_("Favorites")); - +$(document).ready(function(){ //Creating functions var generateList = function(){ var favStor = []; for(var i=1; i div:nth-child("+i+")").html()); } - return JSON.stringify(favStor); + return 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(); + add_favorites(); } //This removes a board from favorites, localStorage.favorites and the page function addBoard(){ $("#sortable").append("
"+($("#plusBox").val())+"
"); - $("#minusList").append("
-
"); + $("#minusList").append( $('
-
').on('click', function(e){removeBoard($(this).data('board'));}) ); 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 + $("#plusBox").val(""); //Removing text from textbox + add_favorites(); } //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(){ +var favorites = JSON.parse(localStorage.favorites); +Options.add_tab('fav-tab','star',_("Favorites")); //Pregenerating list of boards -var favList = ['
']; +var favList = $('
'); for(var i=0; i'; + favList.append( $('
'+favorites[i]+'
') ); } -favList += '
'; //Creating list of minus symbols to remove unwanted boards -var minusList = ['
']; +var minusList = $('
'); for(var i=0; i-
'; + minusList.append( $('
-
').on('click', function(e){removeBoard($(this).data('board'));}) ); } -minusList += "
"; //Help message so people understand how sorting boards works -$("Drag the boards to sort them.

").appendTo(Options.get_tab('fav-tab').content); +$(""+_("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 +$(favList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of favorite boards 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 ) { +var addDiv = $("
"); + +var plusBox = $("").appendTo(addDiv); +plusBox.keydown(function( event ) { if(event.keyCode == 13){ $("#plus").click(); } }); //Adding plus symbol to use to add board -$("
+
").css({ +$("
+
").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 +}).on('click', function(e){addBoard()}).appendTo(addDiv); -$("#sortable").sortable(); //Making boards with sortable id use the sortable jquery function +addDiv.appendTo(Options.get_tab('fav-tab').content); //Adding the plus button +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(); +}); });