PageSourceSearch

https://lazoo.org/wp-content/plugins/hashbar-wp-notification-bar/assets/js/frontend.js?ver=2.0.4

js lazoo.org collected 2026-09-24 09:25:25 UTC 25,933 bytes, 596 lines download raw bytes

1;(function ($) {
2    "use strict";
3
4    $.fn.get_transparent_selector = function get_transparent_selector(){
5        let transparent_header_selector = $(this).closest('.hthb-notification.hthb-pos--top[data-transparent_header_selector]').last().data('transparent_header_selector');
6        if($(this).closest('.hthb-notification.hthb-pos--top').hasClass('hthb-transparent')){
7            return transparent_header_selector;
8        }
9
10        return false;
11    }
12
13    $.fn.add_transparent_header_spacing = function add_transparent_header_spacing(top_notification_height){
14        if( $('body').find('#wpadminbar').length ){
15            top_notification_height = Number.parseInt(top_notification_height + $('body').find('#wpadminbar').height());
16        }
17    }
18
19    function calculate_top_zero(){
20        if( $('body').find('#wpadminbar').length ){
21            return '32px';
22        } else{
23            return '0px';
24        }
25    }
26
27    // Move notification bars to start of <body> so DOM order matches visual order.
28    // Bars are injected via wp_footer (end of body) but display fixed at top/bottom.
29    // Without this, keyboard Tab reaches close button only after all page content.
30    $(document).ready(function () {
31        $('body').prepend($('.hthb-notification'));
32    });
33
34    var timeout = 400;
35    $(window).on('load',function(){
36        var top_notification_height         = Number.parseInt($('.hthb-notification.hthb-pos--top').last().height()),
37            bottom_notification_height      = $('.hthb-notification.hthb-pos--bottom').last().height(),
38            left_wall_notification_width    = $('.hthb-notification.hthb-pos--left-wall').last().width(),
39            right_wall_notification_width   = $('.hthb-notification.hthb-pos--right-wall').last().width();
40
41        var position;
42
43        // if load as minimized disabled
44        $('.hthb-notification.hthb-state--open').each(function(){
45            position = $(this).getPostion();
46
47            if( position == 'top' ){
48                $('body').addClass('hthb hthb-pt--' + top_notification_height );
49                if( $(this).get_transparent_selector() ){
50
51                    $($(this).get_transparent_selector()).addClass('hthb-top-unset');
52                    $($(this).get_transparent_selector()).css( {'top':'unset'} );
53
54                }
55            } else if( position == 'bottom'){
56                $('body').css('padding-bottom', bottom_notification_height + 'px');
57            }
58
59            // Implement how many time to show
60            var time_to_show           = $(this).data('time_to_show'),
61                id                     = $(this).data('id') ? '_' + $(this).data('id') : '', 
62                coockie_count          = Cookies.get('hashbarpro_cookiecount' + id),
63                hashbarpro_oldcookie   = Cookies.get('hashbarpro_oldcookie' + id);
64
65            if( time_to_show && time_to_show > 0 ){
66
67                if(document.cookie.indexOf("hashbarpro_oldcookie" + id) >= 0){
68                    if(time_to_show == hashbarpro_oldcookie && coockie_count){
69                        coockie_count++;
70                        Cookies.set('hashbarpro_cookiecount' + id, coockie_count, { expires: 7 });
71                    } else {
72                        Cookies.set('hashbarpro_oldcookie' + id, time_to_show, { expires: 7 });
73                        Cookies.set('hashbarpro_cookiecount' + id, 1, { expires: 7 });
74                    }
75                } else {
76                    Cookies.set('hashbarpro_oldcookie' + id, time_to_show, { expires: 7 });
77                    Cookies.set('hashbarpro_cookiecount' + id, 1, { expires: 7 });
78                }
79            }
80
81            if( coockie_count > time_to_show ){
82               $(this).css({'display': 'none'});
83               $(this).removeClass('hthb-state--open').addClass('hthb-state--minimized');
84
85               if( position == 'top' ){
86                    $('body').removeClass('hthb');
87               }
88            }
89            
90        });
91
92        // Load as mimimized if option is set to minimized
93        $('.hthb-notification.hthb-state--minimized').each(function(){
94             var position = $(this).getPostion();
95             if( position == 'top' || position == 'top-promo' || position == 'bottom' || position == 'bottom-promo' ){
96                $(this).find('.hthb-row').css('display', 'none');
97             }
98            
99        });
100
101        // Left/right wall
102        $('.hthb-notification.hthb-state--minimized').each(function(){
103            var position = $(this).getPostion();
104            if( position == 'left-wall' ){
105                  $(this).css('left', '-' + left_wall_notification_width + 'px' );
106            } else if( position == 'right-wall' ){
107                 $(this).css('right', '-' + right_wall_notification_width + 'px' );
108            }
109           
110        });
111
112        setTimeout(function(){
113            $('.hthb-notification').addClass('hthb-loaded');
114        }, timeout );
115
116        $('.hthb-notification').each(function() {
117            const delay_time = $(this).attr('data-delay_time');
118            if(+delay_time) {
119                setTimeout(() => {
120                    $(this).showNotification( top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width );
121                }, +delay_time*1000);
122            }
123        })
124
125        // When click close button
126        $('.hthb-close-toggle').on('click', function(){
127            const $notification = $(this).closest('.hthb-notification');
128            const $hthb_id = $notification[0].dataset.id;
129            let $expire_time = +hashbar_localize.cookies_expire_time
130            if(hashbar_localize.cookies_expire_type === 'hours') {
131                $expire_time = $expire_time/24;
132            }
133            if(hashbar_localize.cookies_expire_type === 'minutes') {
134                $expire_time = $expire_time/1440;
135            }
136
137            $(this).minimizeNotification( top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width);
138
139            // Mark as manually closed to prevent scroll-based reopening
140            $notification.addClass('hthb-manually-closed');
141
142            // Keep closed
143            if( hashbar_localize.bar_keep_closed == '1' ){
144                Cookies.set(`keep_closed_bar_${$hthb_id}`, '1', { expires: $expire_time, path: '/' });
145            }
146
147            // Don't show forever
148            if( hashbar_localize.dont_show_bar_after_close == '1' ) {
149                Cookies.set( `dont_show_bar_${$hthb_id}`, '1', { expires: $expire_time, path: '/' } );
150            }
151        });
152
153        // When clicked open button
154        $('.hthb-open-toggle').on('click', function(){
155            // Remove manually-closed class to allow reopening
156            $(this).closest('.hthb-notification').removeClass('hthb-manually-closed');
157            $(this).showNotification( top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width );
158        });
159
160        // Enter / Space on custom controls (role="button" on <span>)
161        $('.hthb-close-toggle, .hthb-open-toggle').on('keydown', function (e) {
162            if (e.key !== 'Enter' && e.key !== ' ') {
163                return;
164            }
165            e.preventDefault();
166            $(this).trigger('click');
167        });
168
169        // When scroll position matched with a notification
170        // Show the notifications
171        var window_inner_height             = $(window).height(),
172            page_height                     = $('body').height();
173
174        let current_scroll_position         = window.pageYOffset || document.documentElement.scrollTop,
175            current_scroll_position_percent = current_scroll_position / scroll_pos_max * 100;
176            current_scroll_position_percent = Number.parseInt(current_scroll_position_percent);
177
178        var scroll_pos_max = $(document).height() - $(window).height();
179
180        $(window).on('scroll', function(e){
181            current_scroll_position         = $(window).scrollTop(),
182            current_scroll_position_percent = current_scroll_position / scroll_pos_max * 100;
183            current_scroll_position_percent = Number.parseInt(current_scroll_position_percent);
184
185            $(`.hthb-scroll`).each(function(){
186                let scroll_to_show = $(this).data('scroll_to_show'),
187                    scroll_to_hide = $(this).data('scroll_to_hide'),
188                    hthb_id = $(this)[0].dataset.id;
189
190                $(this).trigger_notification_on_scroll(hthb_id, scroll_to_show, scroll_to_hide, current_scroll_position, scroll_pos_max);
191            });
192        });
193    });
194    
195    /**
196     * Calculate % of a given value.
197     * For example, If the give value is 1000 & we want to know the 75% of it.
198     * It will return 750 as the result.
199     *
200     * @param number percent_amount, % amount.
201     * @param number percent_of, Total amount from where the % should be calculated.
202     * @return number
203     */
204    function percent_of(percent_amount, percent_of){
205        percent_of = Number.parseInt(percent_of);
206        percent_amount = Number.parseInt(percent_amount);
207        
208        return percent_of * percent_amount / 100;
209    }
210
211    $.fn.getPostion = function(){
212        if(this.closest('.hthb-notification').hasClass('hthb-pos--top')){
213            return 'top';
214        }
215
216        if(this.closest('.hthb-notification').hasClass('hthb-pos--bottom')){
217            return 'bottom';
218        }
219
220        if(this.closest('.hthb-notification').hasClass('hthb-pos--left-wall')){
221            return 'left-wall';
222        }
223
224        if(this.closest('.hthb-notification').hasClass('hthb-pos--right-wall')){
225            return 'right-wall';
226        }
227
228        if(this.closest('.hthb-notification').hasClass('hthb-pos--bottom-promo')){
229            return 'bottom-promo';
230        }
231
232        if(this.closest('.hthb-notification').hasClass('hthb-pos--top-promo')){
233            return 'top-promo';
234        }
235    }
236
237    $.fn.minimizeNotification = function(top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width){
238        var postion = this.getPostion(),
239            left_wall_notification_width = this.closest('.hthb-notification').width(),
240            right_wall_notification_width = this.closest('.hthb-notification').width();
241
242        this.closest('.hthb-notification').removeClass('hthb-state--open');
243        this.closest('.hthb-notification').addClass('hthb-state--minimized');
244
245        if(postion != 'left-wall' && postion != 'right-wall'){
246            // Use slideUp instead of slideToggle to prevent double-toggle issue
247            this.closest('.hthb-notification').find('.hthb-row').slideUp();
248        }
249
250        if( postion == 'top' ){
251            $('body').removeClass('hthb');
252
253            // for sticky
254            if( this.get_transparent_selector() ){
255                $(this.get_transparent_selector()).addClass('hthb-top-unset');
256                $(this.get_transparent_selector()).css({'top': calculate_top_zero()});
257            }
258        } else if( postion == 'bottom' ){
259            $('body').css('padding-bottom', '');
260        } else if( postion == 'left-wall' ){
261            this.closest('.hthb-notification').css('left', '-' + left_wall_notification_width + 'px' );
262        } else if( postion == 'right-wall' ){
263            this.closest('.hthb-notification').css('right', '-' + right_wall_notification_width + 'px' );
264        }
265    }
266
267    $.fn.showNotification = function(top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width){
268        // Don't reopen if user manually closed the notification
269        if( this.closest('.hthb-notification').is('.hthb-manually-closed') ){
270            return;
271        }
272
273        var postion = this.getPostion(),
274        left_wall_notification_width = this.closest('.hthb-notification').width(),
275        right_wall_notification_width = this.closest('.hthb-notification').width();
276
277        this.closest('.hthb-notification').removeClass('hthb-state--minimized');
278        this.closest('.hthb-notification').addClass('hthb-state--open');
279
280        if(postion != 'left-wall' && postion != 'right-wall'){
281            // Use slideDown instead of slideToggle to prevent double-toggle issue
282            this.closest('.hthb-notification').find('.hthb-row').slideDown();
283        }
284
285        if( postion == 'top' ){
286            $('body').addClass('hthb hthb-pt--'+ top_notification_height );
287
288            // for sticky
289            if( this.get_transparent_selector() ){
290                $(this.get_transparent_selector()).addClass('hthb-top-unset');
291                $(this.get_transparent_selector()).css({'top': 'unset'});
292            }
293        } else if( postion == 'bottom' ){
294            $('body').css('padding-bottom', bottom_notification_height + 'px');
295        } else if( postion == 'left-wall' ){
296            this.closest('.hthb-notification').css('left', '');
297        } else if( postion == 'right-wall' ){
298            this.closest('.hthb-notification').css('right', '');
299        }
300    }
301
302    $.fn.trigger_click_on_open_button = function(){
303        // Don't reopen if user manually closed the notification
304        if( $(this).is('.hthb-manually-closed') ){
305            return;
306        }
307        $(this).addClass('hthb-trigger-open-clicked').removeClass('hthb-trigger-close-clicked');
308        $(this).find('.hthb-open-toggle').trigger('click');
309    }
310
311    $.fn.trigger_click_on_close_button = function(){
312        $(this).removeClass('hthb-trigger-open-clicked').addClass('hthb-trigger-close-clicked');
313        $(this).find('.hthb-close-toggle').trigger('click');
314    }
315
316    $.fn.check_keep_close_bar = function(id){
317        var keep_closed_bar = Cookies.get(`keep_closed_bar_${id}`);
318        if( hashbar_localize.bar_keep_closed === '1' && keep_closed_bar){
319            return false;
320        }else{
321            return true;
322        }
323    }
324
325    $.fn.trigger_notification_on_scroll = function( id, scroll_to_show, scroll_to_hide, current_scroll_position, scroll_pos_max ){
326        // Don't reopen if user manually closed the notification
327        if( $(this).is('.hthb-manually-closed') ){
328            return;
329        }
330
331        if( (scroll_to_show && typeof scroll_to_show == 'string' && scroll_to_show.indexOf('%')) > 0 && (scroll_to_hide && typeof scroll_to_hide == 'string' && scroll_to_hide.indexOf('%')) > 1 ){
332            scroll_to_show = Number.parseInt(scroll_to_show);
333            scroll_to_hide = Number.parseInt(scroll_to_hide);
334            // 20% ,  80%
335
336            if(current_scroll_position > percent_of(scroll_to_show, scroll_pos_max) &&  current_scroll_position < percent_of(scroll_to_hide, scroll_pos_max) ){
337                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
338                    if($(this).check_keep_close_bar(id)){
339                        $(this).trigger_click_on_open_button(); // show
340                    }
341                }
342            } else{
343                if( !$(this).is('.hthb-state--minimized') ){
344                    $(this).trigger_click_on_close_button(); // hide
345                }
346            }
347        } else if( (scroll_to_show && typeof scroll_to_show == 'string' && scroll_to_show.indexOf('%')) &&  (scroll_to_hide === '' || scroll_to_hide == undefined) ){
348            scroll_to_show = Number.parseInt(scroll_to_show);
349            // 20% , ''/undefined
350
351            if( current_scroll_position > percent_of(scroll_to_show, scroll_pos_max) ){
352                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
353                    if($(this).check_keep_close_bar(id)){
354                        $(this).trigger_click_on_open_button(); // show
355                    }
356                }
357            } else {
358                if( !$(this).is('.hthb-state--minimized') ){
359                    $(this).trigger_click_on_close_button(); // hide
360                }
361            }
362        } else if( (scroll_to_show && typeof scroll_to_show == 'number') && (scroll_to_hide && typeof scroll_to_hide == 'string')){
363            // 300 , 80%
364
365            if( current_scroll_position > scroll_to_show &&  current_scroll_position < percent_of(scroll_to_hide, scroll_pos_max) ){
366                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
367                    if($(this).check_keep_close_bar(id)){
368                        $(this).trigger_click_on_open_button(); // show
369                    }
370                }
371            } else{
372                if( !$(this).is('.hthb-state--minimized') ){
373                    $(this).trigger_click_on_close_button(); // hide
374                }
375            }
376
377        } else if( (scroll_to_show === '' || scroll_to_show == undefined) && (scroll_to_hide && typeof scroll_to_hide == 'string' && scroll_to_hide.indexOf('%')) ){
378            scroll_to_hide = Number.parseInt(scroll_to_hide);
379            // empty / undefined , 90%
380
381            if( current_scroll_position > percent_of(scroll_to_hide, scroll_pos_max) ){
382                if( !$(this).is('.hthb-state--minimized') ){
383                    $(this).trigger_click_on_close_button(); // hide
384                }
385            } else{
386                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
387                    if($(this).check_keep_close_bar(id)){
388                        $(this).trigger_click_on_open_button(); // show
389                    }
390                }
391            }
392
393        } else if( (scroll_to_show && typeof scroll_to_show == 'number') && (scroll_to_hide === '' || scroll_to_hide == undefined) ){
394            // 300 , empty/undefined
395            if( current_scroll_position < scroll_to_show ){
396                if( !$(this).is('.hthb-state--minimized') ){
397                    $(this).trigger_click_on_close_button(); // hide
398                }
399
400            } else{
401                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
402                    if($(this).check_keep_close_bar(id)){
403                        $(this).trigger_click_on_open_button(); // show
404                    }
405                }
406            }
407
408        } else {
409        }
410    }
411
412    $(document).ready(function(){
413        $(".hthb-countdown").each(function(){
414            var countdown_id = "#"+$(this).attr('id')+" .hthb-countdown-section .hthb-countdown-wrap",
415                finalDate    = $(countdown_id).data('countdown'),
416                customLabel  = $(countdown_id).data('custom_label');
417            $(countdown_id).countdown(finalDate, function (event) {
418                $(countdown_id+' .countdown-day').html(event.strftime('%D'));
419                $(countdown_id+' .countdown-day-text').html(customLabel.day);
420                $(countdown_id+' .countdown-hour').html(event.strftime('%H'));
421                $(countdown_id+' .countdown-hour-text').html(customLabel.hour);
422                $(countdown_id+' .countdown-minute').html(event.strftime('%M'));
423                $(countdown_id+' .countdown-minite-text').html(customLabel.min);
424                $(countdown_id+' .countdown-second').html(event.strftime('%S'));
425                $(countdown_id+' .countdown-second-text').html(customLabel.sec);
426            });
427        });
428
429        // Initialize new announcement bar countdowns
430        initializeNewAnnouncementBars();
431    });
432
433    /**
434     * Initialize new announcement bars with countdown timers
435     */
436    function initializeNewAnnouncementBars() {
437        var bars = document.querySelectorAll('.hashbar-announcement-bar');
438        if (bars.length === 0) {
439            return;
440        }
441
442        bars.forEach(function(bar) {
443            if (bar.getAttribute('data-countdown-enabled') === 'true') {
444                initializeCountdown(bar);
445            }
446        });
447    }
448
449    /**
450     * Initialize countdown timer
451     */
452    function initializeCountdown(bar) {
453        // Prevent multiple initializations on the same bar
454        if (bar.hasAttribute('data-countdown-initialized')) {
455            return;
456        }
457        bar.setAttribute('data-countdown-initialized', 'true');
458
459        var countdownType = bar.getAttribute('data-countdown-type');
460        var countdownDate = bar.getAttribute('data-countdown-date');
461
462        // Find the bar wrapper (parent of the bar if it exists)
463        var barWrapper = bar.parentElement && bar.parentElement.classList.contains('hashbar-announcement-bar-wrapper')
464            ? bar.parentElement
465            : bar;
466
467        // Query all countdown timers in the wrapper (could be before, inline, after, or below)
468        var timerElements = barWrapper.querySelectorAll('.hashbar-countdown-timer');
469
470        if (timerElements.length === 0 || !countdownDate) {
471            return;
472        }
473
474        // Update all countdown timers immediately and then every second
475        timerElements.forEach(function(timerElement) {
476            updateCountdown(timerElement, countdownDate, countdownType);
477        });
478
479        // Store the interval ID on the bar for potential cleanup
480        var intervalId = setInterval(function() {
481            timerElements.forEach(function(timerElement) {
482                updateCountdown(timerElement, countdownDate, countdownType);
483            });
484        }, 1000);
485
486        bar.setAttribute('data-countdown-interval', intervalId);
487    }
488
489    /**
490     * Update countdown display
491     */
492    function updateCountdown(timerElement, countdownDate, countdownType) {
493        var now = new Date().getTime();
494        var countDate = new Date(countdownDate).getTime();
495        var distance = countDate - now;
496
497        if (distance < 0) {
498            timerElement.textContent = 'Ended';
499            return;
500        }
501
502        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
503        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
504        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
505        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
506
507        // Get display options from element attributes
508        var showDays = timerElement.getAttribute('data-show-days') !== 'false';
509        var showHours = timerElement.getAttribute('data-show-hours') !== 'false';
510        var showMinutes = timerElement.getAttribute('data-show-minutes') !== 'false';
511        var showSeconds = timerElement.getAttribute('data-show-seconds') !== 'false';
512
513        // Determine style (simple, digital, circular)
514        var style = timerElement.getAttribute('data-countdown-style') || 'simple';
515
516        if (style === 'simple') {
517            // Simple text format: "5d 3h 45m 30s"
518            var parts = [];
519            if (showDays && days > 0) parts.push(days + 'd');
520            if (showHours && hours > 0) parts.push(hours + 'h');
521            if (showMinutes && minutes > 0) parts.push(minutes + 'm');
522            if (showSeconds) parts.push(seconds + 's');
523
524            timerElement.textContent = parts.length > 0 ? parts.join(' ') : '0s';
525        } else if (style === 'digital') {
526            // Digital format: "05:03:45:30"
527            var displayText = '';
528            if (showDays) displayText += padZero(days) + ':';
529            if (showHours) displayText += padZero(hours) + ':';
530            if (showMinutes) displayText += padZero(minutes) + ':';
531            if (showSeconds) displayText += padZero(seconds);
532
533            // Remove trailing colon if no seconds are shown
534            timerElement.textContent = displayText.replace(/:$/, '');
535        } else if (style === 'circular' || style === 'box') {
536            // Circular or box format - update boxes
537            updateBoxCountdown(timerElement, days, hours, minutes, seconds, showDays, showHours, showMinutes, showSeconds);
538        } else if (countdownType === 'compact') {
539            // Legacy compact format
540            if (days > 0) {
541                timerElement.textContent = days + 'd ' + hours + 'h';
542            } else if (hours > 0) {
543                timerElement.textContent = hours + 'h ' + minutes + 'm';
544            } else {
545                timerElement.textContent = minutes + 'm ' + seconds + 's';
546            }
547        } else {
548            // Legacy detailed format
549            timerElement.textContent = padZero(days) + ':' + padZero(hours) + ':' + padZero(minutes) + ':' + padZero(seconds);
550        }
551    }
552
553    /**
554     * Update box-style countdown display (circular or rounded squares)
555     */
556    function updateBoxCountdown(timerElement, days, hours, minutes, seconds, showDays, showHours, showMinutes, showSeconds) {
557        // Update days box (works with both .countdown-circle-box and .countdown-box classes)
558        if (showDays) {
559            var daysBox = timerElement.querySelector('.countdown-days');
560            if (daysBox) {
561                daysBox.textContent = String(days).padStart(2, '0');
562            }
563        }
564
565        // Update hours box
566        if (showHours) {
567            var hoursBox = timerElement.querySelector('.countdown-hours');
568            if (hoursBox) {
569                hoursBox.textContent = String(hours).padStart(2, '0');
570            }
571        }
572
573        // Update minutes box
574        if (showMinutes) {
575            var minutesBox = timerElement.querySelector('.countdown-minutes');
576            if (minutesBox) {
577                minutesBox.textContent = String(minutes).padStart(2, '0');
578            }
579        }
580
581        // Update seconds box
582        if (showSeconds) {
583            var secondsBox = timerElement.querySelector('.countdown-seconds');
584            if (secondsBox) {
585                secondsBox.textContent = String(seconds).padStart(2, '0');
586            }
587        }
588    }
589
590    /**
591     * Pad number with leading zero
592     */
593    function padZero(num) {
594        return (num < 10 ? '0' : '') + num;
595    }
596})(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.