1(function($){ 2$(document).ready(function(){ 3 4 $('.ancr').each(function(){ 5 var $ancr = $(this); 6 this.announcer = new Announcer($ancr); 7 }); 8 9}); 10})(jQuery); 11 12function Announcer_Position(){ 13 this.spacer = false; 14 this.normal_moved = false; 15 16 this.sticky_offset = 0; 17 this.sticky_group = false; 18 this.sticky_elements = false; 19} 20 21function Announcer_State(){ 22 23 this.bars = []; 24 this.top = new Announcer_Position(); 25 this.bottom = new Announcer_Position(); 26 this.on_scroll_bars = []; 27 28 this.listen_on_scroll(); 29 30} 31 32Announcer_State.prototype.add = function(bar){ 33 34 var position = bar.props.position; 35 var position_class = '.ancr-pos-' + position; 36 37 this.bars.push(bar); 38 39 if(bar.props.sticky == 'yes'){ 40 this.add_spacer(position); 41 if(!this[position].sticky_group){ 42 this[position].sticky_group = jQuery(position_class + '.ancr-sticky'); 43 } 44 }else{ 45 if(position == 'top'){ 46 if(!this[position].normal_moved){ 47 var normal_class = position_class + '.ancr-normal'; 48 if(this[position].spacer){ 49 jQuery(normal_class).detach().insertAfter(this[position].spacer); 50 }else{ 51 jQuery(normal_class).detach().prependTo('body'); 52 } 53 this[position].normal_moved = true; 54 } 55 } 56 } 57 58 if(bar.props.show_on == 'page_scroll'){ 59 this.on_scroll_bars.push(bar); 60 } 61 62} 63 64Announcer_State.prototype.add_spacer = function(position){ 65 if(!this[position].spacer){ 66 var $spacer = jQuery('<div class="ancr-' + position + '-spacer"></div>'); 67 this[position].spacer = $spacer; 68 if(position == 'top'){ 69 jQuery('body').prepend($spacer); 70 }else{ 71 jQuery('body').append($spacer); 72 } 73 } 74} 75 76Announcer_State.prototype.update_offsets = function(position){ 77 78 if(this[position].sticky_group){ 79 this[position].sticky_offset = this[position].sticky_group.outerHeight(); 80 this[position].spacer.animate({height: this[position].sticky_offset}, 200); 81 if(jQuery('body').hasClass('admin-bar')){ 82 jQuery('html').css('margin-top', this[position].sticky_offset + 'px'); 83 } 84 } 85 86} 87 88Announcer_State.prototype.set_cookie = function(name, value, expiry_days, site_wide){ 89 90 if(('' + name).includes('PREVIEW')){ 91 return; 92 } 93 94 var expires = ''; 95 var path = '; path=/'; 96 97 if(expiry_days) { 98 var date = new Date(); 99 date.setTime(date.getTime()+(expiry_days*24*60*60*1000)); 100 expires = "; expires=" + date.toGMTString(); 101 } 102 103 if(!site_wide){ 104 path = '; path=' + window.location.pathname; 105 } 106 107 document.cookie = name + '=' + value + expires + path; 108 109} 110 111Announcer_State.prototype.get_cookie = function(name){ 112 113 var name_eq = name + "="; 114 var ca = document.cookie.split(';'); 115 116 for(var i = 0; i < ca.length; i++) { 117 var c = ca[i]; 118 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 119 120 if (c.indexOf(name_eq) == 0){ 121 return c.substring(name_eq.length, c.length); 122 } 123 } 124 125 return null; 126 127} 128 129Announcer_State.prototype.listen_on_scroll = function(){ 130 131 var self = this; 132 var $ = jQuery; 133 134 $(window).scroll(function(){ 135 var at = $(window).scrollTop(); 136 137 for(var i = 0; i < self.on_scroll_bars.length; i++){ 138 var bar = self.on_scroll_bars[i]; 139 140 if(at >= bar.props.show_after_scroll){ 141 if(!bar.is_shown){ 142 if(bar.can_show()) bar.show(); 143 } 144 }else{ 145 if(bar.is_shown){ 146 bar.hide(false); 147 } 148 } 149 } 150 151 }); 152 153} 154 155Announcer_State.prototype.adjust_fixed_elements = function(){ 156 157 var top = this['top']; 158 159 if(!top.sticky_group){ 160 return; 161 } 162 163 if(!top.sticky_elements){ 164 165 var possible_stickies = document.querySelectorAll('div, header, nav'); 166 top.sticky_elements = []; 167 168 for(var i = 0; i < possible_stickies.length; i++){ 169 var element = possible_stickies[i]; 170 171 if(element.className.includes('ancr-')){ 172 continue; 173 } 174 175 var element_bound = element.getBoundingClientRect(); 176 var element_style = window.getComputedStyle(element, null); 177 178 if(element_style.position === 'fixed' && element_style.display != 'none' && element_bound.top <= top['sticky_offset'] && element_bound.left == 0){ 179 top.sticky_elements.push(element); 180 } 181 } 182 183 } 184 185 for(i = 0; i < top.sticky_elements.length; i++){ 186 var element = top.sticky_elements[i]; 187 element.style.top = top['sticky_offset'] + 'px'; 188 } 189 190} 191 192Announcer_State.prototype.is_mobile = function(){ 193 return /Mobi|Android/i.test(navigator.userAgent); 194} 195 196window.ancr_state = new Announcer_State(); 197 198function Announcer($el){ 199 200 this.$el = $el; 201 this.props = $el.data('props'); 202 this.id = this.props.id; 203 this.is_shown = false; 204 this.close_cookie = 'ancr_close_' + this.id; 205 this.force_closed = false; 206 207 ancr_state.add(this); 208 209 this.register_events(); 210 this.check_show(); 211 212} 213 214Announcer.prototype.register_events = function(){ 215 216 var self = this; 217 var $close_btn = this.$el.find('.ancr-close'); 218 219 if(this.props.close_content_click == 'yes'){ 220 $close_btn = $close_btn.add(this.$el.find('.ancr-inner a')); 221 } 222 223 if($close_btn.length != 0){ 224 $close_btn.on('click', function(e){
225 if(jQuery(this).attr('href') == '#'){ 226 e.preventDefault(); 227 } 228 self.hide(); 229 if(self.props.show_on == 'page_scroll'){ 230 self.force_closed = true; 231 } 232 }); 233 } 234 235 if(this.props.layout == 'ticker'){ 236 var initialize_ticker = function(){ 237 self.$el[0].style.setProperty('--ancr-width', self.$el.outerWidth() + 'px'); 238 var $content = self.$el.find('.ancr-content'); 239 var $btn_wrap = self.$el.find('.ancr-btn-wrap'); 240 var total_width = $content.outerWidth() + ($btn_wrap.length ? $btn_wrap.outerWidth() : 0); 241 self.$el.find('.ancr-container').css({ 242 'min-width': total_width + 30, 243 'visibility': 'visible' 244 }); 245 246 var ticker_speed = self.props.ticker_speed; 247 self.$el[0].style.setProperty('--ancr-ticker-speed', ticker_speed + 's'); 248 249 // Start the ticker animation 250 self.$el.addClass('ancr-lo-ticker-anim'); 251 }; 252 jQuery(window).on('resize', initialize_ticker); 253 setTimeout(function(){ 254 initialize_ticker(); 255 }, 500); 256 } 257 258} 259 260Announcer.prototype.can_show = function(){ 261 262 if(this.props.display == 'custom'){ 263 return false; 264 } 265 266 var closed_cookie = ancr_state.get_cookie(this.close_cookie); 267 268 if(this.props.devices == 'mobile_only' && !ancr_state.is_mobile()){ 269 return false; 270 } 271 272 if(this.props.devices == 'desktop_only' && ancr_state.is_mobile()){ 273 return false; 274 } 275 276 if(this.props.keep_closed == 'yes' && closed_cookie){ 277 return false; 278 } 279 280 if(this.props.display == 'schedule'){ 281 var now = Date.now()/1000; 282 var schedule_from = this.props.schedule_from || (now - 1); 283 var schedule_to = this.props.schedule_to || (now + 1); 284 285 if(now > schedule_from && now < schedule_to){ 286 return true; 287 }else{ 288 return false; 289 } 290 } 291 292 if(this.force_closed){ 293 return false; 294 } 295 296 return true; 297 298} 299 300Announcer.prototype.check_show = function(){ 301 302 var self = this; 303 304 if(!this.can_show()){ 305 return; 306 } 307 308 if(this.props.show_on == 'page_open'){ 309 self.show(); 310 }else if(this.props.show_on == 'duration'){ 311 setTimeout(function(){ 312 self.show(); 313 }, this.props.show_after_duration * 1000) 314 } 315 316} 317 318Announcer.prototype.show = function(){ 319 var self = this; 320 this.is_shown = true; 321 322 this.animate('show', function(){ 323 self.after_show(); 324 }); 325 326} 327 328Announcer.prototype.after_show = function(){ 329 330 var position = this.props.position; 331 ancr_state.update_offsets(position); 332 ancr_state.adjust_fixed_elements(); 333 334 if(this.props.auto_close != '0'){ 335 this.auto_close(); 336 } 337 338} 339 340Announcer.prototype.hide = function(set_cookie=true){ 341 var self = this; 342 this.is_shown = false; 343 344 this.animate('hide', function(){ 345 self.after_hide(set_cookie); 346 }); 347} 348 349Announcer.prototype.after_hide = function(set_cookie=true){ 350 351 var position = this.props.position; 352 ancr_state.update_offsets(position); 353 ancr_state.adjust_fixed_elements(); 354 355 var closed_duration = (this.props.closed_duration == '0') ? false : this.props.closed_duration; 356 357 if(this.props.keep_closed == 'yes' && set_cookie){ 358 ancr_state.set_cookie(this.close_cookie, 1, closed_duration, true); 359 } 360 361} 362 363Announcer.prototype.set_offset = function(){ 364 var position = this.props.position; 365 var css_props = {}; 366 var offset = ancr_state[position].offset_total; 367 368 css_props[position] = offset + 'px'; 369 //this.$el.animate(css_props); 370 371} 372 373Announcer.prototype.auto_close = function(){ 374 var self = this; 375 setTimeout(function(){ 376 self.hide(); 377 }, this.props.auto_close * 1000); 378} 379 380Announcer.prototype.animate = function(type, callback){ 381 382 var animations = { 383 'slide' : ['slideDown', 'slideUp'], 384 'fade' : ['fadeIn', 'fadeOut'] 385 }; 386 387 var chosen = (type == 'show') ? this.props.open_animation : this.props.close_animation; 388 var duration = 400; 389 var animation = 'show'; 390 391 if(chosen == 'none'){ 392 animation = (type == 'show') ? 'show' : 'hide'; 393 duration = 0; 394 }else{ 395 animation = (type == 'show') ? animations[chosen][0] : animations[chosen][1]; 396 } 397 398 this.$el[animation](duration, callback); 399 400}
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.