(function ($) { "use strict"; var bootsnav = { initialize: function() { this.event(); this.hoverdropdown(); this.navbarsticky(); this.navbarscrollspy(); }, event : function(){ // ------------------------------------------------------------------------------ // // variable // ------------------------------------------------------------------------------ // var getnav = $("nav.navbar.bootsnav"); // ------------------------------------------------------------------------------ // // navbar center // ------------------------------------------------------------------------------ // if( getnav.hasclass("brand-center")){ var postsarr = new array(), index = $("nav.brand-center"), $postslist = index.find('ul.navbar-nav'); //create array of all posts in lists index.find('ul.navbar-nav > li').each(function(){ postsarr.push($(this).html()); }); //split the array at this point. the original array is altered. var firstlist = postsarr.splice(0, math.round(postsarr.length / 2)), secondlist = postsarr, listhtml = ''; var createhtml = function(list){ listhtml = ''; for (var i = 0; i < list.length; i++) { listhtml += '
  • ' + list[i] + '
  • ' } } //generate html for first list createhtml(firstlist); $postslist.html(listhtml); index.find("ul.nav").first().addclass("navbar-left"); //generate html for second list createhtml(secondlist); //create new list after original one $postslist.after('').next().html(listhtml); index.find("ul.nav").last().addclass("navbar-right"); //wrap navigation menu index.find("ul.nav.navbar-left").wrap("
    "); index.find("ul.nav.navbar-right").wrap("
    "); //selection class index.find('ul.navbar-nav > li').each(function(){ var dropdown = $("ul.dropdown-menu", this), megamenu = $("ul.megamenu-content", this); dropdown.closest("li").addclass("dropdown"); megamenu.closest("li").addclass("megamenu-fw"); }); } // ------------------------------------------------------------------------------ // // navbar sidebar // ------------------------------------------------------------------------------ // if( getnav.hasclass("navbar-sidebar")){ // add class to body $("body").addclass("wrap-nav-sidebar"); getnav.wrapinner("
    "); }else{ $(".bootsnav").addclass("on"); } // ------------------------------------------------------------------------------ // // menu center // ------------------------------------------------------------------------------ // if( getnav.find("ul.nav").hasclass("navbar-center")){ getnav.addclass("menu-center"); } // ------------------------------------------------------------------------------ // // navbar full // ------------------------------------------------------------------------------ // if( getnav.hasclass("navbar-full")){ // add class to body $("nav.navbar.bootsnav").find("ul.nav").wrap("
    "); $(".wrap-full-menu").wrap(""); $("ul.nav.navbar-nav").prepend("
  • "); }else if( getnav.hasclass("navbar-mobile")){ getnav.removeclass("no-full"); }else{ getnav.addclass("no-full"); } // ------------------------------------------------------------------------------ // // navbar mobile // ------------------------------------------------------------------------------ // if( getnav.hasclass("navbar-mobile")){ // add class to body $('.navbar-collapse').on('shown.bs.collapse', function() { $("body").addclass("side-right"); }); $('.navbar-collapse').on('hide.bs.collapse', function() { $("body").removeclass("side-right"); }); $(window).on("resize", function(){ $("body").removeclass("side-right"); }); } // ------------------------------------------------------------------------------ // // navbar fixed // ------------------------------------------------------------------------------ // if( getnav.hasclass("no-background")){ $(window).on("scroll", function(){ var scrolltop = $(window).scrolltop(); if(scrolltop >34){ $(".navbar-fixed").removeclass("no-background"); }else { $(".navbar-fixed").addclass("no-background"); } }); } // ------------------------------------------------------------------------------ // // navbar fixed // ------------------------------------------------------------------------------ // if( getnav.hasclass("navbar-transparent")){ $(window).on("scroll", function(){ var scrolltop = $(window).scrolltop(); if(scrolltop >34){ $(".navbar-fixed").removeclass("navbar-transparent"); }else { $(".navbar-fixed").addclass("navbar-transparent"); } }); } // ------------------------------------------------------------------------------ // // button cart // ------------------------------------------------------------------------------ // $(".btn-cart").on("click", function(e){ e.stoppropagation(); }); // ------------------------------------------------------------------------------ // // toggle search // ------------------------------------------------------------------------------ // $("nav.navbar.bootsnav .attr-nav").each(function(){ $("li.search > a", this).on("click", function(e){ e.preventdefault(); $(".top-search").slidetoggle(); }); }); $(".input-group-addon.close-search").on("click", function(){ $(".top-search").slideup(); }); // ------------------------------------------------------------------------------ // // toggle side menu // ------------------------------------------------------------------------------ // $("nav.navbar.bootsnav .attr-nav").each(function(){ $("li.side-menu > a", this).on("click", function(e){ e.preventdefault(); $("nav.navbar.bootsnav > .side").toggleclass("on"); $("body").toggleclass("on-side"); }); }); $(".side .close-side").on("click", function(e){ e.preventdefault(); $("nav.navbar.bootsnav > .side").removeclass("on"); $("body").removeclass("on-side"); }); // ------------------------------------------------------------------------------ // // navbat tabs // ------------------------------------------------------------------------------ // $(".tab-nav li").each(function(){ $("a", this).off("click"); $("a", this).on("click", function(e){ e.preventdefault(); var cek = $(this).closest("li").hasclass("active"); if( cek ){ $("a", this).off("click"); }else{ var getid = $(this).attr("href"); $(".tab-nav li").removeclass("active"); $(this).closest("li").addclass("active"); } }); }); $(".dropdown-tabs .tab-pane").each(function(){ var getbg = $(this).data("background"); $(this).css("background-image","url('" + getbg +"')"); $(this).addclass("animated"); }); // ------------------------------------------------------------------------------ // // wrapper // ------------------------------------------------------------------------------ // $("body").wrapinner( "
    "); }, // ------------------------------------------------------------------------------ // // change dropdown to hover on dekstop // ------------------------------------------------------------------------------ // hoverdropdown : function(){ var getnav = $("nav.navbar.bootsnav"), getwindow = $(window).width(), getheight = $(window).height(), getin = getnav.find("ul.nav").data("in"), getout = getnav.find("ul.nav").data("out"); if( getwindow < 981 ){ // height of scroll navigation sidebar $(".scroller").css("height", "auto"); // disable mouseenter event $("nav.navbar.bootsnav ul.nav").find("li.dropdown").off("mouseenter"); $("nav.navbar.bootsnav ul.nav").find("li.dropdown").off("mouseleave"); $("nav.navbar.bootsnav ul.nav").find(".title").off("mouseenter"); $("nav.navbar.bootsnav ul.nav").off("mouseleave"); $(".navbar-collapse").removeclass("animated"); // enable click event $("nav.navbar.bootsnav ul.nav").each(function(){ $(".dropdown-menu", this).addclass("animated"); $(".dropdown-menu", this).removeclass(getout); // dropdown fade toggle $("a.dropdown-toggle", this).off('click'); $("a.dropdown-toggle", this).on('click', function (e) { e.stoppropagation(); $(this).closest("li.dropdown").find(".dropdown-menu").first().stop().fadetoggle().toggleclass(getin); $(this).closest("li.dropdown").first().toggleclass("on"); return false; }); // hidden dropdown action $('li.dropdown', this).each(function () { $(this).find(".dropdown-menu").stop().fadeout(); $(this).on('hidden.bs.dropdown', function () { $(this).find(".dropdown-menu").stop().fadeout(); }); return false; }); // megamenu style $(".megamenu-fw", this).each(function(){ $(".col-menu", this).each(function(){ $(".content", this).addclass("animated"); $(".content", this).stop().fadeout(); $(".title", this).off("click"); $(".title", this).on("click", function(){ $(this).closest(".col-menu").find(".content").stop().fadetoggle().addclass(getin); $(this).closest(".col-menu").toggleclass("on"); return false; }); $(".content", this).on("click", function(e){ e.stoppropagation(); }); }); }); }); // hidden dropdown var cleanopen = function(){ $('li.dropdown', this).removeclass("on"); $(".dropdown-menu", this).stop().fadeout(); $(".dropdown-menu", this).removeclass(getin); $(".col-menu", this).removeclass("on"); $(".col-menu .content", this).stop().fadeout(); $(".col-menu .content", this).removeclass(getin); } // hidden om mouse leave $("nav.navbar.bootsnav").on("mouseleave", function(){ cleanopen(); }); // enable click atribute navigation $("nav.navbar.bootsnav .attr-nav").each(function(){ $(".dropdown-menu", this).removeclass("animated"); $("li.dropdown", this).off("mouseenter"); $("li.dropdown", this).off("mouseleave"); $("a.dropdown-toggle", this).off('click'); $("a.dropdown-toggle", this).on('click', function (e) { e.stoppropagation(); $(this).closest("li.dropdown").find(".dropdown-menu").first().stop().fadetoggle(); $(".navbar-toggle").each(function(){ $(".fa", this).removeclass("fa-times"); $(".fa", this).addclass("fa-bars"); $(".navbar-collapse").removeclass("in"); $(".navbar-collapse").removeclass("on"); }); }); $(this).on("mouseleave", function(){ $(".dropdown-menu", this).stop().fadeout(); $("li.dropdown", this).removeclass("on"); return false; }); }); // toggle bars $(".navbar-toggle").each(function(){ $(this).off("click"); $(this).on("click", function(){ $(".fa", this).toggleclass("fa-bars"); $(".fa", this).toggleclass("fa-times"); cleanopen(); }); }); }else if( getwindow > 981 ){ // height of scroll navigation sidebar $(".scroller").css("height", getheight + "px"); // navbar sidebar if( getnav.hasclass("navbar-sidebar")){ // hover effect sidebar menu $("nav.navbar.bootsnav ul.nav").each(function(){ $("a.dropdown-toggle", this).off('click'); $("a.dropdown-toggle", this).on('click', function (e) { e.stoppropagation(); }); $(".dropdown-menu", this).addclass("animated"); $("li.dropdown", this).on("mouseenter", function(){ $(".dropdown-menu", this).eq(0).removeclass(getout); $(".dropdown-menu", this).eq(0).stop().fadein().addclass(getin); $(this).addclass("on"); return false; }); $(".col-menu").each(function(){ $(".content", this).addclass("animated"); $(".title", this).on("mouseenter", function(){ $(this).closest(".col-menu").find(".content").stop().fadein().addclass(getin); $(this).closest(".col-menu").addclass("on"); return false; }); }); $(this).on("mouseleave", function(){ $(".dropdown-menu", this).stop().removeclass(getin); $(".dropdown-menu", this).stop().addclass(getout).fadeout(); $(".col-menu", this).find(".content").stop().fadeout().removeclass(getin); $(".col-menu", this).removeclass("on"); $("li.dropdown", this).removeclass("on"); return false; }); }); }else{ // hover effect default menu $("nav.navbar.bootsnav ul.nav").each(function(){ $("a.dropdown-toggle", this).off('click'); $("a.dropdown-toggle", this).on('click', function (e) { e.stoppropagation(); }); $(".megamenu-fw", this).each(function(){ $(".title", this).off("click"); $("a.dropdown-toggle", this).off("click"); $(".content").removeclass("animated"); }); $(".dropdown-menu", this).addclass("animated"); $("li.dropdown", this).on("mouseenter", function(){ $(".dropdown-menu", this).eq(0).removeclass(getout); $(".dropdown-menu", this).eq(0).stop().fadein().addclass(getin); $(this).addclass("on"); return false; }); $("li.dropdown", this).on("mouseleave", function(){ $(".dropdown-menu", this).eq(0).removeclass(getin); $(".dropdown-menu", this).eq(0).stop().fadeout().addclass(getout); $(this).removeclass("on"); }); $(this).on("mouseleave", function(){ $(".dropdown-menu", this).removeclass(getin); $(".dropdown-menu", this).eq(0).stop().fadeout().addclass(getout); $("li.dropdown", this).removeclass("on"); return false; }); }); } // ------------------------------------------------------------------------------ // // hover effect atribute navigation // ------------------------------------------------------------------------------ // $("nav.navbar.bootsnav .attr-nav").each(function(){ $("a.dropdown-toggle", this).off('click'); $("a.dropdown-toggle", this).on('click', function (e) { e.stoppropagation(); }); $(".dropdown-menu", this).addclass("animated"); $("li.dropdown", this).on("mouseenter", function(){ $(".dropdown-menu", this).eq(0).removeclass(getout); $(".dropdown-menu", this).eq(0).stop().fadein().addclass(getin); $(this).addclass("on"); return false; }); $("li.dropdown", this).on("mouseleave", function(){ $(".dropdown-menu", this).eq(0).removeclass(getin); $(".dropdown-menu", this).eq(0).stop().fadeout().addclass(getout); $(this).removeclass("on"); }); $(this).on("mouseleave", function(){ $(".dropdown-menu", this).removeclass(getin); $(".dropdown-menu", this).eq(0).stop().fadeout().addclass(getout); $("li.dropdown", this).removeclass("on"); return false; }); }); } // ------------------------------------------------------------------------------ // // menu fullscreen // ------------------------------------------------------------------------------ // if( getnav.hasclass("navbar-full")){ var windowheight = $(window).height(), windowwidth = $(window).width(); $(".nav-full").css("height", windowheight + "px"); $(".wrap-full-menu").css("height", windowheight + "px"); $(".wrap-full-menu").css("width", windowwidth + "px"); $(".navbar-collapse").addclass("animated"); $(".navbar-toggle").each(function(){ var getid = $(this).data("target"); $(this).off("click"); $(this).on("click", function(e){ e.preventdefault(); $(getid).removeclass(getout); $(getid).addclass("in"); $(getid).addclass(getin); return false; }); $("li.close-full-menu").on("click", function(e){ e.preventdefault(); $(getid).addclass(getout); settimeout(function(){ $(getid).removeclass("in"); $(getid).removeclass(getin); }, 500); return false; }); }); } }, // ------------------------------------------------------------------------------ // // navbar sticky // ------------------------------------------------------------------------------ // navbarsticky : function(){ var getnav = $("nav.navbar.bootsnav"), navsticky = getnav.hasclass("navbar-sticky"); if( navsticky ){ // wraped navigation getnav.wrap("
    "); // set height navigation var getheight = getnav.height(); $(".wrap-sticky").height(getheight); // windown on scroll var getoffset = $(".wrap-sticky").offset().top; $(window).on("scroll", function(){ var scrolltop = $(window).scrolltop(); if(scrolltop > getoffset){ getnav.addclass("sticked"); }else { getnav.removeclass("sticked"); } }); } }, // ------------------------------------------------------------------------------ // // navbar scrollspy // ------------------------------------------------------------------------------ // navbarscrollspy : function(){ var navscrollspy = $(".navbar-scrollspy"), $body = $('body'), getnav = $('nav.navbar.bootsnav'), offset = getnav.outerheight(); if( navscrollspy.length ){ $body.scrollspy({target: '.navbar', offset: offset }); // animation scrollspy $('.scroll').on('click', function(event) { event.preventdefault(); // active link $('.scroll').removeclass("active"); $(this).addclass("active"); // remove navbar collapse $(".navbar-collapse").removeclass("in"); // toggle bars $(".navbar-toggle").each(function(){ $(".fa", this).removeclass("fa-times"); $(".fa", this).addclass("fa-bars"); }); // scroll var scrolltop = $(window).scrolltop(), $anchor = $(this).find('a'), $section = $($anchor.attr('href')).offset().top, $window = $(window).width(), $minusdesktop = getnav.data("minus-value-desktop"), $minusmobile = getnav.data("minus-value-mobile"), $speed = getnav.data("speed"); if( $window > 992 ){ var $position = $section - $minusdesktop; }else{ var $position = $section - $minusmobile; } $('html, body').stop().animate({ scrolltop: $position }, $speed); }); // activate navigation var fixspy = function() { var data = $body.data('bs.scrollspy'); if (data) { offset = getnav.outerheight(); data.options.offset = offset; $body.data('bs.scrollspy', data); $body.scrollspy('refresh'); } } // activate navigation on resize var resizetimer; $(window).on('resize', function() { cleartimeout(resizetimer); var resizetimer = settimeout(fixspy, 200); }); } } }; // initialize $(document).ready(function(){ bootsnav.initialize(); }); // reset on resize $(window).on("resize", function(){ bootsnav.hoverdropdown(); bootsnav.navbarsticky(); // toggle bars $(".navbar-toggle").each(function(){ $(".fa", this).removeclass("fa-times"); $(".fa", this).addclass("fa-bars"); $(this).removeclass("fixed"); }); $(".navbar-collapse").removeclass("in"); $(".navbar-collapse").removeclass("on"); $(".navbar-collapse").removeclass("bouncein"); }); }(jquery));