PageSourceSearch

https://assets.viewstub.com/wp/wp-content/plugins/hashbar-wp-notification-bar/assets/js/frontend.js?ver=1.3.8

js viewstub.com collected 2026-09-24 09:25:31 UTC 17,651 bytes, 379 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    var timeout = 400;
28    $(window).on('load',function(){
29        var top_notification_height         = Number.parseInt($('.hthb-notification.hthb-pos--top').last().height()),
30            bottom_notification_height      = $('.hthb-notification.hthb-pos--bottom').last().height(),
31            left_wall_notification_width    = $('.hthb-notification.hthb-pos--left-wall').last().width(),
32            right_wall_notification_width   = $('.hthb-notification.hthb-pos--right-wall').last().width();
33
34        var position;
35
36        // if load as minimized disabled
37        $('.hthb-notification.hthb-state--open').each(function(){
38            position = $(this).getPostion();
39
40            if( position == 'top' ){
41                $('body').addClass('hthb hthb-pt--' + top_notification_height );
42                if( $(this).get_transparent_selector() ){
43
44                    $($(this).get_transparent_selector()).addClass('hthb-top-unset');
45                    $($(this).get_transparent_selector()).css( {'top':'unset'} );
46
47                }
48            } else if( position == 'bottom'){
49                $('body').css('padding-bottom', bottom_notification_height + 'px');
50            }
51
52            // Implement how many time to show
53            var time_to_show           = $(this).data('time_to_show'),
54                id                     = $(this).data('id') ? '_' + $(this).data('id') : '', 
55                coockie_count          = Cookies.get('hashbarpro_cookiecount' + id),
56                hashbarpro_oldcookie   = Cookies.get('hashbarpro_oldcookie' + id);
57
58            if( time_to_show && time_to_show > 0 ){
59
60                if(document.cookie.indexOf("hashbarpro_oldcookie" + id) >= 0){
61                    if(time_to_show == hashbarpro_oldcookie){
62                        coockie_count++;
63                        Cookies.set('hashbarpro_cookiecount' + id, coockie_count, { expires: 7 });
64                    } else {
65                        Cookies.set('hashbarpro_oldcookie' + id, time_to_show, { expires: 7 });
66                        Cookies.set('hashbarpro_cookiecount' + id, 1, { expires: 7 });
67                    }
68                } else {
69                    Cookies.set('hashbarpro_oldcookie' + id, time_to_show, { expires: 7 });
70                    Cookies.set('hashbarpro_cookiecount' + id, 1, { expires: 7 });
71                }
72            }
73
74            if( coockie_count > time_to_show ){
75               $(this).css({'display': 'none'});
76               $(this).removeClass('hthb-state--open').addClass('hthb-state--minimized');
77
78               if( position == 'top' ){
79                    $('body').removeClass('hthb');
80               }
81            }
82            
83        });
84
85        // Load as mimimized if option is set to minimized
86        $('.hthb-notification.hthb-state--minimized').each(function(){
87             var position = $(this).getPostion();
88             if( position == 'top' || position == 'top-promo' || position == 'bottom' || position == 'bottom-promo' ){
89                $(this).find('.hthb-row').css('display', 'none');
90             }
91            
92        });
93
94        // Left/right wall
95        $('.hthb-notification.hthb-state--minimized').each(function(){
96            var position = $(this).getPostion();
97            if( position == 'left-wall' ){
98                  $(this).css('left', '-' + left_wall_notification_width + 'px' );
99            } else if( position == 'right-wall' ){
100                 $(this).css('right', '-' + right_wall_notification_width + 'px' );
101            }
102           
103        });
104
105        setTimeout(function(){
106            $('.hthb-notification').addClass('hthb-loaded');
107        }, timeout );
108
109        // When click close button
110        $('.hthb-close-toggle').on('click', function(){
111            $(this).minimizeNotification( top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width);
112
113            // Keep closed
114            if( hashbar_localize.bar_keep_closed == '1' ){
115                Cookies.set('keep_closed_bar', '1', { expires: 7, path: '/' });
116            }
117
118            // Don't show forever
119            if( hashbar_localize.dont_show_bar_after_close == '1' ){
120                Cookies.set( 'dont_show_bar', '1', { expires: 7, path: '/' } );
121            }
122        });
123
124        // When clicked open button
125        $('.hthb-open-toggle').on('click', function(){
126            $(this).showNotification( top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width );
127        });
128
129        // When scroll position matched with a notification
130        // Show the notifications
131        var window_inner_height             = $(window).height(),
132            page_height                     = $('body').height();
133
134        let current_scroll_position         = window.pageYOffset || document.documentElement.scrollTop,
135            current_scroll_position_percent = current_scroll_position / scroll_pos_max * 100;
136            current_scroll_position_percent = Number.parseInt(current_scroll_position_percent);
137
138        var scroll_pos_max = $(document).height() - $(window).height();
139
140        $(window).on('scroll', function(e){
141            current_scroll_position         = $(window).scrollTop(),
142            current_scroll_position_percent = current_scroll_position / scroll_pos_max * 100;
143            current_scroll_position_percent = Number.parseInt(current_scroll_position_percent);
144
145            $(`.hthb-scroll`).each(function(){
146                let scroll_to_show = $(this).data('scroll_to_show'),
147                    scroll_to_hide = $(this).data('scroll_to_hide');
148
149                $(this).trigger_notification_on_scroll(scroll_to_show, scroll_to_hide, current_scroll_position, scroll_pos_max);
150            });
151        });
152    });
153    
154    /**
155     * Calculate % of a given value.
156     * For example, If the give value is 1000 & we want to know the 75% of it.
157     * It will return 750 as the result.
158     *
159     * @param number percent_amount, % amount.
160     * @param number percent_of, Total amount from where the % should be calculated.
161     * @return number
162     */
163    function percent_of(percent_amount, percent_of){
164        percent_of = Number.parseInt(percent_of);
165        percent_amount = Number.parseInt(percent_amount);
166        
167        return percent_of * percent_amount / 100;
168    }
169
170    $.fn.getPostion = function(){
171        if(this.closest('.hthb-notification').hasClass('hthb-pos--top')){
172            return 'top';
173        }
174
175        if(this.closest('.hthb-notification').hasClass('hthb-pos--bottom')){
176            return 'bottom';
177        }
178
179        if(this.closest('.hthb-notification').hasClass('hthb-pos--left-wall')){
180            return 'left-wall';
181        }
182
183        if(this.closest('.hthb-notification').hasClass('hthb-pos--right-wall')){
184            return 'right-wall';
185        }
186
187        if(this.closest('.hthb-notification').hasClass('hthb-pos--bottom-promo')){
188            return 'bottom-promo';
189        }
190
191        if(this.closest('.hthb-notification').hasClass('hthb-pos--top-promo')){
192            return 'top-promo';
193        }
194    }
195
196    $.fn.minimizeNotification = function(top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width){
197        var postion = this.getPostion(),
198            left_wall_notification_width = this.closest('.hthb-notification').width(),
199            right_wall_notification_width = this.closest('.hthb-notification').width();
200
201        this.closest('.hthb-notification').removeClass('hthb-state--open');
202        this.closest('.hthb-notification').addClass('hthb-state--minimized');
203
204        if(postion != 'left-wall' && postion != 'right-wall'){
205            this.closest('.hthb-notification').find('.hthb-row').slideToggle();
206        }
207        
208        if( postion == 'top' ){
209            $('body').removeClass('hthb');
210
211            // for sticky
212            if( this.get_transparent_selector() ){
213                $(this.get_transparent_selector()).addClass('hthb-top-unset');
214                $(this.get_transparent_selector()).css({'top': calculate_top_zero()});
215            }
216        } else if( postion == 'bottom' ){
217            $('body').css('padding-bottom', '');
218        } else if( postion == 'left-wall' ){
219            this.closest('.hthb-notification').css('left', '-' + left_wall_notification_width + 'px' );
220        } else if( postion == 'right-wall' ){
221            this.closest('.hthb-notification').css('right', '-' + right_wall_notification_width + 'px' );
222        }
223    }
224
225    $.fn.showNotification = function(top_notification_height, bottom_notification_height, left_wall_notification_width, right_wall_notification_width){
226        var postion = this.getPostion(),
227        left_wall_notification_width = this.closest('.hthb-notification').width(),
228        right_wall_notification_width = this.closest('.hthb-notification').width();
229
230        this.closest('.hthb-notification').removeClass('hthb-state--minimized');
231        this.closest('.hthb-notification').addClass('hthb-state--open');
232
233        if(postion != 'left-wall' && postion != 'right-wall'){
234            this.closest('.hthb-notification').find('.hthb-row').slideToggle();
235        }
236        
237        if( postion == 'top' ){
238            $('body').addClass('hthb hthb-pt--'+ top_notification_height );
239
240            // for sticky
241            if( this.get_transparent_selector() ){
242                $(this.get_transparent_selector()).addClass('hthb-top-unset');
243                $(this.get_transparent_selector()).css({'top': 'unset'});
244            }
245        } else if( postion == 'bottom' ){
246            $('body').css('padding-bottom', bottom_notification_height + 'px');
247        } else if( postion == 'left-wall' ){
248            this.closest('.hthb-notification').css('left', '');
249        } else if( postion == 'right-wall' ){
250            this.closest('.hthb-notification').css('right', '');
251        }
252    }
253
254    $.fn.trigger_click_on_open_button = function(){
255        $(this).addClass('hthb-trigger-open-clicked').removeClass('hthb-trigger-close-clicked');
256        $(this).find('.hthb-open-toggle').trigger('click');
257    }
258
259    $.fn.trigger_click_on_close_button = function(){
260        $(this).removeClass('hthb-trigger-open-clicked').addClass('hthb-trigger-close-clicked');
261        $(this).find('.hthb-close-toggle').trigger('click');
262    }
263
264    $.fn.check_keep_close_bar = function(){
265        var keep_closed_bar = Cookies.get('keep_closed_bar');
266        if( hashbar_localize.bar_keep_closed === '1' && keep_closed_bar){
267            return false;
268        }else{
269            return true;
270        }
271    }
272
273    $.fn.trigger_notification_on_scroll = function( scroll_to_show, scroll_to_hide, current_scroll_position, scroll_pos_max ){
274        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 ){
275            scroll_to_show = Number.parseInt(scroll_to_show);
276            scroll_to_hide = Number.parseInt(scroll_to_hide);
277            // 20% ,  80%
278            // console.log(1,scroll_to_show,scroll_to_hide,current_scroll_position, percent_of(scroll_to_hide, scroll_pos_max));
279
280            if(current_scroll_position > percent_of(scroll_to_show, scroll_pos_max) &&  current_scroll_position < percent_of(scroll_to_hide, scroll_pos_max) ){
281                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
282                    if($(this).check_keep_close_bar()){
283                        $(this).trigger_click_on_open_button(); // show
284                    }
285                }
286            } else{
287                if( !$(this).is('.hthb-state--minimized') ){
288                    $(this).trigger_click_on_close_button(); // hide
289                }
290            }
291        } else if( (scroll_to_show && typeof scroll_to_show == 'string' && scroll_to_show.indexOf('%')) &&  (scroll_to_hide === '' || scroll_to_hide == undefined) ){
292            scroll_to_show = Number.parseInt(scroll_to_show);
293            // 20% , ''/undefined
294            // console.log(2,scroll_to_show,scroll_to_hide,current_scroll_position, percent_of(scroll_to_hide, scroll_pos_max));
295
296            if( current_scroll_position > percent_of(scroll_to_show, scroll_pos_max) ){
297                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
298                    if($(this).check_keep_close_bar()){
299                        $(this).trigger_click_on_open_button(); // show
300                    }
301                }
302            } else {
303                if( !$(this).is('.hthb-state--minimized') ){
304                    $(this).trigger_click_on_close_button(); // hide
305                }
306            }
307        } else if( (scroll_to_show && typeof scroll_to_show == 'number') && (scroll_to_hide && typeof scroll_to_hide == 'string')){
308            // 300 , 80%
309            // console.log(3,scroll_to_show,scroll_to_hide,current_scroll_position, percent_of(scroll_to_hide, scroll_pos_max));
310
311            if( current_scroll_position > scroll_to_show &&  current_scroll_position < percent_of(scroll_to_hide, scroll_pos_max) ){
312                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
313                    if($(this).check_keep_close_bar()){
314                        $(this).trigger_click_on_open_button(); // show
315                    }
316                }
317            } else{
318                if( !$(this).is('.hthb-state--minimized') ){
319                    $(this).trigger_click_on_close_button(); // hide
320                }
321            }
322
323        } else if( (scroll_to_show === '' || scroll_to_show == undefined) && (scroll_to_hide && typeof scroll_to_hide == 'string' && scroll_to_hide.indexOf('%')) ){
324            scroll_to_hide = Number.parseInt(scroll_to_hide);
325            // empty / undefined , 90%
326            // console.log(4,scroll_to_show,scroll_to_hide,current_scroll_position, percent_of(scroll_to_hide, scroll_pos_max));
327
328            if( current_scroll_position > percent_of(scroll_to_hide, scroll_pos_max) ){
329                if( !$(this).is('.hthb-state--minimized') ){
330                    $(this).trigger_click_on_close_button(); // hide
331                }
332            } else{
333                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
334                    if($(this).check_keep_close_bar()){
335                        $(this).trigger_click_on_open_button(); // show 
336                    }
337                }
338            }
339
340        } else if( (scroll_to_show && typeof scroll_to_show == 'number') && (scroll_to_hide === '' || scroll_to_hide == undefined) ){
341            // 300 , empty/undefined 
342            // console.log(5,scroll_to_show,scroll_to_hide,current_scroll_position, percent_of(scroll_to_hide, scroll_pos_max));
343            if( current_scroll_position < scroll_to_show ){
344                if( !$(this).is('.hthb-state--minimized') ){
345                    $(this).trigger_click_on_close_button(); // hide
346                }
347
348            } else{
349                if( !$(this).is('.hthb-state--open') && !$(this).is('.hthb-trigger-open-clicked') ){
350                    if($(this).check_keep_close_bar()){
351                        $(this).trigger_click_on_open_button(); // show
352                    }
353                }
354            }
355            
356        } else {
357            console.log(`Invalid formate  Scroll to show=${typeof scroll_to_show} ${scroll_to_show } scroll_to_hide=${typeof scroll_to_hide} ${scroll_to_hide}`);
358        }
359    }
360
361    $(document).ready(function(){
362        $(".hthb-countdown").each(function(){
363            var countdown_id = "#"+$(this).attr('id')+" .hthb-countdown-section .hthb-countdown-wrap",
364                finalDate    = $(countdown_id).data('countdown'),
365                customLabel  = $(countdown_id).data('custom_label');
366            $(countdown_id).countdown(finalDate, function (event) {
367                $(countdown_id+' .countdown-day').html(event.strftime('%D'));
368                $(countdown_id+' .countdown-day-text').html(customLabel.day);
369                $(countdown_id+' .countdown-hour').html(event.strftime('%H'));
370                $(countdown_id+' .countdown-hour-text').html(customLabel.hour);
371                $(countdown_id+' .countdown-minute').html(event.strftime('%M'));
372                $(countdown_id+' .countdown-minite-text').html(customLabel.min);
373                $(countdown_id+' .countdown-second').html(event.strftime('%S'));
374                $(countdown_id+' .countdown-second-text').html(customLabel.sec);
375            });
376        });
377
378    });
379})(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.