The version of vichan running on lainchan.org
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

73 рядки
3.0KB

  1. $(document).ready(function(){
  2. //Creating functions
  3. var generateList = function(){
  4. var favStor = [];
  5. for(var i=1; i<favorites.length+1; i++){
  6. favStor.push($("#sortable > div:nth-child("+i+")").html());
  7. }
  8. return favStor;
  9. } //This will generate a list of boards based off of the list on the screen
  10. function removeBoard(boardNumber){
  11. favorites.splice(boardNumber, 1);
  12. localStorage.favorites = JSON.stringify(favorites);
  13. $("#sortable > div:nth-child("+(boardNumber+1)+")").remove();
  14. $("#minusList > div:nth-child("+(favorites.length+1)+")").remove();
  15. add_favorites();
  16. } //This removes a board from favorites, localStorage.favorites and the page
  17. function addBoard(){
  18. $("#sortable").append("<div>"+($("#plusBox").val())+"</div>");
  19. $("#minusList").append( $('<div data-board="'+favorites.length+'" style="cursor: pointer; margin-right: 5px">-</div>').on('click', function(e){removeBoard($(this).data('board'));}) );
  20. favorites.push($("#plusBox").val());
  21. localStorage.favorites = JSON.stringify(favorites);
  22. $("#plusBox").val(""); //Removing text from textbox
  23. add_favorites();
  24. } //This adds the text inside the textbox to favorites, localStorage.favorites and the page
  25. var favorites = JSON.parse(localStorage.favorites);
  26. Options.add_tab('fav-tab','star',_("Favorites"));
  27. //Pregenerating list of boards
  28. var favList = $('<div id="sortable" style="cursor: pointer; display: inline-block">');
  29. for(var i=0; i<favorites.length; i++){
  30. favList.append( $('<div>'+favorites[i]+'</div>') );
  31. }
  32. //Creating list of minus symbols to remove unwanted boards
  33. var minusList = $('<div id="minusList" style="color: #0000FF; display: inline-block">');
  34. for(var i=0; i<favorites.length; i++){
  35. minusList.append( $('<div data-board="'+i+'" style="cursor: pointer; margin-right: 5px">-</div>').on('click', function(e){removeBoard($(this).data('board'));}) );
  36. }
  37. //Help message so people understand how sorting boards works
  38. $("<span>"+_("Drag the boards to sort them.")+"</span><br><br>").appendTo(Options.get_tab('fav-tab').content);
  39. //Adding list of boards and minus symbols to remove boards with
  40. $(minusList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of minus symbols to the tab
  41. $(favList).appendTo(Options.get_tab('fav-tab').content); //Adding the list of favorite boards to the tab
  42. //Adding spacing and text box to right boards into
  43. var addDiv = $("<div id='favs-add-board'>");
  44. var plusBox = $("<input id=\"plusBox\" type=\"text\">").appendTo(addDiv);
  45. plusBox.keydown(function( event ) {
  46. if(event.keyCode == 13){
  47. $("#plus").click();
  48. }
  49. });
  50. //Adding plus symbol to use to add board
  51. $("<div id=\"plus\">+</div>").css({
  52. cursor: "pointer",
  53. color: "#0000FF"
  54. }).on('click', function(e){addBoard()}).appendTo(addDiv);
  55. addDiv.appendTo(Options.get_tab('fav-tab').content); //Adding the plus button
  56. favList.sortable(); //Making boards with sortable id use the sortable jquery function
  57. favList.on('sortstop', function() {
  58. favorites = generateList();
  59. localStorage.favorites = JSON.stringify(favorites);
  60. add_favorites();
  61. });
  62. });