1(function() { 2 var $, win; 3 4 $ = this.jQuery || window.jQuery; 5 6 $win=$(window); 7 8 $.fn.omStickSidebar = function(opts) { 9 10 if (opts == null) { 11 opts = {}; 12 } 13 14 if(opts.disableOnTouch == null || opts.disableOnTouch == true) { 15 if(!!('ontouchstart' in window)) { 16 return this; 17 } 18 } 19 20 var topGapEl, topGap, topGapH, minWidth; 21 22 topGapEl=(opts.topGapEl == null ? false : $(opts.topGapEl)); 23 topGap=(opts.topGap == null ? 0 : $(opts.topGap)) 24 topGapH=topGap; 25 26 minWidth=(opts.minWidth == null ? false : opts.minWidth); 27 28 var fn=function($el) { 29 var $container=(opts.container == null ? $el.parent() : $(opts.container)); 30 31 var containerH, elH, stuckMode=false, lastScroll, containerOffset, windowH, elW, elOffset, windowW, scrollTimer, scrolling; 32 33 var refreshHeight=function(){ 34 var pos=$el.css('position'); 35 if(pos == 'static' || pos == 'relative') { 36 elW=$el.width(); 37 } else { 38 var $tmp=$el.clone(); 39 $tmp.css({ 40 visibility: 'hidden', 41 position: 'absolute', 42 top: 0, 43 left: 0, 44 right: 0, 45 width: 'auto', 46 }).insertBefore($el); 47 elW=$tmp.width(); 48 $tmp.remove(); 49 $el.css('width',elW+'px'); 50 } 51 52 containerH=$container.height(); 53 elH=$el.outerHeight(); 54 var offset=$container.offset(); 55 containerOffset=offset.top; 56 windowH=$win.height(); 57 windowW=$win.width(); 58 if(topGapEl) { 59 topGapH=topGap+topGapEl.height(); 60 } 61 } 62 refreshHeight(); 63 $('window, img').load(refreshHeight); 64 $win.resize(refreshHeight); 65 66 var lightRefreshHeight=function(){ 67 containerH=$container.height(); 68 elH=$el.outerHeight(); 69 } 70 71 if(minWidth) { 72 $win.resize(function(){ 73 if(windowW < minWidth && stuckMode != false ) { 74 $el.css({ 75 position: 'relative', 76 top: 'auto', 77 bottom: 'auto', 78 width: 'auto' 79 }); 80 stuckMode=false; 81 } 82 }); 83 } 84 85 $win.scroll(function(){ 86 if(minWidth && windowW < minWidth ) { 87 return; 88 } 89 90 if(!scrolling) { 91 lightRefreshHeight(); 92 } 93 94 scrolling=true; 95 clearTimeout(scrollTimer); 96 scrollTimer=setTimeout(function(){ 97 scrolling=false; 98 },1000); 99 100 101 if(elH == containerH) { 102 return; 103 } 104 105 var direction; 106 scroll=$win.scrollTop(); 107 if(lastScroll == null || lastScroll <= scroll) { 108 direction='down'; 109 } else { 110 direction='up'; 111 } 112 113 if(elH > windowH) { 114 if(direction == 'down' && ((stuckMode == false && scroll + windowH > containerOffset + elH && scroll + windowH < containerOffset + containerH) || stuckMode == 'absolute' && scroll + windowH > containerOffset + elH + elOffset )) { 115 var bottom=0; 116 $el.css({ 117 position: 'fixed', 118 top: 'auto', 119 bottom: bottom+'px', 120 width: elW+'px' 121 }); 122 stuckMode='bottom'; 123 } else if(direction == 'down' && stuckMode == 'bottom' && scroll + windowH > containerOffset + containerH) { 124 var top=containerH - elH; 125 elOffset=top; 126 $el.css({ 127 position: 'absolute', 128 top: top+'px', 129 bottom: 'auto', 130 width: elW+'px' 131 }); 132 stuckMode='absolute-bottom'; 133 } else if((direction == 'up' && stuckMode == 'bottom') || (direction == 'down' && stuckMode == 'top')) { 134 var offset=$el.offset(); 135 var top=offset.top - containerOffset + (lastScroll - scroll); 136 elOffset=top; 137 $el.css({ 138 position: 'absolute', 139 top: top+'px', 140 bottom: 'auto', 141 width: elW+'px' 142 }); 143 stuckMode='absolute'; 144 } else if(direction == 'up' && (stuckMode == 'absolute' || stuckMode == 'absolute-bottom') && scroll < containerOffset + elOffset - topGapH) { 145 var top=topGapH; 146 $el.css({ 147 position: 'fixed', 148 top: top+'px', 149 bottom: 'auto', 150 width: elW+'px' 151 }); 152 stuckMode='top'; 153 } else if(direction == 'up' && stuckMode == 'top' && scroll < containerOffset - topGapH) { 154 $el.css({ 155 position: 'relative', 156 top: 'auto', 157 bottom: 'auto', 158 width: 'auto' 159 }); 160 stuckMode=false; 161 } 162 } else { 163 if((direction == 'down' && stuckMode == false && scroll > containerOffset - topGapH) || (direction == 'up' && stuckMode == 'absolute-bottom' && scroll < containerOffset + elOffset - topGapH)) { 164 var top=topGapH; 165 $el.css({ 166 position: 'fixed', 167 top: top+'px', 168 bottom: 'auto', 169 width: elW+'px' 170 }); 171 stuckMode='top'; 172 }
172 else if(direction == 'up' && stuckMode == 'top' && scroll < containerOffset - topGapH) { 173 $el.css({ 174 position: 'relative', 175 top: 'auto', 176 bottom: 'auto', 177 width: 'auto' 178 }); 179 stuckMode=false; 180 } else if(direction == 'down' && stuckMode == 'top' && scroll + elH + topGapH > containerOffset + containerH) { 181 var top=containerH - elH; 182 elOffset=top; 183 $el.css({ 184 position: 'absolute', 185 top: top+'px', 186 bottom: 'auto', 187 width: elW+'px' 188 }); 189 stuckMode='absolute-bottom'; 190 } 191 } 192 193 lastScroll=scroll; 194 }); 195 196 } 197 198 for (i = 0, len = this.length; i < len; i++) { 199 elm = this[i]; 200 fn($(elm)); 201 } 202 return this; 203 }; 204 205}).call(this);
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.