app.js 34 KB
Newer Older
f3brysan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
/*=========================================================================================
  File Name: app.js
  Description: Template related app JS.
  ----------------------------------------------------------------------------------------
  Item Name: Frest HTML Admin Template
  Version: 1.0
  Author: Pixinvent
  Author URL: hhttp://www.themeforest.net/user/pixinvent
==========================================================================================*/

; (function (window, document, $) {
  "use strict"
  var $html = $("html")
  var $body = $("body")
  var $danger = "#FF5B5C"
  var $primary = "#5A8DEE"
  var $primary_lighten = "#e7edf3"
  var $warning = "#FDAC41"
  var $textcolor = "#304156"

  function scrollTopFn(){
    var $scrollTop = $(window).scrollTop();
    if ($scrollTop > 60) {
      $("body").addClass("navbar-scrolled");
    }else{
      $("body").removeClass("navbar-scrolled");
    }
    if ($scrollTop > 20) {
      $("body").addClass("page-scrolled");
    }
    else{
      $("body").removeClass("page-scrolled");
    }
  }
  $(window).scroll(function () {
    scrollTopFn();
  });

  $(window).on("load", function () {
    var rtl
    var compactMenu = false // Set it to true, if you want default menu to be compact

    if ($body.hasClass("menu-collapsed")) {
      compactMenu = true
    }

    if ($("html").data("textdirection") == "rtl") {
      rtl = true
    }

    setTimeout(function () {
      $html.removeClass("loading").addClass("loaded")
    }, 1200)

    $.app.menu.init(compactMenu)

    // Livioncs are initialized for vertical menu
    $.each($(".menu-livicon"), function (i) {
      var $this = $(this),
        icon = $this.data("icon"),
        iconStyle = $("#main-menu-navigation").data("icon-style")

      $this.addLiviconEvo({
        name: icon,
        style: iconStyle,
        duration: 0.85,
        strokeWidth: "1.3px",
        eventOn: "none",
        strokeColor: menuIconColorsObj.iconStrokeColor,
        solidColor: menuIconColorsObj.iconSolidColor,
        fillColor: menuIconColorsObj.iconFillColor,
        strokeColorAlt: menuIconColorsObj.iconStrokeColorAlt,
        afterAdd: function () {
          if (i === $(".main-menu-content .menu-livicon").length - 1) {
            // When hover over any menu item, start animation and stop all other animation
            $(".main-menu-content .nav-item a").on("mouseenter", function () {
              if ($(".main-menu-content .menu-livicon").length) {
                $(".main-menu-content .menu-livicon").stopLiviconEvo()
                $(this)
                  .find(".menu-livicon")
                  .playLiviconEvo()
              }
            })
          }
        }
      })
    })

    function updateLivicon(el) {
      el.updateLiviconEvo({
        strokeColor: menuActiveIconColorsObj.iconStrokeColor,
        solidColor: menuActiveIconColorsObj.iconSolidColor,
        fillColor: menuActiveIconColorsObj.iconFillColor,
        strokeColorAlt: menuActiveIconColorsObj.iconStrokeColorAlt
      })
    }

    // Navigation configurations
    var config = {
      speed: 300 // set speed to expand / collpase menu
    }
    if ($.app.nav.initialized === false) {
      $.app.nav.init(config)
    }

    Unison.on("change", function (bp) {
      $.app.menu.change(compactMenu)
    })

    // Tooltip Initialization
    $('[data-toggle="tooltip"]').tooltip({
      container: "body"
    })

    // Tooltip For Horizontal Layout - Bookmark Icons
    /* tooltip-horizontal-bookmark - Add Custom Class */
    $(".tooltip-horizontal-bookmark").tooltip({
      customClass: "tooltip-horizontal-bookmark"
    })

    // Top Navbars - Hide on Scroll
    if ($(".navbar-hide-on-scroll").length > 0) {
      $(".navbar-hide-on-scroll.fixed-top").headroom({
        offset: 205,
        tolerance: 5,
        classes: {
          // when element is initialised
          initial: "headroom",
          // when scrolling up
          pinned: "headroom--pinned-top",
          // when scrolling down
          unpinned: "headroom--unpinned-top"
        }
      })
      // Bottom Navbars - Hide on Scroll
      $(".navbar-hide-on-scroll.fixed-bottom").headroom({
        offset: 205,
        tolerance: 5,
        classes: {
          // when element is initialised
          initial: "headroom",
          // when scrolling up
          pinned: "headroom--pinned-bottom",
          // when scrolling down
          unpinned: "headroom--unpinned-bottom"
        }
      })
    }

    // Collapsible Card
    $('a[data-action="collapse"]').on("click", function (e) {
      e.preventDefault()
      $(this)
        .closest(".card")
        .children(".card-content")
        .collapse("toggle")
      // Adding bottom padding on card collapse
      $(this)
        .closest(".card")
        .children(".card-header")
        .css("padding-bottom", "1.5rem")
      $(this)
        .closest(".card")
        .find('[data-action="collapse"]')
        .toggleClass("rotate")
    })

    // Toggle fullscreen
    $('a[data-action="expand"]').on("click", function (e) {
      e.preventDefault()
      $(this)
        .closest(".card")
        .find('[data-action="expand"] i')
        .toggleClass("bx-fullscreen bx-exit-fullscreen")
      $(this)
        .closest(".card")
        .toggleClass("card-fullscreen")
    })

    //  Notifications & messages scrollable
    $(".scrollable-container").each(function () {
      var scrollable_container = new PerfectScrollbar($(this)[0], {
        wheelPropagation: false
      })
    })

    // Reload Card
    $('a[data-action="reload"]').on("click", function () {
      var block_ele = $(this)
        .closest(".card")
        .find(".card-content")
      var reloadActionOverlay
      if ($body.hasClass("dark-layout")) {
        var reloadActionOverlay = "#10163a"
      } else {
        var reloadActionOverlay = "#fff"
      }
      // Block Element
      block_ele.block({
        message:
          '<div class="bx bx-sync icon-spin font-medium-2 text-primary"></div>',
        timeout: 2000, //unblock after 2 seconds
        overlayCSS: {
          backgroundColor: reloadActionOverlay,
          cursor: "wait"
        },
        css: {
          border: 0,
          padding: 0,
          backgroundColor: "none"
        }
      })
    })

    // Close Card
    $('a[data-action="close"]').on("click", function () {
      $(this)
        .closest(".card")
        .removeClass()
        .slideUp("fast")
    })

    // Match the height of each card in a row
    setTimeout(function () {
      $(".row.match-height").each(function () {
        $(this)
          .find(".card")
          .not(".card .card")
          .matchHeight() // Not .card .card prevents collapsible cards from taking height
      })
    }, 500)

    $('.card .heading-elements a[data-action="collapse"]').on(
      "click",
      function () {
        var $this = $(this),
          card = $this.closest(".card")
        var cardHeight

        if (parseInt(card[0].style.height, 10) > 0) {
          cardHeight = card.css("height")
          card.css("height", "").attr("data-height", cardHeight)
        } else {
          if (card.data("height")) {
            cardHeight = card.data("height")
            card.css("height", cardHeight).attr("data-height", "")
          }
        }
      }
    )

    // Add sidebar group active class to active menu
    $(".main-menu-content")
      .find("li.active")
      .parents("li")
      .addClass("sidebar-group-active")

    // Update Active Menu item Icon with active color
    if ($(".nav-item.active .menu-livicon").length) {
      updateLivicon($(".nav-item.active .menu-livicon"))
    }

    // Update Active sidebar group menu icon with active ccolor
    if ($(".main-menu-content li.sidebar-group-active .menu-livicon").length) {
      updateLivicon(
        $(".main-menu-content li.sidebar-group-active .menu-livicon")
      )
    }

    // Add open class to parent list item if subitem is active except compact menu
    var menuType = $body.data("menu")
    if (menuType != "horizontal-menu" && compactMenu === false) {
      $(".main-menu-content")
        .find("li.active")
        .parents("li")
        .addClass("open")
    }
    if (menuType == "horizontal-menu") {
      $(".main-menu-content")
        .find("li.active")
        .parents("li:not(.nav-item)")
        .addClass("open")
      $(".main-menu-content")
        .find("li.active")
        .parents("li")
        .addClass("active")
    }

    //card heading actions buttons small screen support
    $(".heading-elements-toggle").on("click", function () {
      $(this)
        .next(".heading-elements")
        .toggleClass("visible")
    })

    //  Dynamic height for the chartjs div for the chart animations to work
    var chartjsDiv = $(".chartjs"),
      canvasHeight = chartjsDiv.children("canvas").attr("height")
    chartjsDiv.css("height", canvasHeight)

    if ($body.hasClass("boxed-layout")) {
      if ($body.hasClass("vertical-overlay-menu")) {
        var menuWidth = $(".main-menu").width()
        var contentPosition = $(".app-content").position().left
        var menuPositionAdjust = contentPosition - menuWidth
        if ($body.hasClass("menu-flipped")) {
          $(".main-menu").css("right", menuPositionAdjust + "px")
        } else {
          $(".main-menu").css("left", menuPositionAdjust + "px")
        }
      }
    }

    //Custom File Input
    $(".custom-file input").change(function (e) {
      $(this)
        .next(".custom-file-label")
        .html(e.target.files[0].name)
    })

    /* Text Area Counter Set Start */

    $(".char-textarea").on("keyup", function (event) {
      checkTextAreaMaxLength(this, event)
      // to later change text color in dark layout
      $(this).addClass("active")
    })

    /*
    Checks the MaxLength of the Textarea
    -----------------------------------------------------
    @prerequisite:  textBox = textarea dom element
            e = textarea event
                    length = Max length of characters
    */
    function checkTextAreaMaxLength(textBox, e) {
      var maxLength = parseInt($(textBox).data("length"))

      if (!checkSpecialKeys(e)) {
        if (textBox.value.length < maxLength - 1)
          textBox.value = textBox.value.substring(0, maxLength)
      }
      $(".char-count").html(textBox.value.length)

      if (textBox.value.length > maxLength) {
        $(".counter-value").css("background-color", $danger)
        $(".char-textarea").css("color", $danger)
        // to change text color after limit is maxedout out
        $(".char-textarea").addClass("max-limit")
      } else {
        $(".counter-value").css("background-color", $primary)
        $(".char-textarea").css("color", $textcolor)
        $(".char-textarea").removeClass("max-limit")
      }

      return true
    }
    /*
    Checks if the keyCode pressed is inside special chars
    -------------------------------------------------------
    @prerequisite:  e = e.keyCode object for the key pressed
    */
    function checkSpecialKeys(e) {
      if (
        e.keyCode != 8 &&
        e.keyCode != 46 &&
        e.keyCode != 37 &&
        e.keyCode != 38 &&
        e.keyCode != 39 &&
        e.keyCode != 40
      )
        return false
      else return true
    }

    $(".content-overlay").on("click", function () {
      $(".search-list").removeClass("show")
      $(".app-content").removeClass("show-overlay")
      $(".bookmark-wrapper .bookmark-input").removeClass("show")
    })

    // To show shadow in main menu when menu scrolls
    var container = document.getElementsByClassName("main-menu-content")
    if (container.length > 0) {
      container[0].addEventListener("ps-scroll-y", function () {
        if (
          $(this)
            .find(".ps__thumb-y")
            .position().top > 0
        ) {
          $(".shadow-bottom").css("display", "block")
        } else {
          $(".shadow-bottom").css("display", "none")
        }
      })
    }
  })

  // Hide overlay menu on content overlay click on small screens
  $(document).on("click", ".sidenav-overlay", function (e) {
    // Hide menu
    $.app.menu.hide()
    return false
  })

  // Execute below code only if we find hammer js for touch swipe feature on small screen
  if (typeof Hammer !== "undefined") {
    // Swipe menu gesture
    var swipeInElement = document.querySelector(".drag-target")

    if ($(swipeInElement).length > 0) {
      var swipeInMenu = new Hammer(swipeInElement)

      swipeInMenu.on("panright", function (ev) {
        if ($body.hasClass("vertical-overlay-menu")) {
          $.app.menu.open()
          return false
        }
      })
    }

    // menu swipe out gesture
    setTimeout(function () {
      var swipeOutElement = document.querySelector(".main-menu")
      var swipeOutMenu

      if ($(swipeOutElement).length > 0) {
        swipeOutMenu = new Hammer(swipeOutElement)

        swipeOutMenu.get("pan").set({
          direction: Hammer.DIRECTION_ALL,
          threshold: 100
        })

        swipeOutMenu.on("panleft", function (ev) {
          if ($body.hasClass("vertical-overlay-menu")) {
            $.app.menu.hide()
            return false
          }
        })
      }
    }, 300)

    // menu overlay swipe out gestrue
    var swipeOutOverlayElement = document.querySelector(".sidenav-overlay")

    if ($(swipeOutOverlayElement).length > 0) {
      var swipeOutOverlayMenu = new Hammer(swipeOutOverlayElement)

      swipeOutOverlayMenu.on("panleft", function (ev) {
        if ($body.hasClass("vertical-overlay-menu")) {
          $.app.menu.hide()
          return false
        }
      })
    }
  }

  $(document).on("click", ".menu-toggle, .modern-nav-toggle", function (e) {
    e.preventDefault()

    // Toggle menu
    $.app.menu.toggle()

    setTimeout(function () {
      $(window).trigger("resize")
    }, 200)

    if ($("#collapsed-sidebar").length > 0) {
      setTimeout(function () {
        if ($body.hasClass("menu-expanded") || $body.hasClass("menu-open")) {
          $("#collapsed-sidebar").prop("checked", false)
        } else {
          $("#collapsed-sidebar").prop("checked", true)
        }
      }, 1000)
    }

    // Hides dropdown on click of menu toggle
    // $('[data-toggle="dropdown"]').dropdown('hide');

    // Hides collapse dropdown on click of menu toggle
    if (
      $(
        ".vertical-overlay-menu .navbar-with-menu .navbar-container .navbar-collapse"
      ).hasClass("show")
    ) {
      $(
        ".vertical-overlay-menu .navbar-with-menu .navbar-container .navbar-collapse"
      ).removeClass("show")
    }

    return false
  })

  // Add Children Class
  $(".navigation")
    .find("li")
    .has("ul")
    .addClass("has-sub")

  $(".carousel").carousel({
    interval: 2000
  })

  // Page full screen
  $(".nav-link-expand").on("click", function (e) {
    if (typeof screenfull != "undefined") {
      if (screenfull.enabled) {
        screenfull.toggle()
      }
    }
  })
  if (typeof screenfull != "undefined") {
    if (screenfull.enabled) {
      $(document).on(screenfull.raw.fullscreenchange, function () {
        if (screenfull.isFullscreen) {
          $(".nav-link-expand")
            .find("i")
            .toggleClass("bx-exit-fullscreen bx-fullscreen")
          $("html").addClass("full-screen")
        } else {
          $(".nav-link-expand")
            .find("i")
            .toggleClass("bx-fullscreen bx-exit-fullscreen")
          $("html").removeClass("full-screen")
        }
      })
    }
  }
  $(document).ready(function () {
    /**********************************
     *   Form Wizard Step Icon
     **********************************/
    $(".step-icon").each(function () {
      var $this = $(this)
      if ($this.siblings("span.step").length > 0) {
        $this.siblings("span.step").empty()
        $(this).appendTo($(this).siblings("span.step"))
      }
    })
  })

  // Update manual scroller when window is resized
  $(window).resize(function () {
    $.app.menu.manualScroller.updateHeight()
    // To show shadow in main menu when menu scrolls
    var container = document.getElementsByClassName("main-menu-content")
    if (container.length > 0) {
      container[0].addEventListener("ps-scroll-y", function () {
        if (
          $(this)
            .find(".ps__thumb-y")
            .position().top > 0
        ) {
          $(".shadow-bottom").css("display", "block")
        } else {
          $(".shadow-bottom").css("display", "none")
        }
      })
    }
  })

  $("#sidebar-page-navigation").on("click", "a.nav-link", function (e) {
    e.preventDefault()
    e.stopPropagation()
    var $this = $(this),
      href = $this.attr("href")
    var offset = $(href).offset()
    var scrollto = offset.top - 80 // minus fixed header height
    $("html, body").animate(
      {
        scrollTop: scrollto
      },
      0
    )
    setTimeout(function () {
      $this
        .parent(".nav-item")
        .siblings(".nav-item")
        .children(".nav-link")
        .removeClass("active")
      $this.addClass("active")
    }, 100)
  })

  // main menu internationalization

  // init i18n and load language file
  i18next
    .use(window.i18nextXHRBackend)
    .init({
      debug: false,
      fallbackLng: "en",
      backend: {
        loadPath: "../../../app-assets/data/locales/{{lng}}.json"
      },
      returnObjects: true
    },
      function (err, t) {
        // resources have been loaded
        jqueryI18next.init(i18next, $)
      }
    )

  // change language according to data-language of dropdown item
  $(".dropdown-language .dropdown-item").on("click", function () {
    var $this = $(this)
    $this.siblings(".selected").removeClass("selected")
    $this.addClass("selected")
    var selectedLang = $this.text()
    var selectedFlag = $this.find(".flag-icon").attr("class")
    $("#dropdown-flag .selected-language").text(selectedLang)
    $("#dropdown-flag .flag-icon")
      .removeClass()
      .addClass(selectedFlag)
    var currentLanguage = $this.data("language")
    i18next.changeLanguage(currentLanguage, function (err, t) {
      $(".main-menu").localize()
    })
  })

  /********************* Bookmark & Search ***********************/
  // This variable is used for mouseenter and mouseleave events of search list
  var $filename = $(".search-input input").data("search")

  // Bookmark icon click
  $(".bookmark-wrapper .bookmark-star").on("click", function (e) {
    e.stopPropagation()
    $(".bookmark-wrapper .bookmark-input").toggleClass("show")
    $(".bookmark-wrapper .bookmark-input input").val("")
    $(".bookmark-wrapper .bookmark-input input").blur()
    $(".bookmark-wrapper .bookmark-input input").focus()
    $(".bookmark-wrapper .search-list").addClass("show")

    var arrList = $("ul.nav.navbar-nav.bookmark-icons li"),
      $arrList = "",
      $activeItemClass = ""

    $("ul.search-list li").remove()

    for (var i = 0; i < arrList.length; i++) {
      if (i === 0) {
        $activeItemClass = "current_item"
      } else {
        $activeItemClass = ""
      }
      $arrList +=
        '<li class="auto-suggestion d-flex align-items-center justify-content-between cursor-pointer ' +
        $activeItemClass +
        '">' +
        '<a class="d-flex align-items-center justify-content-between w-100" href=' +
        arrList[i].firstChild.href +
        ">" +
        '<div class="d-flex justify-content-start">' +
        '<span class="mr-75 ' +
        arrList[i].firstChild.firstChild.className +
        '"  data-icon="' +
        arrList[i].firstChild.firstChild.className +
        '"></span>' +
        "<span>" +
        arrList[i].firstChild.dataset.originalTitle +
        "</span>" +
        "</div>" +
        '<span class="float-right bookmark-icon bx bx-star warning"></span>' +
        "</a>" +
        "</li>"
    }
    $("ul.search-list").append($arrList)
  })

  // Navigation Search area Open
  $(".nav-link-search").on("click", function () {
    var $this = $(this)
    var searchInput = $(this)
      .parent(".nav-search")
      .find(".search-input")
    searchInput.addClass("open")
    $(".search-input input").focus()
    $(".search-input .search-list li").remove()
    $(".search-input .search-list").addClass("show")
    $(".bookmark-wrapper .bookmark-input").removeClass("show")
  })

  // Navigation Search area Close
  $(".search-input-close i").on("click", function () {
    var $this = $(this),
      searchInput = $(this).closest(".search-input")
    if (searchInput.hasClass("open")) {
      searchInput.removeClass("open")
      $(".search-input input").val("")
      $(".search-input input").blur()
      $(".search-input .search-list").removeClass("show")
      if ($(".app-content").hasClass("show-overlay")) {
        $(".app-content").removeClass("show-overlay")
      }
    }
  })

  // Navigation Search area Close on click of app-content
  $(".app-content").on("click", function () {
    var $this = $(".search-input-close"),
      searchInput = $($this).parent(".search-input")
    if (searchInput.hasClass("open")) {
      searchInput.removeClass("open")
    }
  })

  // Filter
  $(".search-input .input").on("keyup", function (e) {
    if (e.keyCode !== 38 && e.keyCode !== 40 && e.keyCode !== 13) {
      if (e.keyCode == 27) {
        $(".app-content").removeClass("show-overlay")
        $(".bookmark-input input").val("")
        $(".bookmark-input input").blur()
        $(".search-input input").val("")
        $(".search-input input").blur()
        $(".search-input").removeClass("open")
        if ($(".search-list").hasClass("show")) {
          $(this).removeClass("show")
          $(".search-input").removeClass("show")
        }
      }

      // Define variables
      var value = $(this)
        .val()
        .toLowerCase(), //get values of inout on keyup
        activeClass = "",
        bookmark = false,
        liList = $("ul.search-list li") // get all the list items of the search
      liList.remove()
      // To check if current is bookmark input
      if (
        $(this)
          .parent()
          .hasClass("bookmark-input")
      ) {
        bookmark = true
      }

      // If input value is blank
      if (value != "") {
        $(".app-content").addClass("show-overlay")

        // condition for bookmark and search input click
        if ($(".bookmark-input").focus()) {
          $(".bookmark-input .search-list").addClass("show")
        } else {
          $(".search-input .search-list").addClass("show")
          $(".bookmark-input .search-list").removeClass("show")
        }
        if (bookmark === false) {
          $(".search-input .search-list").addClass("show")
          $(".bookmark-input .search-list").removeClass("show")
        }

        var $startList = "",
          $otherList = "",
          $htmlList = "",
          $activeItemClass = "",
          $bookmarkIcon = "",
          a = 0

        // getting json data from file for search results
        $.getJSON("../../../app-assets/data/" + $filename + ".json", function (
          data
        ) {
          for (var i = 0; i < data.listItems.length; i++) {
            // if current is bookmark then give class to star icon
            if (bookmark === true) {
              activeClass = "" // resetting active bookmark class
              var arrList = $("ul.nav.navbar-nav.bookmark-icons li"),
                $arrList = ""
              // Loop to check if current seach value match with the bookmarks already there in navbar
              for (var j = 0; j < arrList.length; j++) {
                if (
                  data.listItems[i].name ===
                  arrList[j].firstChild.dataset.originalTitle
                ) {
                  activeClass = " warning"
                  break
                } else {
                  activeClass = ""
                }
              }
              $bookmarkIcon =
                '<span class="float-right bookmark-icon bx bx-star' +
                activeClass +
                '"></span>'
            }
            // Search list item start with entered letters and create list
            if (
              data.listItems[i].name.toLowerCase().indexOf(value) == 0 &&
              a < 10 || !(data.listItems[i].name.toLowerCase().indexOf(value) == 0) &&
              data.listItems[i].name.toLowerCase().indexOf(value) > -1 &&
              a < 10
            ) {
              if (a === 0) {
                $activeItemClass = "current_item"
              } else {
                $activeItemClass = ""
              }
              $startList +=
                '<li class="auto-suggestion d-flex align-items-center justify-content-between cursor-pointer ' +
                $activeItemClass +
                '">' +
                '<a class="d-flex align-items-center justify-content-between w-100" href=' +
                data.listItems[i].url +
                ">" +
                '<div class="d-flex justify-content-start">' +
                '<span class="mr-75 ' +
                data.listItems[i].icon +
                '" data-icon="' +
                data.listItems[i].icon +
                '"></span>' +
                "<span>" +
                data.listItems[i].name +
                "</span>" +
                "</div>" +
                $bookmarkIcon +
                "</a>" +
                "</li>"
              a++
            }
          }
          for (var i = 0; i < data.listItems.length; i++) {
            if (bookmark === true) {
              activeClass = "" // resetting active bookmark class
              var arrList = $("ul.nav.navbar-nav.bookmark-icons li"),
                $arrList = ""
              // Loop to check if current seach value match with the bookmarks already there in navbar
              for (var j = 0; j < arrList.length; j++) {
                if (
                  data.listItems[i].name ===
                  arrList[j].firstChild.dataset.originalTitle
                ) {
                  activeClass = " warning"
                } else {
                  activeClass = ""
                }
              }
              $bookmarkIcon =
                '<span class="float-right bookmark-icon bx bx-star' +
                activeClass +
                '"></span>'
            }
            // Search list item not start with letters and create list
            if (
              !(data.listItems[i].name.toLowerCase().indexOf(value) == 0) &&
              data.listItems[i].name.toLowerCase().indexOf(value) > -1 &&
              a < 10
            ) {
              if (a === 0) {
                $activeItemClass = "current_item"
              } else {
                $activeItemClass = ""
              }
              $otherList +=
                '<li class="auto-suggestion d-flex align-items-center justify-content-between cursor-pointer ' +
                $activeItemClass +
                '">' +
                '<a class="d-flex align-items-center justify-content-between w-100" href=' +
                data.listItems[i].url +
                ">" +
                '<div class="d-flex justify-content-start">' +
                '<span class="mr-75 ' +
                data.listItems[i].icon +
                '" data-icon="' +
                data.listItems[i].icon +
                '"></span>' +
                "<span>" +
                data.listItems[i].name +
                "</span>" +
                "</div>" +
                $bookmarkIcon +
                "</a>" +
                "</li>"
              a++
            }
          }
          if ($startList == "" && $otherList == "") {
            $otherList =
              '<li class="auto-suggestion d-flex align-items-center justify-content-between cursor-pointer">' +
              '<a class="d-flex align-items-center justify-content-between w-100">' +
              '<div class="d-flex justify-content-start">' +
              '<span class="mr-75 bx bx-error-circle"></span>' +
              "<span>No results found.</span>" +
              "</div>" +
              "</a>" +
              "</li>"
          }

          $htmlList = $startList.concat($otherList) // merging start with and other list
          $("ul.search-list").html($htmlList) // Appending list to <ul>
        })
      } else {
        if (bookmark === true) {
          var arrList = $("ul.nav.navbar-nav.bookmark-icons li"),
            $arrList = ""
          for (var i = 0; i < arrList.length; i++) {
            if (i === 0) {
              $activeItemClass = "current_item"
            } else {
              $activeItemClass = ""
            }
            $arrList +=
              '<li class="auto-suggestion d-flex align-items-center justify-content-between cursor-pointer">' +
              '<a class="d-flex align-items-center justify-content-between w-100" href=' +
              arrList[i].firstChild.href +
              ">" +
              '<div class="d-flex justify-content-start">' +
              '<span class="mr-75 ' +
              arrList[i].firstChild.firstChild.className +
              '"  data-icon="' +
              arrList[i].firstChild.firstChild.className +
              '"></span>' +
              "<span>" +
              arrList[i].firstChild.dataset.originalTitle +
              "</span>" +
              "</div>" +
              '<span class="float-right bookmark-icon bx bx-star warning"></span>' +
              "</a>" +
              "</li>"
          }
          $("ul.search-list").append($arrList)
        } else {
          // if search input blank, hide overlay
          if ($(".app-content").hasClass("show-overlay")) {
            $(".app-content").removeClass("show-overlay")
          }
          // If filter box is empty
          if ($(".search-list").hasClass("show")) {
            $(".search-list").removeClass("show")
          }
        }
      }
    }
  })

  // Add class on hover of the list
  $(document).on("mouseenter", ".search-list li", function (e) {
    $(this)
      .siblings()
      .removeClass("current_item")
    $(this).addClass("current_item")
  })
  $(document).on("click", ".search-list li", function (e) {
    e.stopPropagation()
  })

  $("html").on("click", function ($this) {
    if (!$($this.target).hasClass("bookmark-icon")) {
      if ($(".bookmark-input .search-list").hasClass("show")) {
        $(".bookmark-input .search-list").removeClass("show")
      }
      if ($(".bookmark-input").hasClass("show")) {
        $(".bookmark-input").removeClass("show")
      }
    }
  })

  // Favorite star click
  $(document).on(
    "click",
    ".bookmark-input .search-list .bookmark-icon",
    function (e) {
      e.stopPropagation()
      if ($(this).hasClass("warning")) {
        $(this).removeClass("warning")
        var arrList = $("ul.nav.navbar-nav.bookmark-icons li")
        for (var i = 0; i < arrList.length; i++) {
          if (
            arrList[i].firstChild.dataset.originalTitle ==
            $(this).parent()[0].innerText
          ) {
            arrList[i].remove()
          }
        }
        e.preventDefault()
      } else {
        var arrList = $("ul.nav.navbar-nav.bookmark-icons li")
        $(this).addClass("warning")
        e.preventDefault()
        var $url = $(this).parent()[0].href,
          $name = $(this).parent()[0].innerText,
          $icon = $(this).parent()[0].firstChild.firstChild.dataset.icon,
          $listItem = "",
          $listItemDropdown = ""
        $listItem =
          '<li class="nav-item d-none d-lg-block">' +
          '<a class="nav-link" href="' +
          $url +
          '" data-toggle="tooltip" data-placement="top" title="' +
          $name +
          '">' +
          '<i class="ficon ' +
          $icon +
          '"></i>' +
          "</a>" +
          "</li>"
        $("ul.nav.bookmark-icons").append($listItem)
        $('[data-toggle="tooltip"]').tooltip()
      }
    }
  )

  // If we use up key(38) Down key (40) or Enter key(13)
  $(window).on("keydown", function (e) {
    var $current = $(".search-list li.current_item"),
      $next,
      $prev
    if (e.keyCode === 40) {
      $next = $current.next()
      $current.removeClass("current_item")
      $current = $next.addClass("current_item")
    } else if (e.keyCode === 38) {
      $prev = $current.prev()
      $current.removeClass("current_item")
      $current = $prev.addClass("current_item")
    }

    if (e.keyCode === 13 && $(".search-list li.current_item").length > 0) {
      var selected_item = $(".search-list li.current_item a")
      window.location = selected_item.attr("href")
      $(selected_item).trigger("click")
    }
  })

  // Navbar Sticky - add classes on reload of page
  var $scrollTop = $(window).scrollTop()
  if ($scrollTop > 20) {
    $(".navbar-sticky .main-header-navbar").css({
      "background-color": "#ffff",
      "box-shadow": "-8px 12px 18px 0 rgba(25, 42, 70, 0.13)"
    })
    $(".navbar-static .main-header-navbar").css({
      "background-color": "transparent",
      "box-shadow": "none"
    })
  }

  // Navbar Sticky -  add classes on scroll down the page
  $(window).scroll(function () {
    if ($(this).scrollTop() > 20) {
      $(".navbar-sticky .main-header-navbar").css({
        "background-color": "#ffff",
        "box-shadow": "-8px 12px 18px 0 rgba(25, 42, 70, 0.13)"
      })
      $(".navbar-static .main-header-navbar").css({
        "background-color": "transparent",
        "box-shadow": "none"
      })
    } else {
      $(".navbar-sticky .main-header-navbar").css({
        "background-color": "#f2f4f4",
        "box-shadow": "none"
      })
      $(".navbar-static .main-header-navbar").css({
        "background-color": "transparent",
        "box-shadow": "none"
      })
    }
  })

  // Navbar Sticky - add classes on reload of page
  var $scrollTop = $(window).scrollTop()
  if ($scrollTop > 20) {
    $(".dark-layout.navbar-sticky .main-header-navbar").css({
      "background-color": "#272e48",
      "box-shadow": "rgba(26, 35, 59, .70) -8px 12px 18px 0px"
    })
  }

  // Navbar Sticky -  add classes on scroll down the page
  $(window).scroll(function () {
    if ($(this).scrollTop() > 20) {
      $(".dark-layout.navbar-sticky .main-header-navbar").css({
        "background-color": "#272e48",
        "box-shadow": "rgba(26, 35, 59, .70) -8px 12px 18px 0px"
      })
    } else {
      $(".dark-layout.navbar-sticky .main-header-navbar").css({
        "background-color": "transparent",
        "box-shadow": "none"
      })
    }
  })

  // Header Notification Dropdown Remains Opened on click of switch Label
  $(".header-navbar .dropdown-notification label").on("click", function (e) {
    e.stopPropagation()
  })
})(window, document, jQuery)