1(function($) { 2 3 function HeaderAnimation(el, options) { 4 this.el = el; 5 this.$el = $(el); 6 this.options = { 7 startTop: 1 8 }; 9 $.extend(this.options, options); 10 this.initialize(); 11 } 12 13 HeaderAnimation.prototype = { 14 initialize: function() { 15 var self = this; 16 this.$page = $('#page').length ? $('#page') : $('body'); 17 this.$wrapper = $('#site-header-wrapper'); 18 this.$topArea = $('#top-area'); 19 this.topAreaInSiteHeader = $('#site-header #top-area').length > 0; 20 this.$headerMain = $('.header-main', this.$el); 21 this.hasAdminBar = document.body.className.indexOf('admin-bar') != -1; 22 this.adminBarOffset = 0; 23 this.adminBarHeight = 0; 24 this.topOffset = 0; 25 this.oldScrollY = 0; 26 this.isResponsive = null; 27 this.isResponsiveOld = null; 28 29 this.hideWrapper = this.$wrapper.hasClass('site-header-wrapper-transparent'); 30 this.videoBackground = $('.page-title-block .gem-video-background').length && $('.page-title-block .gem-video-background').data('headerup'); 31 32 if(this.$el.hasClass('header-on-slideshow') && $('#main-content > *').first().is('.gem-slideshow, .block-slideshow')) { 33 this.$wrapper.css({position: 'absolute'}); 34 } 35 36 if(this.$el.hasClass('header-on-slideshow') && $('#main-content > *').first().is('.gem-slideshow, .block-slideshow')) { 37 this.$wrapper.addClass('header-on-slideshow'); 38 } else { 39 this.$el.removeClass('header-on-slideshow'); 40 } 41 42 if(this.videoBackground) { 43 this.$el.addClass('header-on-slideshow'); 44 this.$wrapper.addClass('header-on-slideshow'); 45 } 46 47 this.initHeader(); 48 49 $(document).ready(function() { 50 self.updateAdminBarInfo(); 51 self.updateStartTop(); 52 }); 53 54 $(window).scroll(function() { 55 self.scrollHandler(); 56 }); 57 58 if ($('#thegem-perspective').length) { 59 this.$page.scroll(function() { 60 self.scrollHandler(); 61 }); 62 } 63 64 $(window).resize(function() { 65 setTimeout(function() { 66 self.initHeader(); 67 self.scrollHandler(); 68 }, 0); 69 }); 70 }, 71 72 initHeader: function() { 73 this.isResponsiveOld = this.isResponsive; 74 this.isResponsive = window.isResponsiveMenuVisible(); 75 76 if (this.isResponsive) { 77 this.$el.addClass('shrink-mobile'); 78 } else { 79 this.$el.removeClass('shrink-mobile'); 80 } 81 82 this.updateAdminBarInfo(); 83 this.updateStartTop(); 84 if (this.isResponsive != this.isResponsiveOld) { 85 this.initializeStyles(); 86 } 87 }, 88 89 updateAdminBarInfo: function() { 90 if (this.hasAdminBar) { 91 this.adminBarHeight = $('#wpadminbar').outerHeight(); 92 this.adminBarOffset = this.hasAdminBar && $('#wpadminbar').css('position') == 'fixed' ? parseInt(this.adminBarHeight) : 0; 93 } 94 }, 95 96 updateStartTop: function() { 97 if (this.$topArea.length && this.$topArea.is(':visible') && !this.topAreaInSiteHeader) { 98 this.options.startTop = this.$topArea.outerHeight(); 99 } else { 100 this.options.startTop = 1; 101 } 102 103 if (this.hasAdminBar && this.adminBarOffset == 0) { 104 this.options.startTop += this.adminBarHeight; 105 } 106 }, 107 108 setMargin: function($img) { 109 var $small = $img.siblings('img.small'), 110 w = 0; 111 112 if (this.$headerMain.hasClass('logo-position-right')) { 113 w = $small.width(); 114 } else if (this.$headerMain.hasClass('logo-position-center') || this.$headerMain.hasClass('logo-position-menu_center')) { 115 w = $img.width(); 116 var smallWidth = $small.width(), 117 offset = (w - smallWidth) / 2; 118 119 w = smallWidth + offset; 120 $small.css('margin-right', offset + 'px'); 121 } 122 if (!w) { 123 w = $img.width(); 124 } 125 $small.css('margin-left', '-' + w + 'px'); 126 $img.parent().css('min-width', w + 'px'); 127 128 $small.show(); 129 }, 130 131 initializeStyles: function() { 132 var self = this; 133 134 if (this.$headerMain.hasClass('logo-position-menu_center')) { 135 var $img = $('#primary-navigation .menu-item-logo a .logo img.default', this.$el); 136 } else { 137 var $img = $('.site-title a .logo img:visible', this.$el); 138 } 139 140 if ($img.length && $img[0].complete) { 141 self.setMargin($img); 142 self.initializeHeight(); 143 } else { 144 $img.on('load error', function() { 145 self.setMargin($img); 146 self.initializeHeight(); 147 }); 148 } 149 }, 150 151 initializeHeight: function() { 152 if (this.hideWrapper) { 153 return false;
154 } 155 156 that = this; 157 158 setTimeout(function() { 159 var shrink = that.$el.hasClass('shrink'); 160 if (shrink) { 161 that.$el.removeClass('shrink').addClass('without-transition'); 162 } 163 var elHeight = that.$el.outerHeight(); 164 that.$wrapper.height(elHeight); 165 if (shrink) { 166 that.$el.addClass('shrink').removeClass('without-transition'); 167 } 168 }, 50); 169 }, 170 171 scrollHandler: function() { 172 var self = this, 173 scrollY = this.getScrollY(); 174 175 if (scrollY >= this.options.startTop) { 176 if (!this.$el.hasClass('shrink')) { 177 var shrinkClass = 'shrink fixed'; 178 if (window.gemSettings.fillTopArea) { 179 shrinkClass += ' fill'; 180 } 181 this.$el.addClass(shrinkClass) 182 } 183 var top = 0; 184 if (this.$page[0].scrollTop > 0) { 185 top += this.$page[0].scrollTop; 186 } else { 187 if (this.hasAdminBar) { 188 top += this.adminBarOffset; 189 } 190 } 191 192 this.$el.css({ 193 top: top != 0 ? top : '' 194 }); 195 } else { 196 if (this.$el.hasClass('shrink')) { 197 this.$el.removeClass('shrink fixed') 198 } 199 if (this.hasAdminBar) { 200 this.$el.css({ 201 top: '' 202 }); 203 } 204 } 205 206 if (this.isResponsive && !this.$wrapper.hasClass('sticky-header-on-mobile')) { 207 if (!$('.mobile-menu-slide-wrapper.opened').length && !$('#primary-menu.dl-menuopen').length && !$('.menu-overlay.active').length) { 208 if (scrollY - this.oldScrollY > 0 && scrollY > 300 && !this.$el.hasClass('hidden')) { 209 self.$el.addClass('hidden'); 210 } 211 212 if (scrollY - this.oldScrollY < 0 && this.$el.hasClass('hidden')) { 213 self.$el.removeClass('hidden'); 214 } 215 } else { 216 self.$el.removeClass('hidden'); 217 } 218 } 219 220 this.oldScrollY = scrollY; 221 }, 222 223 getScrollY: function() { 224 return window.pageYOffset || document.documentElement.scrollTop + this.$page[0].scrollTop; 225 }, 226 }; 227 228 $.fn.headerAnimation = function(options) { 229 options = options || {}; 230 return new HeaderAnimation(this.get(0), options); 231 }; 232})(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.