PageSourceSearch

https://schodiste.org/components/com_gridbox/libraries/modules/initmenu.js?2.20.3.1

js schodiste.org collected 2026-10-07 21:59:14 UTC 14,855 bytes, 316 lines download raw bytes

1/**
2* @package   Gridbox
3* @author    Balbooa http://www.balbooa.com/
4* @copyright Copyright @ Balbooa
5* @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
6*/
7
8function compileValue(item){
9    var value = item.offset().top,
10        header = $g('header.header'),
11        comp = header[0] ? getComputedStyle(header[0]) : {},
12        top = window.scrollY,
13        stickies = $g('.ba-sticky-header'),
14        sticky = 0;
15    if (item.closest('.ba-wrapper').parent().hasClass('header')) {
16        value = 0;
17    } else {
18        stickies.each(function(){
19            if (this.offsetHeight > 0) {
20                let section = this.querySelector('.ba-sticky-header > .ba-section'),
21                    obj = app.items[section.id],
22                    offset = obj.desktop.offset;
23                if (app.view != 'desktop') {
24                    for (var ind in breakpoints) {
25                        if (!obj[ind]) {
26                            obj[ind] = {};
27                        }
28                        offset = obj[ind].offset ? obj[ind].offset : offset;
29                        if (ind == app.view) {
30                            break;
31                        }
32                    }
33                }
34                if ((!obj.scrollup && offset < value) || (obj.scrollup && offset < value && value < top)) {
35                    sticky = this.offsetHeight > sticky ? this.offsetHeight : sticky;
36                }
37            }
38        });
39        if ((!header.hasClass('sidebar-menu') || (app.view != 'desktop' && app.view != 'laptop'))
40            && comp.position == 'fixed') {
41            sticky = header[0].offsetHeight > sticky ? header[0].offsetHeight : sticky;
42            if (header.find('.resizing-header').length > 0) {
43                let resizingSection = getComputedStyle(header.find('.resizing-header')[0]);
44                value += resizingSection.paddingTop.replace('px', '') * 1;
45                value += resizingSection.paddingBottom.replace('px', '') * 1;
46            }
47        }
48        value -= sticky;
49    }
50
51    return Math.ceil(value);
52}
53
54app.initmenu = function(obj, key){
55    $g('#'+key).find('li[class*="item-"].current, li[class*="item-"].active').each(function(){
56        this.classList.add('active');
57        $g(this).parents('li').addClass('active visible-nav-child');
58    });
59    $g(`#${key} li[class*="item-"] a[data-anchor]`).on('click', function(event){
60        const id = this.dataset.anchor
61        if (!document.getElementById(id)) {
62            return;
63        }
64        event.preventDefault();
65
66        $g(this).closest('ul').find('.active').removeClass('active current');
67        this.parentNode.classList.add('active');
68        const item = $g('#' + id);
69        let value = compileValue(item),
70            speed = 1000,
71            alias = this.dataset.alias,
72            url = location.href.replace(location.hash, '') + '#' + alias;
73        $g(`.ba-item-main-menu a[data-anchor="${id}"]`).not(this).each(function(){
74            $g(this).closest('ul').find('.active').removeClass('active');
75            this.parentNode.classList.add('active');
76        });
77        if (window.scrollY != value) {
78            window.onePageScroll = false;
79            $g('html, body').stop().animate({
80                'scrollTop' : value
81            }, speed, function(){
82                setTimeout(function(){
83                    window.onePageScroll = true;
84                }, 200);
85            });
86        }
87        window.history.replaceState(null, null, url);
88    })
89    $g('#'+key+' > .ba-menu-wrapper > .open-menu i').on('mousedown', function(event){
90        if (event.button && event.button != 0) {
91            return false;
92        }
93        event.stopPropagation();
94        setTimeout(function(){
95            var width = window.innerWidth - document.documentElement.clientWidth;
96            $g('#'+key+' > .ba-menu-wrapper > .main-menu')
97                .find('li.deeper.parent > ul, .ba-wrapper[data-megamenu]').css('max-height', '');
98            $g('#'+key+' > .ba-menu-wrapper > .main-menu').addClass('visible-menu').removeClass('hide-menu')
99                .css('right', -width+'px').closest('.column-wrapper').addClass('column-with-menu')
100                .parents('.ba-row-wrapper').addClass('row-with-menu');
101            if (themeData.page.view == 'gridbox') {
102                var computed = getComputedStyle(document.querySelector('header.header'));
103                document.querySelector('header.header').classList.add('ba-header-position-'+computed.position);
104            }
105            $g('#'+key+' > .ba-menu-backdrop').addClass('ba-visible-menu-backdrop');
106            $g('body').addClass('ba-opened-menu');
107        }, 50);
108    });
109    $g('#'+key+' > .ba-menu-backdrop, #'+key+' > .ba-menu-wrapper > .main-menu > .close-menu i').off('click').on('click', function(){
110        if (!document.body.classList.contains('body-megamenu-editing')) {
111            $g('.visible-menu').addClass('hide-menu').removeClass('visible-menu').css('right', '')
112                .closest('.column-wrapper').removeClass('column-with-menu');
113            $g('.ba-menu-backdrop').removeClass('ba-visible-menu-backdrop').addClass('ba-menu-backdrop-out');
114            setTimeout(function(){
115                $g('.ba-menu-backdrop.ba-menu-backdrop-out').removeClass('ba-menu-backdrop-out');
116            }, 300);
117            $g('#'+key+' > .ba-menu-wrapper > .main-menu')
118                .find('li.deeper.parent > ul, .ba-wrapper[data-megamenu]').css('max-height', '');
119            setTimeout(function(){
120                if (themeData.page.view == 'gridbox') {
121                    var computed = getComputedStyle(document.querySelector('header.header'));
122                    document.querySelector('header.header').classList.remove('ba-header-position-'+computed.position);
123                }
124                $g('body').removeClass('ba-opened-menu');
125                $g('.row-with-menu').removeClass('row-with-menu');
126            }, 500);
127        }
128    });
129    if (themeData.page.view == 'gridbox') {
130        $g('#'+key+' .ba-menu-wrapper').on('click', '.ba-edit-item', function(event){
131            event.preventDefault();
132            event.stopPropagation();
133        });
134        var addNewItem = $g('#'+key+' > .ba-menu-wrapper > .main-menu > .add-new-item');
135        if (addNewItem.length == 0) {
136            addNewItem = '<div class="add-new-item"><span><i class="zmdi zmdi-layers"></i>'+
137                '<span class="ba-tooltip ba-top">'+top.app._('ADD_NEW_ITEM')+'</span></span></div>';
138            $g('#'+key+' > .ba-menu-wrapper > .main-menu').append(addNewItem);
139            addNewItem = $g('#'+key+' > .ba-menu-wrapper > .main-menu > .add-new-item');
140        }
141        addNewItem.find('i').on('click', function(){
142            app.edit = this.closest('.ba-item').id;
143            window.parent.app.checkModule('addPlugins');
144        });
145        if ($g('#'+key+' > .ba-edit-item .open-mobile-menu').length == 0) {
146            var str = '<span class="ba-edit-wrapper"><i class="zmdi zmdi-open-in-new open-mobile-menu"></i>'+
147                '<span class="ba-tooltip tooltip-delay settings-tooltip">'+top.app._('OPEN')+
148                '</span></span>';
149            $g('#'+key+' > .ba-edit-item .ba-buttons-wrapper .ba-edit-wrapper').first().before(str);
150        }
151        $g('.edit-mobile-menu-item').off('mousedown').on('mousedown', function(event){
152            if (event.button && event.button != 0) {
153                return false;
154            }
155            event.stopPropagation();
156            $g(this).closest('.ba-item').find('> .ba-edit-item .edit-item').trigger('mousedown');
157        });
158        $g('.open-mobile-menu').off('mousedown').on('mousedown', function(event){
159            if (event.button && event.button != 0) {
160                return false;
161            }
162            event.stopPropagation();
163            $g(this).closest('.ba-item').find('> .ba-menu-wrapper > .open-menu i').first().trigger('mousedown');
164        });
165    }
166    $g('#'+key+' > .ba-menu-wrapper .tabs-content-wrapper[data-megamenu]').each(function(){
167        var li = $g('#'+key+' > .ba-menu-wrapper > .main-menu > .integration-wrapper > ul > li.'+this.dataset.megamenu);
168        if (li.length != 0 && $g(this).closest('li').length == 0) {
169            li.prepend(this);
170        }
171    });
172
173    const parents = document.querySelectorAll(`#${key} li.deeper.parent`);
174    parents.forEach(parent => {
175        const trigger = parent.querySelector(':scope > a, :scope > span');
176        const submenu = parent.querySelector(':scope > ul, :scope > .ba-wrapper');
177
178        if (!trigger || !submenu) return;
179
180        submenu.setAttribute('aria-hidden', 'true');
181
182        trigger.addEventListener('keydown', e => {
183            if (e.key === 'ArrowDown') {
184                e.preventDefault();
185                e.stopPropagation();
186                submenu.classList.add('show-menu');
187                submenu.setAttribute('aria-hidden', 'false');
188                if (submenu.classList.contains('ba-wrapper')) {
189                    setMegamenuPosition(parent);
190                }
191            } else if (e.key === 'Escape') {
192                submenu.classList.remove('show-menu');
193                submenu.setAttribute('aria-hidden', 'true');
194            }
195        });
196
197        submenu.addEventListener('keydown', e => {
198            if (e.key === 'Escape') {
199                e.stopPropagation();
200                submenu.classList.remove('show-menu');
201                submenu.setAttribute('aria-hidden', 'true');
202                const parentLi = submenu.closest('li.deeper.parent');
203                const parentTrigger = parentLi?.querySelector(':scope > a, :scope > span');
204                if (parentTrigger) parentTrigger.focus();
205            }
206        });
207
208
209        parent.addEventListener('focusout', () => {
210            setTimeout(() => {
211                if (!parent.contains(document.activeElement)) {
212                    submenu.classList.remove('show-menu');
213                    submenu.setAttribute('aria-hidden', 'true');
214                }
215            }, 10);
216        });
217    });
218
219    $g('#'+key).on('mouseenter', 'li.megamenu-item', function(){
220        setMegamenuPosition(this);
221    });
222    $g('#'+key).off('click.deeper')
223        .on('click.deeper', 'li.deeper.parent > a > i.ba-icons, li.deeper.parent > span > i.ba-icons', function(event){
224        event.preventDefault();
225        event.stopPropagation();
226        let li = $g(this).closest('li.deeper.parent');
227        if (li.hasClass('visible-nav-child')) {
228            li.removeClass('visible-nav-child').addClass('hidden-nav-child');
229        } else {
230            $g('#'+key+' .visible-nav-child').find(' > ul, > .ba-wrapper').css('max-height', '');
231            li.addClass('visible-nav-child').removeClass('hidden-nav-child');
232            setTimeout(function(){
233                $g('#'+key+' .visible-nav-child').find(' > ul, > .ba-wrapper').each(function(){
234                   this.style.maxHeight = $g(this).outerHeight()+'px';
235                });
236            }, 500);
237        }
238    });
239    $g('#'+key).on('mouseenter.test', '.integration-wrapper > ul > li.deeper.parent:not(.megamenu-item)', function(){
240        let vertical = this.closest('.ba-menu-wrapper').classList.contains('vertical-menu'),
241            ul = this.querySelector('ul'),
242            rect = this.getBoundingClientRect();
243        if (!vertical && document.documentElement.clientWidth < rect.left + ul.clientWidth) {
244            ul.classList.add('dropdown-left-direction');
245        } else if (vertical && document.documentElement.clientHeight < rect.bottom + ul.clientHeight) {
246            ul.classList.add('dropdown-top-direction');
247            ul.style.setProperty('--dropdown-top-diff', (rect.bottom + ul.clientHeight - document.documentElement.clientHeight)+'px');
248        }
249    });
250    $g('#'+key).on('mouseenter.test', 'li.deeper.parent > ul li.deeper.parent', function(){
251        let vertical = this.closest('.ba-menu-wrapper').classList.contains('vertical-menu'),
252            ul = this.querySelector('ul'),
253            rect = this.getBoundingClientRect();
254        if (!vertical && document.documentElement.clientWidth < rect.right + ul.clientWidth) {
255            ul.classList.add('child-dropdown-left-direction');
256        } else if (vertical && document.documentElement.clientHeight < rect.bottom + ul.clientHeight) {
257            ul.classList.add('dropdown-top-direction');
258            ul.style.setProperty('--dropdown-top-diff', (rect.bottom + ul.clientHeight - document.documentElement.clientHeight)+'px');
259        }
260    });
261    if (themeData.page.view != 'gridbox') {
262        let endCoords = {};
263        let startCoords = {}
264        $g('#'+key).on('touchstart', function(event){
265            endCoords = event.originalEvent.targetTouches[0];
266            startCoords = event.originalEvent.targetTouches[0];
267        }).on('touchmove', function(event){
268            endCoords = event.originalEvent.targetTouches[0];
269        }).on('touchend', function(){
270            let hDistance = endCoords.pageX - startCoords.pageX,
271                xAbs = Math.abs(endCoords.pageX - startCoords.pageX),
272                yAbs = Math.abs(endCoords.pageY - startCoords.pageY);
273            if (hDistance >= 100 && xAbs >= yAbs * 2) {
274                $g('#'+key+' .ba-menu-backdrop').trigger('click');
275            }
276        });
277    }
278    initItems();
279}
280
281function setMegamenuPosition(li)
282{
283    let rectangle = li.getBoundingClientRect(),
284        comp = getComputedStyle(document.body),
285        borderLeft = comp.borderLeftWidth.replace('px', '') * 1,
286        left = rectangle.left - borderLeft,
287        wrapper = $g(li).find(' > div.tabs-content-wrapper'),
288        width = document.body.clientWidth;
289    wrapper[0].style.setProperty('--menu-item-left-offset', left+'px');
290    wrapper[0].style.setProperty('--menu-item-width', li.offsetWidth+'px');
291    wrapper.css({
292        'margin-left': '',
293        'width': width+'px',
294        'max-width': ''
295    });
296    const itemsSelectors = [
297        '.ba-item-slideshow',
298        '.ba-item-slideset',
299        '.ba-item-carousel',
300        '.ba-item-map',
301        '.ba-item-recent-posts-slider',
302        '.ba-item-openstreetmap',
303        '.ba-item-recent-posts'
304    ]
305    wrapper.find(itemsSelectors.join(', ')).each(function(){
306        let object = {
307            data: app.items[this.id],
308            selector: this.id
309        };
310        app.checkModule('initItems', object);
311    });
312}
313
314if (app.modules.initmenu) {
315    app.initmenu(app.modules.initmenu.data, app.modules.initmenu.selector);
316}

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.