1'use strict'; 2 3 4 5(function () { 6 var $, win; 7 8 $ = jQuery; 9 10 win = $(window); 11 12 $.fn.stick_in_parent = function (opts) { 13 var doc, elm, enable_bottoming, fn, i, inner_scrolling, len, manual_spacer, offset_top, parent_selector, recalc_every, sticky_class; 14 if (opts == null) { 15 opts = {}; 16 } 17 sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, recalc_every = opts.recalc_every, parent_selector = opts.parent, offset_top = opts.offset_top, manual_spacer = opts.spacer, enable_bottoming = opts.bottoming; 18 if (offset_top == null) { 19 offset_top = 0; 20 } 21 if (parent_selector == null) { 22 parent_selector = void 0; 23 } 24 if (inner_scrolling == null) { 25 inner_scrolling = true; 26 } 27 if (sticky_class == null) { 28 sticky_class = "is_stuck"; 29 } 30 doc = $(document); 31 if (enable_bottoming == null) { 32 enable_bottoming = true; 33 } 34 fn = function fn(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { 35 var bottomed, _detach, fixed, last_pos, last_scroll_height, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; 36 if (elm.data("sticky_kit")) { 37 return; 38 } 39 elm.data("sticky_kit", true); 40 last_scroll_height = doc.height(); 41 parent = elm.parent(); 42 if (parent_selector != null) { 43 parent = parent.closest(parent_selector); 44 } 45 if (!parent.length) { 46 throw "failed to find stick parent"; 47 } 48 fixed = false; 49 bottomed = false; 50 spacer = manual_spacer != null ? manual_spacer && elm.closest(manual_spacer) : $("<div />"); 51 if (spacer) { 52 spacer.css('position', elm.css('position')); 53 } 54 recalc = function recalc() { 55 var border_top, padding_top, restore; 56 if (detached) { 57 return; 58 } 59 last_scroll_height = doc.height(); 60 border_top = parseInt(parent.css("border-top-width"), 10); 61 padding_top = parseInt(parent.css("padding-top"), 10); 62 padding_bottom = parseInt(parent.css("padding-bottom"), 10); 63 parent_top = parent.offset().top + border_top + padding_top; 64 parent_height = parent.height(); 65 if (fixed) { 66 fixed = false; 67 bottomed = false; 68 if (manual_spacer == null) { 69 elm.insertAfter(spacer); 70 spacer.detach(); 71 } 72 elm.css({ 73 position: "", 74 top: "", 75 width: "", 76 bottom: "" 77 }).removeClass(sticky_class); 78 restore = true; 79 } 80 top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top; 81 height = elm.outerHeight(true); 82 el_float = elm.css("float"); 83 if (spacer) { 84 spacer.css({ 85 width: elm.outerWidth(true), 86 height: height, 87 display: elm.css("display"), 88 "vertical-align": elm.css("vertical-align"), 89 "float": el_float 90 }); 91 } 92 if (restore) { 93 return tick(); 94 } 95 }; 96 recalc(); 97 if (height === parent_height) { 98 return; 99 } 100 last_pos = void 0; 101 offset = offset_top; 102 recalc_counter = recalc_every; 103 tick = function tick() { 104 var css, delta, recalced, scroll, will_bottom, win_height; 105 if (detached) { 106 return; 107 } 108 recalced = false;
vendor: 5,828 bytes, lines 109-248
109 if (recalc_counter != null) { 110 recalc_counter -= 1; 111 if (recalc_counter <= 0) { 112 recalc_counter = recalc_every; 113 recalc(); 114 recalced = true; 115 } 116 } 117 if (!recalced && doc.height() !== last_scroll_height) { 118 recalc(); 119 recalced = true; 120 } 121 scroll = win.scrollTop(); 122 if (last_pos != null) { 123 delta = scroll - last_pos; 124 } 125 last_pos = scroll; 126 if (fixed) { 127 if (enable_bottoming) { 128 will_bottom = scroll + height + offset > parent_height + parent_top; 129 if (bottomed && !will_bottom) { 130 bottomed = false; 131 elm.css({ 132 position: "fixed", 133 bottom: "", 134 top: offset 135 }).trigger("sticky_kit:unbottom"); 136 } 137 } 138 if (scroll < top) { 139 fixed = false; 140 offset = offset_top; 141 if (manual_spacer == null) { 142 if (el_float === "left" || el_float === "right") { 143 elm.insertAfter(spacer); 144 } 145 spacer.detach(); 146 } 147 css = { 148 position: "", 149 width: "", 150 top: "" 151 }; 152 elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick"); 153 } 154 if (inner_scrolling) { 155 win_height = win.height(); 156 if (height + offset_top > win_height) { 157 if (!bottomed) { 158 offset -= delta; 159 offset = Math.max(win_height - height, offset); 160 offset = Math.min(offset_top, offset); 161 if (fixed) { 162 elm.css({ 163 top: offset + "px" 164 }); 165 } 166 } 167 } 168 } 169 } else { 170 if (scroll > top) { 171 fixed = true; 172 css = { 173 position: "fixed", 174 top: offset 175 }; 176 css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px"; 177 elm.css(css).addClass(sticky_class); 178 if (manual_spacer == null) { 179 elm.after(spacer); 180 if (el_float === "left" || el_float === "right") { 181 spacer.append(elm); 182 } 183 } 184 elm.trigger("sticky_kit:stick"); 185 } 186 } 187 if (fixed && enable_bottoming) { 188 if (will_bottom == null) { 189 will_bottom = scroll + height + offset > parent_height + parent_top; 190 } 191 if (!bottomed && will_bottom) { 192 bottomed = true; 193 if (parent.css("position") === "static") { 194 parent.css({ 195 position: "relative" 196 }); 197 } 198 return elm.css({ 199 position: "absolute", 200 bottom: padding_bottom, 201 top: "auto" 202 }).trigger("sticky_kit:bottom"); 203 } 204 } 205 }; 206 recalc_and_tick = function recalc_and_tick() { 207 recalc(); 208 return tick(); 209 }; 210 _detach = function detach() { 211 detached = true; 212 win.off("touchmove", tick); 213 win.off("scroll", tick); 214 win.off("resize", recalc_and_tick); 215 $(document.body).off("sticky_kit:recalc", recalc_and_tick); 216 elm.off("sticky_kit:detach", _detach); 217 elm.removeData("sticky_kit"); 218 elm.css({ 219 position: "", 220 bottom: "", 221 top: "", 222 width: "" 223 }); 224 parent.position("position", ""); 225 if (fixed) { 226 if (manual_spacer == null) { 227 if (el_float === "left" || el_float === "right") { 228 elm.insertAfter(spacer); 229 } 230 spacer.remove(); 231 } 232 return elm.removeClass(sticky_class); 233 } 234 }; 235 win.on("touchmove", tick); 236 win.on("scroll", tick); 237 win.on("resize", recalc_and_tick); 238 $(document.body).on("sticky_kit:recalc", recalc_and_tick); 239 elm.on("sticky_kit:detach", _detach); 240 return setTimeout(tick, 0); 241 }; 242 for (i = 0, len = this.length; i < len; i++) { 243 elm = this[i]; 244 fn($(elm)); 245 } 246 return this; 247 }; 248}).call(undefined);
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.