Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).ready(function () {
- //declare a global variable
- var filterVal;
- //check if sessionStorage exists and if so, if there is a var called fillTerm
- //if not, set it to a default value (all)
- $.getJSON('openingdata.json', function(data) {
- $.each(data, function(key, full){
- });
- });
- if (sessionStorage && sessionStorage.getItem("filTerm")) {
- filterVal = sessionStorage.getItem("filTerm");
- }
- else {
- filterVal = "all";
- sessionStorage.setItem("filTerm", filterVal);
- }
- //now let's attach some interaction to our buttons
- /*$(".searchBtn").on("click", function () {
- //get the value for our filter
- filterVal = $(this).attr("data-filter");
- //store it in the session storage
- sessionStorage.setItem("filTerm", filterVal);
- console.log(sessionStorage);
- console.log(filterVal);
- //call our view update function
- updateView();
- });*/
- $("#searchBtn").on("click",function(){
- filterVal = $('#searchEntry').val();
- sessionStorage.setItem("filTerm", filterVal);
- updateView();
- });
- $("#searchEntry").on("keypress",function(e){
- if (e.keyCode == 13) {
- filterVal = $('#searchEntry').val();
- sessionStorage.setItem("filTerm", filterVal);
- updateView();
- }
- });
- //this is the function that manipulates the UI
- function updateView() {
- //default situation: all is visible
- if (!filterVal || filterVal === "all") {
- $('.filter').show();
- }
- //hide all and show filtered values
- else {
- $(".filter").hide();
- $('.filter').filter('.' + filterVal).show();
- console.log("searchTerm");
- console.log("filterVal");
- }
- };
- //update the view when the page loads
- updateView();
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement