From 8c4f889c5a9ca7c6fddb8d0c8da0dc071669290c Mon Sep 17 00:00:00 2001 From: Penpo LI Date: Thu, 8 Sep 2016 00:48:45 +0800 Subject: [PATCH] Surport for AMD or modules mode The old code is not compatible when it be called by AMD library, such like RequireJS or SeaJS. So I added that feature. --- .gitignore | 1 + dist/sticky-kit.js | 463 +++++++++++++++++++++++---------------------- sticky-kit.coffee | 447 ++++++++++++++++++++++--------------------- 3 files changed, 467 insertions(+), 444 deletions(-) diff --git a/.gitignore b/.gitignore index a9ffd08..777f721 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .tup +.idea/* diff --git a/dist/sticky-kit.js b/dist/sticky-kit.js index 9597bd0..7ff8eb7 100644 --- a/dist/sticky-kit.js +++ b/dist/sticky-kit.js @@ -1,270 +1,279 @@ -// Generated by CoffeeScript 1.6.2 +// Generated by CoffeeScript 1.10.0 + /** @license Sticky-kit v1.1.3 | MIT | Leaf Corcoran 2015 | http://leafo.net -*/ - + */ (function() { - var $, win; - - $ = this.jQuery || window.jQuery; + (function(factory) { + 'use strict'; + if (typeof define === 'function' && define.amd) { - win = $(window); + /* AMD */ + return define(['jquery'], factory); + } else if (typeof module !== 'undefined' && module.exports) { - $.fn.stick_in_parent = function(opts) { - var doc, elm, enable_bottoming, inner_scrolling, manual_spacer, offset_top, outer_width, parent_selector, recalc_every, sticky_class, _fn, _i, _len; + /* CommonJS */ + return module.exports = factory(require('jquery')); + } else { - if (opts == null) { - opts = {}; - } - 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; - if (offset_top == null) { - offset_top = 0; - } - if (parent_selector == null) { - parent_selector = void 0; - } - if (inner_scrolling == null) { - inner_scrolling = true; + /* Global */ + return factory(jQuery || Zepto); } - if (sticky_class == null) { - sticky_class = "is_stuck"; - } - doc = $(document); - if (enable_bottoming == null) { - enable_bottoming = true; - } - outer_width = function(el) { - var computed, w, _el; - - if (window.getComputedStyle) { - _el = el[0]; - computed = window.getComputedStyle(el[0]); - w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right")); - if (computed.getPropertyValue("box-sizing") !== "border-box") { - w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right")); - } - return w; - } else { - return el.outerWidth(true); + })(function($) { + 'use strict'; + var win; + win = $(window); + return $.fn.stick_in_parent = function(opts) { + var doc, elm, enable_bottoming, fn, i, inner_scrolling, len, manual_spacer, offset_top, outer_width, parent_selector, recalc_every, sticky_class; + if (opts == null) { + opts = {}; } - }; - _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { - var bottomed, detach, fixed, last_pos, last_scroll_height, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; - - if (elm.data("sticky_kit")) { - return; + 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; + if (offset_top == null) { + offset_top = 0; } - elm.data("sticky_kit", true); - last_scroll_height = doc.height(); - parent = elm.parent(); - if (parent_selector != null) { - parent = parent.closest(parent_selector); + if (parent_selector == null) { + parent_selector = void 0; } - if (!parent.length) { - throw "failed to find stick parent"; + if (inner_scrolling == null) { + inner_scrolling = true; } - fixed = false; - bottomed = false; - spacer = manual_spacer != null ? manual_spacer && elm.closest(manual_spacer) : $("
"); - if (spacer) { - spacer.css('position', elm.css('position')); + if (sticky_class == null) { + sticky_class = "is_stuck"; } - recalc = function() { - var border_top, padding_top, restore; - - if (detached) { - return; - } - last_scroll_height = doc.height(); - border_top = parseInt(parent.css("border-top-width"), 10); - padding_top = parseInt(parent.css("padding-top"), 10); - padding_bottom = parseInt(parent.css("padding-bottom"), 10); - parent_top = parent.offset().top + border_top + padding_top; - parent_height = parent.height(); - if (fixed) { - fixed = false; - bottomed = false; - if (manual_spacer == null) { - elm.insertAfter(spacer); - spacer.detach(); + doc = $(document); + if (enable_bottoming == null) { + enable_bottoming = true; + } + outer_width = function(el) { + var _el, computed, w; + if (window.getComputedStyle) { + _el = el[0]; + computed = window.getComputedStyle(el[0]); + w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right")); + if (computed.getPropertyValue("box-sizing") !== "border-box") { + w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right")); } - elm.css({ - position: "", - top: "", - width: "", - bottom: "" - }).removeClass(sticky_class); - restore = true; - } - top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top; - height = elm.outerHeight(true); - el_float = elm.css("float"); - if (spacer) { - spacer.css({ - width: outer_width(elm), - height: height, - display: elm.css("display"), - "vertical-align": elm.css("vertical-align"), - "float": el_float - }); - } - if (restore) { - return tick(); + return w; + } else { + return el.outerWidth(true); } }; - recalc(); - if (height === parent_height) { - return; - } - last_pos = void 0; - offset = offset_top; - recalc_counter = recalc_every; - tick = function() { - var css, delta, recalced, scroll, will_bottom, win_height; - - if (detached) { + fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) { + var bottomed, detach, fixed, last_pos, last_scroll_height, offset, parent, recalc, recalc_and_tick, recalc_counter, spacer, tick; + if (elm.data("sticky_kit")) { return; } - recalced = false; - if (recalc_counter != null) { - recalc_counter -= 1; - if (recalc_counter <= 0) { - recalc_counter = recalc_every; - recalc(); - recalced = true; - } + elm.data("sticky_kit", true); + last_scroll_height = doc.height(); + parent = elm.parent(); + if (parent_selector != null) { + parent = parent.closest(parent_selector); } - if (!recalced && doc.height() !== last_scroll_height) { - recalc(); - recalced = true; + if (!parent.length) { + throw "failed to find stick parent"; } - scroll = win.scrollTop(); - if (last_pos != null) { - delta = scroll - last_pos; + fixed = false; + bottomed = false; + spacer = manual_spacer != null ? manual_spacer && elm.closest(manual_spacer) : $("
"); + if (spacer) { + spacer.css('position', elm.css('position')); } - last_pos = scroll; - if (fixed) { - if (enable_bottoming) { - will_bottom = scroll + height + offset > parent_height + parent_top; - if (bottomed && !will_bottom) { - bottomed = false; - elm.css({ - position: "fixed", - bottom: "", - top: offset - }).trigger("sticky_kit:unbottom"); - } + recalc = function() { + var border_top, padding_top, restore; + if (detached) { + return; } - if (scroll < top) { + last_scroll_height = doc.height(); + border_top = parseInt(parent.css("border-top-width"), 10); + padding_top = parseInt(parent.css("padding-top"), 10); + padding_bottom = parseInt(parent.css("padding-bottom"), 10); + parent_top = parent.offset().top + border_top + padding_top; + parent_height = parent.height(); + if (fixed) { fixed = false; - offset = offset_top; + bottomed = false; if (manual_spacer == null) { - if (el_float === "left" || el_float === "right") { - elm.insertAfter(spacer); - } + elm.insertAfter(spacer); spacer.detach(); } - css = { + elm.css({ position: "", + top: "", width: "", - top: "" - }; - elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick"); + bottom: "" + }).removeClass(sticky_class); + restore = true; + } + top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) || 0) - offset_top; + height = elm.outerHeight(true); + el_float = elm.css("float"); + if (spacer) { + spacer.css({ + width: outer_width(elm), + height: height, + display: elm.css("display"), + "vertical-align": elm.css("vertical-align"), + "float": el_float + }); } - if (inner_scrolling) { - win_height = win.height(); - if (height + offset_top > win_height) { - if (!bottomed) { - offset -= delta; - offset = Math.max(win_height - height, offset); - offset = Math.min(offset_top, offset); - if (fixed) { - elm.css({ - top: offset + "px" - }); + if (restore) { + return tick(); + } + }; + recalc(); + if (height === parent_height) { + return; + } + last_pos = void 0; + offset = offset_top; + recalc_counter = recalc_every; + tick = function() { + var css, delta, recalced, scroll, will_bottom, win_height; + if (detached) { + return; + } + recalced = false; + if (recalc_counter != null) { + recalc_counter -= 1; + if (recalc_counter <= 0) { + recalc_counter = recalc_every; + recalc(); + recalced = true; + } + } + if (!recalced && doc.height() !== last_scroll_height) { + recalc(); + recalced = true; + } + scroll = win.scrollTop(); + if (last_pos != null) { + delta = scroll - last_pos; + } + last_pos = scroll; + if (fixed) { + if (enable_bottoming) { + will_bottom = scroll + height + offset > parent_height + parent_top; + if (bottomed && !will_bottom) { + bottomed = false; + elm.css({ + position: "fixed", + bottom: "", + top: offset + }).trigger("sticky_kit:unbottom"); + } + } + if (scroll < top) { + fixed = false; + offset = offset_top; + if (manual_spacer == null) { + if (el_float === "left" || el_float === "right") { + elm.insertAfter(spacer); } + spacer.detach(); } + css = { + position: "", + width: "", + top: "" + }; + elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick"); } - } - } else { - if (scroll > top) { - fixed = true; - css = { - position: "fixed", - top: offset - }; - css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px"; - elm.css(css).addClass(sticky_class); - if (manual_spacer == null) { - elm.after(spacer); - if (el_float === "left" || el_float === "right") { - spacer.append(elm); + if (inner_scrolling) { + win_height = win.height(); + if (height + offset_top > win_height) { + if (!bottomed) { + offset -= delta; + offset = Math.max(win_height - height, offset); + offset = Math.min(offset_top, offset); + if (fixed) { + elm.css({ + top: offset + "px" + }); + } + } } } - elm.trigger("sticky_kit:stick"); - } - } - if (fixed && enable_bottoming) { - if (will_bottom == null) { - will_bottom = scroll + height + offset > parent_height + parent_top; + } else { + if (scroll > top) { + fixed = true; + css = { + position: "fixed", + top: offset + }; + css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px"; + elm.css(css).addClass(sticky_class); + if (manual_spacer == null) { + elm.after(spacer); + if (el_float === "left" || el_float === "right") { + spacer.append(elm); + } + } + elm.trigger("sticky_kit:stick"); + } } - if (!bottomed && will_bottom) { - bottomed = true; - if (parent.css("position") === "static") { - parent.css({ - position: "relative" - }); + if (fixed && enable_bottoming) { + if (will_bottom == null) { + will_bottom = scroll + height + offset > parent_height + parent_top; + } + if (!bottomed && will_bottom) { + bottomed = true; + if (parent.css("position") === "static") { + parent.css({ + position: "relative" + }); + } + return elm.css({ + position: "absolute", + bottom: padding_bottom, + top: "auto" + }).trigger("sticky_kit:bottom"); } - return elm.css({ - position: "absolute", - bottom: padding_bottom, - top: "auto" - }).trigger("sticky_kit:bottom"); } - } - }; - recalc_and_tick = function() { - recalc(); - return tick(); - }; - detach = function() { - detached = true; - win.off("touchmove", tick); - win.off("scroll", tick); - win.off("resize", recalc_and_tick); - $(document.body).off("sticky_kit:recalc", recalc_and_tick); - elm.off("sticky_kit:detach", detach); - elm.removeData("sticky_kit"); - elm.css({ - position: "", - bottom: "", - top: "", - width: "" - }); - parent.position("position", ""); - if (fixed) { - if (manual_spacer == null) { - if (el_float === "left" || el_float === "right") { - elm.insertAfter(spacer); + }; + recalc_and_tick = function() { + recalc(); + return tick(); + }; + detach = function() { + detached = true; + win.off("touchmove", tick); + win.off("scroll", tick); + win.off("resize", recalc_and_tick); + $(document.body).off("sticky_kit:recalc", recalc_and_tick); + elm.off("sticky_kit:detach", detach); + elm.removeData("sticky_kit"); + elm.css({ + position: "", + bottom: "", + top: "", + width: "" + }); + parent.position("position", ""); + if (fixed) { + if (manual_spacer == null) { + if (el_float === "left" || el_float === "right") { + elm.insertAfter(spacer); + } + spacer.remove(); } - spacer.remove(); + return elm.removeClass(sticky_class); } - return elm.removeClass(sticky_class); - } + }; + win.on("touchmove", tick); + win.on("scroll", tick); + win.on("resize", recalc_and_tick); + $(document.body).on("sticky_kit:recalc", recalc_and_tick); + elm.on("sticky_kit:detach", detach); + return setTimeout(tick, 0); }; - win.on("touchmove", tick); - win.on("scroll", tick); - win.on("resize", recalc_and_tick); - $(document.body).on("sticky_kit:recalc", recalc_and_tick); - elm.on("sticky_kit:detach", detach); - return setTimeout(tick, 0); + for (i = 0, len = this.length; i < len; i++) { + elm = this[i]; + fn($(elm)); + } + return this; }; - for (_i = 0, _len = this.length; _i < _len; _i++) { - elm = this[_i]; - _fn($(elm)); - } - return this; - }; + }); }).call(this); diff --git a/sticky-kit.coffee b/sticky-kit.coffee index 73c3b13..f19561e 100644 --- a/sticky-kit.coffee +++ b/sticky-kit.coffee @@ -1,265 +1,278 @@ ###* @license Sticky-kit v1.1.3 | MIT | Leaf Corcoran 2015 | http://leafo.net ### - -$ = @jQuery or window.jQuery - -win = $ window -$.fn.stick_in_parent = (opts={}) -> - { - sticky_class - inner_scrolling - recalc_every - parent: parent_selector - offset_top - spacer: manual_spacer - bottoming: enable_bottoming - } = opts - - offset_top ?= 0 - parent_selector ?= undefined - inner_scrolling ?= true - sticky_class ?= "is_stuck" - - doc = $(document) - - enable_bottoming = true unless enable_bottoming? - - # we need this because jquery's version (along with css()) rounds everything - outer_width = (el) -> - if window.getComputedStyle - _el = el[0] - computed = window.getComputedStyle el[0] - - w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right")) - - if computed.getPropertyValue("box-sizing") != "border-box" - w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right")) - w - else - el.outerWidth true - - for elm in @ - ((elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) -> - return if elm.data "sticky_kit" - elm.data "sticky_kit", true - - last_scroll_height = doc.height() - - parent = elm.parent() - parent = parent.closest(parent_selector) if parent_selector? - throw "failed to find stick parent" unless parent.length - - fixed = false - bottomed = false - spacer = if manual_spacer? - manual_spacer && elm.closest manual_spacer +((factory) -> + 'use strict'; + if typeof define is 'function' and define.amd + ### AMD ### + define(['jquery'], factory); + else if typeof module isnt 'undefined' and module.exports + ### CommonJS ### + module.exports = factory(require('jquery')); + else + ### Global ### + factory(jQuery or Zepto); +) ($) -> + + 'use strict'; + + win = $ window + + $.fn.stick_in_parent = (opts={}) -> + { + sticky_class + inner_scrolling + recalc_every + parent: parent_selector + offset_top + spacer: manual_spacer + bottoming: enable_bottoming + } = opts + + offset_top ?= 0 + parent_selector ?= undefined + inner_scrolling ?= true + sticky_class ?= "is_stuck" + + doc = $(document) + + enable_bottoming = true unless enable_bottoming? + + # we need this because jquery's version (along with css()) rounds everything + outer_width = (el) -> + if window.getComputedStyle + _el = el[0] + computed = window.getComputedStyle el[0] + + w = parseFloat(computed.getPropertyValue("width")) + parseFloat(computed.getPropertyValue("margin-left")) + parseFloat(computed.getPropertyValue("margin-right")) + + if computed.getPropertyValue("box-sizing") != "border-box" + w += parseFloat(computed.getPropertyValue("border-left-width")) + parseFloat(computed.getPropertyValue("border-right-width")) + parseFloat(computed.getPropertyValue("padding-left")) + parseFloat(computed.getPropertyValue("padding-right")) + w else - $("
") + el.outerWidth true - spacer.css('position', elm.css('position')) if spacer + for elm in @ + ((elm, padding_bottom, parent_top, parent_height, top, height, el_float, detached) -> + return if elm.data "sticky_kit" + elm.data "sticky_kit", true - recalc = -> - return if detached last_scroll_height = doc.height() - border_top = parseInt parent.css("border-top-width"), 10 - padding_top = parseInt parent.css("padding-top"), 10 - padding_bottom = parseInt parent.css("padding-bottom"), 10 + parent = elm.parent() + parent = parent.closest(parent_selector) if parent_selector? + throw "failed to find stick parent" unless parent.length - parent_top = parent.offset().top + border_top + padding_top - parent_height = parent.height() + fixed = false + bottomed = false + spacer = if manual_spacer? + manual_spacer && elm.closest manual_spacer + else + $("
") - if fixed - fixed = false - bottomed = false + spacer.css('position', elm.css('position')) if spacer - unless manual_spacer? - elm.insertAfter(spacer) - spacer.detach() + recalc = -> + return if detached + last_scroll_height = doc.height() - elm.css({ - position: "" - top: "" - width: "" - bottom: "" - }).removeClass(sticky_class) + border_top = parseInt parent.css("border-top-width"), 10 + padding_top = parseInt parent.css("padding-top"), 10 + padding_bottom = parseInt parent.css("padding-bottom"), 10 - restore = true + parent_top = parent.offset().top + border_top + padding_top + parent_height = parent.height() - top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) or 0) - offset_top + if fixed + fixed = false + bottomed = false - height = elm.outerHeight true + unless manual_spacer? + elm.insertAfter(spacer) + spacer.detach() - el_float = elm.css "float" - spacer.css({ - width: outer_width elm - height: height - display: elm.css "display" - "vertical-align": elm.css "vertical-align" - "float": el_float - }) if spacer + elm.css({ + position: "" + top: "" + width: "" + bottom: "" + }).removeClass(sticky_class) - if restore - tick() + restore = true - recalc() - return if height == parent_height + top = elm.offset().top - (parseInt(elm.css("margin-top"), 10) or 0) - offset_top - last_pos = undefined - offset = offset_top + height = elm.outerHeight true - recalc_counter = recalc_every + el_float = elm.css "float" + spacer.css({ + width: outer_width elm + height: height + display: elm.css "display" + "vertical-align": elm.css "vertical-align" + "float": el_float + }) if spacer - tick = -> - return if detached - recalced = false + if restore + tick() - if recalc_counter? - recalc_counter -= 1 - if recalc_counter <= 0 - recalc_counter = recalc_every - recalc() - recalced = true + recalc() + return if height == parent_height - if !recalced && doc.height() != last_scroll_height - recalc() - recalced = true + last_pos = undefined + offset = offset_top - scroll = win.scrollTop() - if last_pos? - delta = scroll - last_pos - last_pos = scroll + recalc_counter = recalc_every - if fixed - if enable_bottoming - will_bottom = scroll + height + offset > parent_height + parent_top + tick = -> + return if detached + recalced = false - # unbottom - if bottomed && !will_bottom - bottomed = false - elm.css({ - position: "fixed" - bottom: "" - top: offset - }).trigger("sticky_kit:unbottom") + if recalc_counter? + recalc_counter -= 1 + if recalc_counter <= 0 + recalc_counter = recalc_every + recalc() + recalced = true - # unfixing - if scroll < top - fixed = false - offset = offset_top + if !recalced && doc.height() != last_scroll_height + recalc() + recalced = true - unless manual_spacer? - if el_float == "left" || el_float == "right" - elm.insertAfter spacer + scroll = win.scrollTop() + if last_pos? + delta = scroll - last_pos + last_pos = scroll + + if fixed + if enable_bottoming + will_bottom = scroll + height + offset > parent_height + parent_top + + # unbottom + if bottomed && !will_bottom + bottomed = false + elm.css({ + position: "fixed" + bottom: "" + top: offset + }).trigger("sticky_kit:unbottom") + + # unfixing + if scroll < top + fixed = false + offset = offset_top + + unless manual_spacer? + if el_float == "left" || el_float == "right" + elm.insertAfter spacer + + spacer.detach() + + css = { + position: "" + width: "" + top: "" + } + elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick") + + # updated offset + if inner_scrolling + win_height = win.height() + if height + offset_top > win_height # bigger than viewport + unless bottomed + offset -= delta + offset = Math.max win_height - height, offset + offset = Math.min offset_top, offset + + if fixed + elm.css { + top: offset + "px" + } + + else + # fixing + if scroll > top + fixed = true + css = { + position: "fixed" + top: offset + } - spacer.detach() + css.width = if elm.css("box-sizing") == "border-box" + elm.outerWidth() + "px" + else + elm.width() + "px" - css = { - position: "" - width: "" - top: "" - } - elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick") - - # updated offset - if inner_scrolling - win_height = win.height() - if height + offset_top > win_height # bigger than viewport - unless bottomed - offset -= delta - offset = Math.max win_height - height, offset - offset = Math.min offset_top, offset - - if fixed - elm.css { - top: offset + "px" - } + elm.css(css).addClass(sticky_class) - else - # fixing - if scroll > top - fixed = true - css = { - position: "fixed" - top: offset - } + unless manual_spacer? + elm.after(spacer) - css.width = if elm.css("box-sizing") == "border-box" - elm.outerWidth() + "px" - else - elm.width() + "px" + if el_float == "left" || el_float == "right" + spacer.append elm - elm.css(css).addClass(sticky_class) + elm.trigger("sticky_kit:stick") - unless manual_spacer? - elm.after(spacer) + # this is down here because we can fix and bottom in same step when + # scrolling huge + if fixed && enable_bottoming + will_bottom ?= scroll + height + offset > parent_height + parent_top - if el_float == "left" || el_float == "right" - spacer.append elm - - elm.trigger("sticky_kit:stick") - - # this is down here because we can fix and bottom in same step when - # scrolling huge - if fixed && enable_bottoming - will_bottom ?= scroll + height + offset > parent_height + parent_top - - # bottomed - if !bottomed && will_bottom - # bottomed out - bottomed = true - if parent.css("position") == "static" - parent.css { - position: "relative" - } + # bottomed + if !bottomed && will_bottom + # bottomed out + bottomed = true + if parent.css("position") == "static" + parent.css { + position: "relative" + } - elm.css({ - position: "absolute" - bottom: padding_bottom - top: "auto" - }).trigger("sticky_kit:bottom") + elm.css({ + position: "absolute" + bottom: padding_bottom + top: "auto" + }).trigger("sticky_kit:bottom") - recalc_and_tick = -> - recalc() - tick() + recalc_and_tick = -> + recalc() + tick() - detach = -> - detached = true - win.off "touchmove", tick - win.off "scroll", tick - win.off "resize", recalc_and_tick + detach = -> + detached = true + win.off "touchmove", tick + win.off "scroll", tick + win.off "resize", recalc_and_tick - $(document.body).off "sticky_kit:recalc", recalc_and_tick - elm.off "sticky_kit:detach", detach - elm.removeData "sticky_kit" + $(document.body).off "sticky_kit:recalc", recalc_and_tick + elm.off "sticky_kit:detach", detach + elm.removeData "sticky_kit" - elm.css { - position: "" - bottom: "" - top: "" - width: "" - } + elm.css { + position: "" + bottom: "" + top: "" + width: "" + } - parent.position "position", "" + parent.position "position", "" - if fixed - unless manual_spacer? - if el_float == "left" || el_float == "right" - elm.insertAfter spacer - spacer.remove() + if fixed + unless manual_spacer? + if el_float == "left" || el_float == "right" + elm.insertAfter spacer + spacer.remove() - elm.removeClass sticky_class + elm.removeClass sticky_class - win.on "touchmove", tick - win.on "scroll", tick - win.on "resize", recalc_and_tick - $(document.body).on "sticky_kit:recalc", recalc_and_tick - elm.on "sticky_kit:detach", detach + win.on "touchmove", tick + win.on "scroll", tick + win.on "resize", recalc_and_tick + $(document.body).on "sticky_kit:recalc", recalc_and_tick + elm.on "sticky_kit:detach", detach - setTimeout tick, 0 + setTimeout tick, 0 - ) $ elm - @ + ) $ elm + @