1(function($) { 2 3 var $headerHeight = $('#header-outer').outerHeight() + 34; 4 var $extraHeight = ($('#wpadminbar').length > 0) ? 28 : 0; //admin bar 5 var secondaryHeader = ($('#header-outer').attr('data-using-secondary') == '1') ? 33 : 0 ; 6 7 $(window).load(function(){ 8 $headerHeight = $('#header-outer').outerHeight() + 34; 9 $extraHeight = ($('#wpadminbar').length > 0) ? 28 : 0; //admin bar 10 }); 11 12 $.fn.extend({ 13 stickyMojo: function(options) { 14 15 var settings = $.extend({ 16 'footerID': '', 17 'contentID': '', 18 'orientation': $(this).css('float') 19 }, options); 20 21 var sticky = { 22 'el': $(this), 23 'stickyLeft': $(settings.contentID).outerWidth() + $(settings.contentID).offset.left, 24 'stickyTop2': $(this).offset().top, 25 'stickyHeight': $(this).outerHeight(true), 26 'contentHeight': $(settings.contentID).outerHeight(true), 27 'win': $(window), 28 'breakPoint': $(this).outerWidth(true) + $(settings.contentID).outerWidth(true), 29 'marg': parseInt($(this).css('margin-top'), 10) 30 }; 31 32 var errors = checkSettings(); 33 cacheElements(); 34 35 return this.each(function() { 36 buildSticky(); 37 }); 38 39 function buildSticky() { 40 if (!errors.length) { 41 sticky.el.css('left', sticky.stickyLeft); 42 43 sticky.win.bind({ 44 'scroll': stick, 45 'resize': function() { 46 sticky.el.css('left', sticky.stickyLeft); 47 sticky.contentHeight = $(settings.contentID).outerHeight(true); 48 sticky.stickyHeight = sticky.el.outerHeight(true); 49 50 stick(); 51 toLiveOrDie(); 52 } 53 }); 54 55 setTimeout(function(){ toLiveOrDie(); },600); 56 57 } else { 58 if (console && console.warn) { 59 console.warn(errors); 60 } else { 61 alert(errors); 62 } 63 } 64 } 65 66 //destroy sticky sidebar if the sidebar is shorter than the content area 67 function toLiveOrDie(){ 68 69 if(parseInt($('#sidebar').height()) + 50 >= parseInt($('#post-area').height())) { 70 sticky.win.unbind('scroll', stick); 71 sticky.el.removeClass('fixed-sidebar'); 72 sticky.el.css({ 73 'position':'relative', 74 'top' : 0, 75 'margin-left' : 0, 76 'bottom' : 0 77 }); 78 } 79 else { 80 sticky.win.unbind('scroll', stick); 81 sticky.win.bind('scroll', stick); 82 sticky.el.addClass('fixed-sidebar'); 83 } 84 85 if($('#sidebar').length > 0) { 86 87 if($(window).scrollTop() < 100) { 88 sticky.stickyTop2 = $('#sidebar').offset().top; 89 sticky.marg = parseInt($('#sidebar').css('margin-top'), 10); 90 } 91 } 92 } 93 94 // Caches the footer and content elements into jquery objects 95 function cacheElements() { 96 settings.footerID = $(settings.footerID); 97 settings.contentID = $(settings.contentID); 98 } 99 100 // Calcualtes the limits top and bottom limits for the sidebar 101 function calculateLimits() { 102 103 return { 104 limit: settings.footerID.offset().top - sticky.stickyHeight - $headerHeight - $extraHeight - secondaryHeader, 105 windowTop: sticky.win.scrollTop(), 106 stickyTop: sticky.stickyTop2 - sticky.marg - $headerHeight - $extraHeight - secondaryHeader 107 } 108 } 109 110 // Sets sidebar to fixed position 111 function setFixedSidebar() { 112 sticky.el.css({ 113 position: 'fixed', 114 right: 'auto', 115 top: $headerHeight + $extraHeight + secondaryHeader, 116 bottom : 'auto' 117 }); 118 } 119 120 // Determines the sidebar orientation and sets margins accordingly 121 function checkOrientation() { 122 if (settings.orientation === "left") { 123 settings.contentID.css('margin-left', sticky.el.outerWidth(true)); 124 } else { 125 sticky.el.css('margin-left', settings.contentID.outerWidth(true)); 126 } 127 } 128 129 // sets sidebar to a static positioned element 130 function setStaticSidebar() { 131 sticky.el.css({ 132 'position': 'static', 133 'margin-left': '0px', 134 'bottom' : 'auto' 135 }); 136 settings.contentID.css('margin-left', '0px'); 137 } 138 139 // initiated to stop the sidebar from intersecting the footer 140 function setLimitedSidebar(diff) { 141 142 sticky.el.css({ 143 position: 'absolute', 144 top: 'auto', 145 right: '0', 146 bottom : -38 147 }); 148 } 149 150 //determines whether sidebar should stick and applies appropriate settings to make it stick 151 function stick() { 152 var tops = calculateLimits(); 153 var hitBreakPoint = tops.stickyTop < tops.windowTop && (sticky.win.width() >= sticky.breakPoint); 154 $headerHeight = $('#header-outer').outerHeight() + 34; 155 156 if (hitBreakPoint) { 157 setFixedSidebar(); 158 checkOrientation(); 159 } else { 160 setStaticSidebar(); 161 } 162 if (tops.limit < tops.windowTop) { 163 var diff = tops.limit - tops.windowTop; 164 setLimitedSidebar(diff); 165 } 166 167 } 168 169 // verifies that all settings are correct 170 function checkSettings() { 171 var errors = []; 172 for (var key in settings) { 173 if (!settings[key]) { 174 errors.push(settings[key]); 175 } 176 } 177 ieVersion() && errors.push("NO IE 7"); 178 return errors; 179 } 180 181 function ieVersion() { 182 if(document.querySelector) { 183 return false;
184 } 185 else { 186 return true; 187 } 188 } 189 } 190 }); 191})(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.