PageSourceSearch

http://www.jaimevidal.es/assets/js/bootsnav.js

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

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.