PageSourceSearch

http://weizun.com/template/default/index/index/js/bootsnav.js

js weizun.com collected 2026-10-02 15:27:02 UTC 28,517 bytes, 591 lines download raw bytes

1(function ($) {
2	"use strict";
3    
4    var bootsnav = {
5        initialize: function() {
6            this.event();
7            this.hoverDropdown();
8            this.navbarSticky();
9            this.navbarScrollspy();
10        },
11        event : function(){
12            
13            // ------------------------------------------------------------------------------ //
14            // Variable
15            // ------------------------------------------------------------------------------ //
16            var getNav = $("nav.navbar.bootsnav");
17            
18            // ------------------------------------------------------------------------------ //
19            // Navbar Center 
20            // ------------------------------------------------------------------------------ //
21            if( getNav.hasClass("brand-center")){                
22                var postsArr = new Array(),
23                    index = $("nav.brand-center"),
24                    $postsList = index.find('ul.navbar-nav');
25
26                //Create array of all posts in lists
27                index.find('ul.navbar-nav > li').each(function(){
28                    postsArr.push($(this).html());
29                });
30                
31                //Split the array at this point. The original array is altered.
32                var firstList = postsArr.splice(0, Math.round(postsArr.length / 2)),
33                    secondList = postsArr,
34                    ListHTML = '';
35                
36                var createHTML = function(list){
37                    ListHTML = '';
38                    for (var i = 0; i < list.length; i++) {
39                        ListHTML += '<li>' + list[i] + '</li>'
40                    }
41                }
42                
43                //Generate HTML for first list
44                createHTML(firstList);
45                $postsList.html(ListHTML);
46                index.find("ul.nav").first().addClass("navbar-left");
47                
48                //Generate HTML for second list
49                createHTML(secondList);
50                //Create new list after original one
51                $postsList.after('<ul class="nav navbar-nav"></ul>').next().html(ListHTML);
52                index.find("ul.nav").last().addClass("navbar-right");
53                
54                //Wrap navigation menu
55                index.find("ul.nav.navbar-left").wrap("<div class='col-half left'></div>");
56                index.find("ul.nav.navbar-right").wrap("<div class='col-half right'></div>");
57                
58                //Selection Class
59                index.find('ul.navbar-nav > li').each(function(){ 
60                    var dropDown = $("ul.dropdown-menu", this),
61                        megaMenu = $("ul.megamenu-content", this);
62                    dropDown.closest("li").addClass("dropdown");
63                    megaMenu.closest("li").addClass("megamenu-fw");
64                });
65            }
66            
67            
68            // ------------------------------------------------------------------------------ //
69            // Navbar Sidebar 
70            // ------------------------------------------------------------------------------ //
71            if( getNav.hasClass("navbar-sidebar")){
72                // Add Class to body
73                $("body").addClass("wrap-nav-sidebar");
74                getNav.wrapInner("<div class='scroller'></div>");
75            }else{
76                $(".bootsnav").addClass("on");
77            }
78            
79            // ------------------------------------------------------------------------------ //
80            // Menu Center 
81            // ------------------------------------------------------------------------------ //
82            if( getNav.find("ul.nav").hasClass("navbar-center")){
83                getNav.addClass("menu-center");
84            }
85            
86            // ------------------------------------------------------------------------------ //
87            // Navbar Full
88            // ------------------------------------------------------------------------------ //
89            if( getNav.hasClass("navbar-full")){
90                // Add Class to body
91                $("nav.navbar.bootsnav").find("ul.nav").wrap("<div class='wrap-full-menu'></div>");
92                $(".wrap-full-menu").wrap("<div class='nav-full'></div>");
93                $("ul.nav.navbar-nav").prepend("<li class='close-full-menu'><a href='#'><i class='fa fa-times'></i></a></li>");
94            }else if( getNav.hasClass("navbar-mobile")){
95                getNav.removeClass("no-full");
96            }else{
97                getNav.addClass("no-full");
98            }
99                
100            // ------------------------------------------------------------------------------ //
101            // Navbar Mobile
102            // ------------------------------------------------------------------------------ //
103            if( getNav.hasClass("navbar-mobile")){
104                // Add Class to body
105                $('.navbar-collapse').on('shown.bs.collapse', function() {
106                    $("body").addClass("side-right");
107                });
108                $('.navbar-collapse').on('hide.bs.collapse', function() {
109                    $("body").removeClass("side-right");
110                });
111                
112                $(window).on("resize", function(){
113                    $("body").removeClass("side-right");
114                });
115            }
116            
117            // ------------------------------------------------------------------------------ //
118            // Navbar Fixed
119            // ------------------------------------------------------------------------------ //
120            if( getNav.hasClass("no-background")){
121                $(window).on("scroll", function(){
122                    var scrollTop = $(window).scrollTop();
123                    if(scrollTop >34){
124                        $(".navbar-fixed").removeClass("no-background");
125                        $(".banner").addClass("active");
126                    }else {
127                        $(".navbar-fixed").addClass("no-background");
128                        $(".banner").removeClass("active");
129                    }
130                });
131            }
132            
133            // ------------------------------------------------------------------------------ //
134            // Navbar Fixed
135            // ------------------------------------------------------------------------------ //
136            if( getNav.hasClass("navbar-transparent")){
137                $(window).on("scroll", function(){
138                    var scrollTop = $(window).scrollTop();
139                    if(scrollTop >34){
140                        $(".navbar-fixed").removeClass("navbar-transparent");
141                    }else {
142                        $(".navbar-fixed").addClass("navbar-transparent");
143                    }
144                });
145            }
146            
147            // ------------------------------------------------------------------------------ //
148            // Button Cart
149            // ------------------------------------------------------------------------------ //
150            $(".btn-cart").on("click", function(e){
151                e.stopPropagation();
152            });
153            
154            // ------------------------------------------------------------------------------ //
155            // Toggle Search
156            // ------------------------------------------------------------------------------ //
157            $("nav.navbar.bootsnav .attr-nav").each(function(){  
158                $("li.search > a", this).on("click", function(e){
159                    e.preventDefault();
160                    $(".top-search").slideToggle();
161                });
162            });
163            $(".input-group-addon.close-search").on("click", function(){
164                $(".top-search").slideUp();
165            });
166            
167            // ------------------------------------------------------------------------------ //
168            // Toggle Side Menu
169            // ------------------------------------------------------------------------------ //
170            $("nav.navbar.bootsnav .attr-nav").each(function(){  
171                $("li.side-menu > a", this).on("click", function(e){
172                    e.preventDefault();
173                    $("nav.navbar.bootsnav > .side").toggleClass("on");
174                    $("body").toggleClass("on-side");
175                });
176            });
177            $(".side .close-side").on("click", function(e){
178                e.preventDefault();
179                $("nav.navbar.bootsnav > .side").removeClass("on");
180                $("body").removeClass("on-side");
181            });            
182            
183            // ------------------------------------------------------------------------------ //
184            // Navbat Tabs
185            // ------------------------------------------------------------------------------ //
186            $(".tab-nav li").each(function(){
187                $("a", this).off("click");
188                $("a", this).on("click", function(e){
189                    e.preventDefault();                    
190                    var cek = $(this).closest("li").hasClass("active");
191                    if( cek ){
192                        $("a", this).off("click");
193                    }else{
194                        var getID = $(this).attr("href");
195                        $(".tab-nav li").removeClass("active");
196                        $(this).closest("li").addClass("active");
197                    }
198                });
199            });
200            
201            $(".dropdown-tabs .tab-pane").each(function(){
202                var getBG = $(this).data("background");
203                $(this).css("background-image","url('" + getBG +"')");
204                $(this).addClass("animated");
205            });
206            
207            // ------------------------------------------------------------------------------ //
208            // Wrapper
209            // ------------------------------------------------------------------------------ //
210            //$("body").wrapInner( "<div class='wrapper'></div>");
211        }, 
212        
213
214        // ------------------------------------------------------------------------------ //
215        // Change dropdown to hover on dekstop
216        // ------------------------------------------------------------------------------ //
217        hoverDropdown : function(){
218            var getNav = $("nav.navbar.bootsnav"),
219                getWindow = $(window).width(),
220                getHeight = $(window).height(),
221                getIn = getNav.find("ul.nav").data("in"),
222                getOut = getNav.find("ul.nav").data("out");
223            
224            if( getWindow < 991 ){
225                
226                // Height of scroll navigation sidebar
227                $(".scroller").css("height", "auto");
228                
229                // Disable mouseenter event
230                $("nav.navbar.bootsnav ul.nav").find("li.dropdown").off("mouseenter");
231                $("nav.navbar.bootsnav ul.nav").find("li.dropdown").off("mouseleave");
232                $("nav.navbar.bootsnav ul.nav").find(".title").off("mouseenter"); 
233                $("nav.navbar.bootsnav ul.nav").off("mouseleave");    
234                $(".navbar-collapse").removeClass("animated");
235                
236                // Enable click event
237                $("nav.navbar.bootsnav ul.nav").each(function(){
238                    $(".dropdown-menu", this).addClass("animated");
239                    $(".dropdown-menu", this).removeClass(getOut);
240                    
241                    // Dropdown Fade Toggle
242                    $("a.dropdown-toggle", this).off('click');
243                    $("a.dropdown-toggle", this).on('click', function (e) {
244                        e.stopPropagation();
245                        $(this).closest("li.dropdown").find(".dropdown-menu").first().stop().fadeToggle().toggleClass(getIn);
246                        $(this).closest("li.dropdown").first().toggleClass("on");                        
247                        return false;
248                    });   
249                    
250                    // Hidden dropdown action
251                    $('li.dropdown', this).each(function () {
252                        $(this).find(".dropdown-menu").stop().fadeOut();
253                        $(this).on('hidden.bs.dropdown', function () {
254                            $(this).find(".dropdown-menu").stop().fadeOut();
255                        });
256                        return false;
257                    });
258
259                    // Megamenu style
260                    $(".megamenu-fw", this).each(function(){
261                        $(".col-menu", this).each(function(){
262                            $(".content", this).addClass("animated");
263                            $(".content", this).stop().fadeOut();
264                            $(".title", this).off("click");
265                            $(".title", this).on("click", function(){
266                                $(this).closest(".col-menu").find(".content").stop().fadeToggle().addClass(getIn);
267                                $(this).closest(".col-menu").toggleClass("on");
268                                return false;
269                            });
270
271                            $(".content", this).on("click", function(e){
272                                e.stopPropagation();
273                            });
274                        });
275                    });  
276                }); 
277                
278                // Hidden dropdown
279                var cleanOpen = function(){
280                    $('li.dropdown', this).removeClass("on");
281                    $(".dropdown-menu", this).stop().fadeOut();
282                    $(".dropdown-menu", this).removeClass(getIn);
283                    $(".col-menu", this).removeClass("on");
284                    $(".col-menu .content", this).stop().fadeOut();
285                    $(".col-menu .content", this).removeClass(getIn);
286                }
287                
288                // Hidden om mouse leave
289                $("nav.navbar.bootsnav").on("mouseleave", function(){
290                    cleanOpen();
291                });
292                
293                // Enable click atribute navigation
294                $("nav.navbar.bootsnav .attr-nav").each(function(){  
295                    $(".dropdown-menu", this).removeClass("animated");
296                    $("li.dropdown", this).off("mouseenter");
297                    $("li.dropdown", this).off("mouseleave");                    
298                    $("a.dropdown-toggle", this).off('click');
299                    $("a.dropdown-toggle", this).on('click', function (e) {
300                        e.stopPropagation();
301                        $(this).closest("li.dropdown").find(".dropdown-menu").first().stop().fadeToggle();
302                        $(".navbar-toggle").each(function(){
303                            $(".fa", this).removeClass("fa-times");
304                            $(".fa", this).addClass("fa-bars");
305                            $(".navbar-collapse").removeClass("in");
306                            $(".navbar-collapse").removeClass("on");
307                        });
308                    });
309                    
310                    $(this).on("mouseleave", function(){
311                        $(".dropdown-menu", this).stop().fadeOut();
312                        $("li.dropdown", this).removeClass("on");
313                        return false;
314                    });
315                });
316                
317                // Toggle Bars
318                $(".navbar-toggle").each(function(){
319                    $(this).off("click");
320                    $(this).on("click", function(){
321                        $(".fa", this).toggleClass("fa-bars");
322                        $(".fa", this).toggleClass("fa-times");
323                        cleanOpen();
324                    });
325                });
326
327            }else if( getWindow > 991 ){
328                // Height of scroll navigation sidebar
329                $(".scroller").css("height", getHeight + "px");
330                
331                // Navbar Sidebar
332                if( getNav.hasClass("navbar-sidebar")){
333                    // Hover effect Sidebar Menu
334                    $("nav.navbar.bootsnav ul.nav").each(function(){  
335                        $("a.dropdown-toggle", this).off('click');
336                        $("a.dropdown-toggle", this).on('click', function (e) {
337                            e.stopPropagation();
338                        }); 
339
340                        $(".dropdown-menu", this).addClass("animated");
341                        $("li.dropdown", this).on("mouseenter", function(){
342                            $(".dropdown-menu", this).eq(0).removeClass(getOut);
343                            $(".dropdown-menu", this).eq(0).stop().fadeIn().addClass(getIn);
344                            $(this).addClass("on");
345                            return false;
346                        });
347                        
348                        $(".col-menu").each(function(){
349                            $(".content", this).addClass("animated");
350                            $(".title", this).on("mouseenter", function(){
351                                $(this).closest(".col-menu").find(".content").stop().fadeIn().addClass(getIn);
352                                $(this).closest(".col-menu").addClass("on");
353                                return false;
354                            });
355                        });
356                        
357                        $(this).on("mouseleave", function(){
358                            $(".dropdown-menu", this).stop().removeClass(getIn);
359                            $(".dropdown-menu", this).stop().addClass(getOut).fadeOut();
360                            $(".col-menu", this).find(".content").stop().fadeOut().removeClass(getIn);
361                            $(".col-menu", this).removeClass("on");
362                            $("li.dropdown", this).removeClass("on");
363                            return false;
364                        });
365                    }); 
366                }else{
367                    // Hover effect Default Menu
368                    $("nav.navbar.bootsnav ul.nav").each(function(){  
369                        $("a.dropdown-toggle", this).off('click');
370                        $("a.dropdown-toggle", this).on('click', function (e) {
371                            e.stopPropagation();
372                        }); 
373
374                        $(".megamenu-fw", this).each(function(){
375                            $(".title", this).off("click");
376                            $("a.dropdown-toggle", this).off("click");
377                            $(".content").removeClass("animated");
378                        });
379
380                        $(".dropdown-menu", this).addClass("animated");
381                        $("li.dropdown", this).on("mouseenter", function(){
382                            $(".dropdown-menu", this).eq(0).removeClass(getOut);
383                            $(".dropdown-menu", this).eq(0).stop().fadeIn().addClass(getIn);
384                            $(this).addClass("on");
385                            return false;
386                        });
387
388                        $("li.dropdown", this).on("mouseleave", function(){
389                            $(".dropdown-menu", this).eq(0).removeClass(getIn);
390                            $(".dropdown-menu", this).eq(0).stop().fadeOut().addClass(getOut);
391                            $(this).removeClass("on");
392                        });
393
394                        $(this).on("mouseleave", function(){
395                            $(".dropdown-menu", this).removeClass(getIn);
396                            $(".dropdown-menu", this).eq(0).stop().fadeOut().addClass(getOut);
397                            $("li.dropdown", this).removeClass("on");
398                            return false;
399                        });
400                    });
401                }
402                
403                // ------------------------------------------------------------------------------ //
404                // Hover effect Atribute Navigation
405                // ------------------------------------------------------------------------------ //
406                $("nav.navbar.bootsnav .attr-nav").each(function(){                      
407                    $("a.dropdown-toggle", this).off('click');
408                    $("a.dropdown-toggle", this).on('click', function (e) {
409                        e.stopPropagation();
410                    }); 
411                    
412                    $(".dropdown-menu", this).addClass("animated");
413                    $("li.dropdown", this).on("mouseenter", function(){
414                        $(".dropdown-menu", this).eq(0).removeClass(getOut);
415                        $(".dropdown-menu", this).eq(0).stop().fadeIn().addClass(getIn);
416                        $(this).addClass("on");
417                        return false;
418                    });
419
420                    $("li.dropdown", this).on("mouseleave", function(){
421                        $(".dropdown-menu", this).eq(0).removeClass(getIn);
422                        $(".dropdown-menu", this).eq(0).stop().fadeOut().addClass(getOut);
423                        $(this).removeClass("on");
424                    });
425
426                    $(this).on("mouseleave", function(){
427                        $(".dropdown-menu", this).removeClass(getIn);
428                        $(".dropdown-menu", this).eq(0).stop().fadeOut().addClass(getOut);
429                        $("li.dropdown", this).removeClass("on");
430                        return false;
431                    });
432                });
433            }
434            
435            // ------------------------------------------------------------------------------ //
436            // Menu Fullscreen
437            // ------------------------------------------------------------------------------ //
438            if( getNav.hasClass("navbar-full")){
439                var windowHeight = $(window).height(),
440                    windowWidth =  $(window).width();
441
442                $(".nav-full").css("height", windowHeight + "px");
443                $(".wrap-full-menu").css("height", windowHeight + "px");
444                $(".wrap-full-menu").css("width", windowWidth + "px");
445                
446                $(".navbar-collapse").addClass("animated");
447                $(".navbar-toggle").each(function(){
448                    var getId = $(this).data("target");
449                    $(this).off("click");
450                    $(this).on("click", function(e){
451                        e.preventDefault();
452                        $(getId).removeClass(getOut);
453                        $(getId).addClass("in");
454                        $(getId).addClass(getIn);
455                        return false;
456                    });
457                    
458                    $("li.close-full-menu").on("click", function(e){
459                        e.preventDefault();
460                        $(getId).addClass(getOut);
461                        setTimeout(function(){
462                            $(getId).removeClass("in");
463                            $(getId).removeClass(getIn);
464                        }, 500);
465                        return false;
466                    });
467                });
468            }
469        },
470        
471        // ------------------------------------------------------------------------------ //
472        // Navbar Sticky
473        // ------------------------------------------------------------------------------ //
474        navbarSticky : function(){  
475            var getNav = $("nav.navbar.bootsnav"),
476                navSticky = getNav.hasClass("navbar-sticky");
477            
478            if( navSticky ){
479                // Wraped navigation
480                getNav.wrap("<div class='wrap-sticky'></div>");
481                
482                // Set Height Navigation
483                var getHeight = getNav.height();             
484                $(".wrap-sticky").height(getHeight);
485                
486                // Windown on scroll
487                var getOffset = $(".wrap-sticky").offset().top;
488                $(window).on("scroll", function(){  
489                    var scrollTop = $(window).scrollTop();
490                    if(scrollTop > getOffset){
491                        getNav.addClass("sticked");
492                    }else {
493                        getNav.removeClass("sticked");
494                    }
495                });
496            }   
497        },
498        
499        // ------------------------------------------------------------------------------ //
500        // Navbar Scrollspy
501        // ------------------------------------------------------------------------------ //
502        navbarScrollspy : function(){ 
503            var navScrollSpy = $(".navbar-scrollspy"),
504                $body   = $('body'), 
505                getNav = $('nav.navbar.bootsnav'),
506                offset  = getNav.outerHeight();
507            
508            if( navScrollSpy.length ){
509                $body.scrollspy({target: '.navbar', offset: offset });
510                
511                // Animation Scrollspy
512                $('.scroll').on('click', function(event) {
513                    event.preventDefault();
514
515                    // Active link
516                    $('.scroll').removeClass("active");
517                    $(this).addClass("active");
518
519                    // Remove navbar collapse
520                    $(".navbar-collapse").removeClass("in");
521
522                    // Toggle Bars
523                    $(".navbar-toggle").each(function(){
524                        $(".fa", this).removeClass("fa-times");
525                        $(".fa", this).addClass("fa-bars");
526                    });
527
528                    // Scroll
529                    var scrollTop = $(window).scrollTop(),
530                        $anchor = $(this).find('a'),
531                        $section = $($anchor.attr('href')).offset().top,
532                        $window = $(window).width(),
533                        $minusDesktop = getNav.data("minus-value-desktop"),
534                        $minusMobile = getNav.data("minus-value-mobile"),
535                        $speed = getNav.data("speed");
536                    
537                    if( $window > 992 ){
538                        var $position = $section - $minusDesktop;
539                    }else{
540                        var $position = $section - $minusMobile;
541                    }             
542                        
543                    $('html, body').stop().animate({
544                        scrollTop: $position
545                    }, $speed);
546                });
547                
548                // Activate Navigation
549                var fixSpy = function() {
550                    var data = $body.data('bs.scrollspy');
551                    if (data) {
552                        offset = getNav.outerHeight();
553                        data.options.offset = offset;
554                        $body.data('bs.scrollspy', data);
555                        $body.scrollspy('refresh');
556                    }
557                }
558                
559                // Activate Navigation on resize
560                var resizeTimer;
561                $(window).on('resize', function() {
562                    clearTimeout(resizeTimer);
563                    var resizeTimer = setTimeout(fixSpy, 200);
564                });
565            }
566        }
567    };
568    
569    // Initialize
570    $(document).ready(function(){
571        bootsnav.initialize();
572    });
573    
574    // Reset on resize
575    $(window).on("resize", function(){   
576        bootsnav.hoverDropdown();
577        bootsnav.navbarSticky(); 
578        
579        // Toggle Bars
580        //$(".navbar-toggle").each(function(){
581//            $(".fa", this).removeClass("fa-times");
582//            $(".fa", this).addClass("fa-bars");
583//            $(this).removeClass("fixed");
584//        });        
585//        $(".navbar-collapse").removeClass("in");
586//        $(".navbar-collapse").removeClass("on");
587//        $(".navbar-collapse").removeClass("bounceIn");      
588    });
589    
590}(jQuery));
591

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.