- commit
- 2aa65b15307c7307c9dab435e7a9d67e321dcec1
- parent
- 4ed3736145a77ea0a1a397cd65c8bcf03aa15726
- Author
- leaf corcoran <leafot@gmail.com>
- Date
- 2013-11-27 07:42
mark elements that are sticky aware with "sticky_kit" data attribute, fixes #19
Diffstat
| M | jquery.sticky-kit.coffee | 4 | ++++ |
| M | jquery.sticky-kit.js | 8 | +++++++- |
| M | jquery.sticky-kit.min.js | 10 | +++++----- |
3 files changed, 16 insertions, 6 deletions
diff --git a/jquery.sticky-kit.coffee b/jquery.sticky-kit.coffee
@@ -14,6 +14,9 @@ $.fn.stick_in_parent = (opts={}) ->
14 14
15 15 for elm in @
16 16 ((elm, padding_bottom, parent_top, parent_height, top, height, float) ->
-1 17 return if elm.data "sticky_kit"
-1 18 elm.data "sticky_kit", true
-1 19
17 20 parent = elm.parent()
18 21 parent = parent.closest(parent_selector) if parent_selector?
19 22 throw "failed to find stick parent" unless parent.length
@@ -157,6 +160,7 @@ $.fn.stick_in_parent = (opts={}) ->
157 160 win.off "scroll", tick
158 161 $(document.body).off "sticky_kit:recalc", recalc_and_tick
159 162 elm.off "sticky_kit:detach", detach
-1 163 elm.removeData "sticky_kit"
160 164
161 165 elm.css {
162 166 position: ""
diff --git a/jquery.sticky-kit.js b/jquery.sticky-kit.js
@@ -1,4 +1,5 @@1 -1 // Generated by CoffeeScript 1.6.3-1 1 // Generated by CoffeeScript 1.4.0 -1 2 2 3 /** 3 4 @license Sticky-kit v1.0.2 | WTFPL | Leaf Corcoran 2013 | http://leafo.net 4 5 */ @@ -31,6 +32,10 @@ 31 32 } 32 33 _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, float) { 33 34 var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, spacer, tick; -1 35 if (elm.data("sticky_kit")) { -1 36 return; -1 37 } -1 38 elm.data("sticky_kit", true); 34 39 parent = elm.parent(); 35 40 if (parent_selector != null) { 36 41 parent = parent.closest(parent_selector); @@ -162,6 +167,7 @@ 162 167 win.off("scroll", tick); 163 168 $(document.body).off("sticky_kit:recalc", recalc_and_tick); 164 169 elm.off("sticky_kit:detach", detach); -1 170 elm.removeData("sticky_kit"); 165 171 elm.css({ 166 172 position: "", 167 173 bottom: "",
diff --git a/jquery.sticky-kit.min.js b/jquery.sticky-kit.min.js
@@ -1,8 +1,8 @@ 1 1 /* 2 2 Sticky-kit v1.0.2 | WTFPL | Leaf Corcoran 2013 | http://leafo.net 3 3 */4 -1 (function(){var b,q;b=this.jQuery;q=b(window);b.fn.stick_in_parent=function(e){var u,m,f,r,B,l,C;null==e&&(e={});r=e.sticky_class;u=e.inner_scrolling;f=e.parent;m=e.offset_top;null==m&&(m=0);null==f&&(f=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,e,l,v,w,n,s){var t,z,h,x,c,d,A,y,g,k;d=a.parent();null!=f&&(d=d.closest(f));if(!d.length)throw"failed to find stick parent";h=!1;g=b("<div />");A=function(){var c,b;c=parseInt(d.css("border-top-width"),10);b=parseInt(d.css("padding-top"),5 -1 10);e=parseInt(d.css("padding-bottom"),10);l=d.offset().top+c+b;v=d.height();c=h?(h=!1,a.insertAfter(g).css({position:"",top:"",width:""}),g.detach(),!0):void 0;w=a.offset().top-parseInt(a.css("margin-top"),10)-m;console.log("setting top",w);n=a.outerHeight(!0);s=a.css("float");g.css({width:a.outerWidth(!0),height:n,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:s});if(c)return k()};A();if(n!==v)return t=!1,x=void 0,c=m,k=function(){var b,k,p,f;p=q.scrollTop();null!=x&&(k=6 -1 p-x);x=p;h?(f=p+n+c>v+l,t&&!f&&(t=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom")),p<w&&(h=!1,c=m,"left"!==s&&"right"!==s||a.insertAfter(g),g.detach(),b={position:"",width:"",top:""},a.css(b).removeClass(r).trigger("sticky_kit:unstick")),u&&(b=q.height(),n>b&&!t&&(c-=k,c=Math.max(b-n,c),c=Math.min(m,c),h&&a.css({top:c+"px"})))):p>w&&(h=!0,b={position:"fixed",top:c},b.width=a.width()+"px",a.css(b).addClass(r).after(g),"left"!==s&&"right"!==s||g.append(a),a.trigger("sticky_kit:stick"));7 -1 if(h&&(null==f&&(f=p+n+c>v+l),!t&&f))return t=!0,"static"===d.css("position")&&d.css({position:"relative"}),a.css({position:"absolute",bottom:e,top:""}).trigger("sticky_kit:bottom")},y=function(){A();return k()},z=function(){q.off("scroll",k);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",z);a.css({position:"",bottom:"",top:""});d.position("position","");if(h)return a.insertAfter(g).removeClass(r),g.remove()},q.on("scroll",k),q.on("resize",y),b(document.body).on("sticky_kit:recalc",8 -1 y),a.on("sticky_kit:detach",z),setTimeout(k,0)};l=0;for(C=this.length;l<C;l++)e=this[l],B(b(e));return this}}).call(this);-1 4 (function(){var b,q;b=this.jQuery;q=b(window);b.fn.stick_in_parent=function(e){var u,m,f,r,B,l,C;null==e&&(e={});r=e.sticky_class;u=e.inner_scrolling;f=e.parent;m=e.offset_top;null==m&&(m=0);null==f&&(f=void 0);null==u&&(u=!0);null==r&&(r="is_stuck");B=function(a,e,l,v,w,n,s){var t,z,h,x,c,d,A,y,g,k;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);d=a.parent();null!=f&&(d=d.closest(f));if(!d.length)throw"failed to find stick parent";h=!1;g=b("<div />");A=function(){var c,b;c=parseInt(d.css("border-top-width"), -1 5 10);b=parseInt(d.css("padding-top"),10);e=parseInt(d.css("padding-bottom"),10);l=d.offset().top+c+b;v=d.height();c=h?(h=!1,a.insertAfter(g).css({position:"",top:"",width:""}),g.detach(),!0):void 0;w=a.offset().top-parseInt(a.css("margin-top"),10)-m;console.log("setting top",w);n=a.outerHeight(!0);s=a.css("float");g.css({width:a.outerWidth(!0),height:n,display:a.css("display"),"vertical-align":a.css("vertical-align"),float:s});if(c)return k()};A();if(n!==v)return t=!1,x=void 0,c=m,k=function(){var b, -1 6 k,p,f;p=q.scrollTop();null!=x&&(k=p-x);x=p;h?(f=p+n+c>v+l,t&&!f&&(t=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom")),p<w&&(h=!1,c=m,"left"!==s&&"right"!==s||a.insertAfter(g),g.detach(),b={position:"",width:"",top:""},a.css(b).removeClass(r).trigger("sticky_kit:unstick")),u&&(b=q.height(),n>b&&!t&&(c-=k,c=Math.max(b-n,c),c=Math.min(m,c),h&&a.css({top:c+"px"})))):p>w&&(h=!0,b={position:"fixed",top:c},b.width=a.width()+"px",a.css(b).addClass(r).after(g),"left"!==s&&"right"!== -1 7 s||g.append(a),a.trigger("sticky_kit:stick"));if(h&&(null==f&&(f=p+n+c>v+l),!t&&f))return t=!0,"static"===d.css("position")&&d.css({position:"relative"}),a.css({position:"absolute",bottom:e,top:""}).trigger("sticky_kit:bottom")},y=function(){A();return k()},z=function(){q.off("scroll",k);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",z);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:""});d.position("position","");if(h)return a.insertAfter(g).removeClass(r),g.remove()}, -1 8 q.on("scroll",k),q.on("resize",y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",z),setTimeout(k,0)}};l=0;for(C=this.length;l<C;l++)e=this[l],B(b(e));return this}}).call(this);