Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3.  
  4. //declare a global variable
  5. var filterVal;
  6. //check if sessionStorage exists and if so, if there is a var called fillTerm
  7. //if not, set it to a default value (all)
  8.  
  9. $.getJSON('openingdata.json', function(data) {
  10. $.each(data, function(key, full){
  11. });
  12. });
  13.  
  14. if (sessionStorage && sessionStorage.getItem("filTerm")) {
  15. filterVal = sessionStorage.getItem("filTerm");
  16.  
  17. }
  18. else {
  19. filterVal = "all";
  20. sessionStorage.setItem("filTerm", filterVal);
  21. }
  22.  
  23.  
  24. //now let's attach some interaction to our buttons
  25. /*$(".searchBtn").on("click", function () {
  26. //get the value for our filter
  27. filterVal = $(this).attr("data-filter");
  28. //store it in the session storage
  29. sessionStorage.setItem("filTerm", filterVal);
  30. console.log(sessionStorage);
  31. console.log(filterVal);
  32. //call our view update function
  33. updateView();
  34. });*/
  35.  
  36. $("#searchBtn").on("click",function(){
  37. filterVal = $('#searchEntry').val();
  38. sessionStorage.setItem("filTerm", filterVal);
  39. updateView();
  40. });
  41.  
  42. $("#searchEntry").on("keypress",function(e){
  43. if (e.keyCode == 13) {
  44. filterVal = $('#searchEntry').val();
  45. sessionStorage.setItem("filTerm", filterVal);
  46. updateView();
  47. }
  48. });
  49.  
  50.  
  51.  
  52. //this is the function that manipulates the UI
  53. function updateView() {
  54. //default situation: all is visible
  55. if (!filterVal || filterVal === "all") {
  56. $('.filter').show();
  57. }
  58. //hide all and show filtered values
  59. else {
  60. $(".filter").hide();
  61. $('.filter').filter('.' + filterVal).show();
  62.  
  63. console.log("searchTerm");
  64. console.log("filterVal");
  65. }
  66. };
  67. //update the view when the page loads
  68. updateView();
  69.  
  70. });
  71. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement