PageSourceSearch

https://inhabitat.com/wp-content/themes/inhabitatresponsive/js/modules/mobile-nav.js?ver=260806-145309

js inhabitat.com collected 2026-09-24 08:25:46 UTC 3,854 bytes, 105 lines download raw bytes

1(function($) {
2    function MobileNav(options) {
3        this.options = $.extend({
4            container: null,
5            hideOnClickOutside: false,
6            menuActiveClass: "nav-active",
7            menuOpener: ".nav-opener",
8            menuDrop: ".nav-drop",
9            toggleEvent: "click",
10            outsideClickEvent: "click touchstart pointerdown MSPointerDown"
11        }, options);
12        this.initStructure();
13        this.attachEvents();
14    }
15    MobileNav.prototype = {
16        initStructure: function() {
17            this.page = $("html");
18            this.container = $(this.options.container);
19            this.opener = this.container.find(this.options.menuOpener);
20            this.drop = this.container.find(this.options.menuDrop);
21            this.links = this.drop.find("a");
22        },
23        attachEvents: function() {
24            var self = this;
25            if (activateResizeHandler) {
26                activateResizeHandler();
27                activateResizeHandler = null;
28            }
29            this.outsideClickHandler = function(e) {
30                if (self.isOpened()) {
31                    var target = $(e.target);
32                    if (!target.closest(self.opener).length && !target.closest(self.drop).length) {
33                        self.hide();
34                    }
35                }
36            };
37            this.openerClickHandler = function(e) {
38                e.preventDefault();
39                self.toggle();
40            };
41
42            this.linkClickHandler = function(e){
43                self.toggle();
44            };
45
46            this.opener.on(this.options.toggleEvent, this.openerClickHandler);
47            this.links.on(this.options.toggleEvent,this.linkClickHandler);
48        },
49        isOpened: function() {
50            return this.container.hasClass(this.options.menuActiveClass);
51        },
52        show: function() {
53            this.container.addClass(this.options.menuActiveClass);
54            if (this.options.hideOnClickOutside) {
55                this.page.on(this.options.outsideClickEvent, this.outsideClickHandler);
56            }
57        },
58        hide: function() {
59            this.container.removeClass(this.options.menuActiveClass);
60            if (this.options.hideOnClickOutside) {
61                this.page.off(this.options.outsideClickEvent, this.outsideClickHandler);
62            }
63        },
64        toggle: function() {
65            if (this.isOpened()) {
66                this.hide();
67            } else {
68                this.show();
69            }
70        },
71        destroy: function() {
72            this.container.removeClass(this.options.menuActiveClass);
73            this.opener.off(this.options.toggleEvent, this.clickHandler);
74            this.page.off(this.options.outsideClickEvent, this.outsideClickHandler);
75        }
76    };
77    var activateResizeHandler = function() {
78        var win = $(window),
79            doc = $("html"),
80            resizeClass = "resize-active",
81            flag, timer;
82        var removeClassHandler = function() {
83            flag = false;
84            doc.removeClass(resizeClass);
85        };
86        var resizeHandler = function() {
87            if (!flag) {
88                flag = true;
89                doc.addClass(resizeClass);
90            }
91            clearTimeout(timer);
92            timer = setTimeout(removeClassHandler, 500);
93        };
94        win.on("resize orientationchange", resizeHandler);
95    };
96    $.fn.mobileNav = function(options) {
97        return this.each(function() {
98            var params = $.extend({}, options, {
99                container: this
100            }),
101                instance = new MobileNav(params);
102            $.data(this, "MobileNav", instance);
103        });
104    };
105}(jQuery));

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.