You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
10 KiB

9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
9 years ago
10 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 2.0.0 - Sticky
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2015 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. !function(e,t,o,n){"use strict";e.fn.sticky=function(o){var i,s=e(this),c=s.selector||"",r=(new Date).getTime(),a=[],l=arguments[0],f="string"==typeof l,m=[].slice.call(arguments,1);return s.each(function(){var s,u,d,h=e.isPlainObject(o)?e.extend(!0,{},e.fn.sticky.settings,o):e.extend({},e.fn.sticky.settings),g=h.className,b=h.namespace,p=h.error,v="."+b,x="module-"+b,C=e(this),S=e(t),y=C.offsetParent(),k=e(h.scrollContext),w=(C.selector||"",C.data(x)),T=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,0)},P=this;d={initialize:function(){d.determineContext(),d.verbose("Initializing sticky",h,y),d.save.positions(),d.checkErrors(),d.bind.events(),h.observeChanges&&d.observeChanges(),d.instantiate()},instantiate:function(){d.verbose("Storing instance of module",d),w=d,C.data(x,d)},destroy:function(){d.verbose("Destroying previous instance"),d.reset(),u&&u.disconnect(),S.off("load"+v,d.event.load).off("resize"+v,d.event.resize),k.off("scrollchange"+v,d.event.scrollchange),C.removeData(x)},observeChanges:function(){var e=s[0];"MutationObserver"in t&&(u=new MutationObserver(function(e){clearTimeout(d.timer),d.timer=setTimeout(function(){d.verbose("DOM tree modified, updating sticky menu",e),d.refresh()},100)}),u.observe(P,{childList:!0,subtree:!0}),u.observe(e,{childList:!0,subtree:!0}),d.debug("Setting up mutation observer",u))},determineContext:function(){return s=h.context?e(h.context):y,0===s.length?void d.error(p.invalidContext,h.context,C):void 0},checkErrors:function(){return d.is.hidden()&&d.error(p.visible,C),d.cache.element.height>d.cache.context.height?(d.reset(),void d.error(p.elementSize,C)):void 0},bind:{events:function(){S.on("load"+v,d.event.load).on("resize"+v,d.event.resize),k.off("scroll"+v).on("scroll"+v,d.event.scroll).on("scrollchange"+v,d.event.scrollchange)}},event:{load:function(){d.verbose("Page contents finished loading"),T(d.refresh)},resize:function(){d.verbose("Window resized"),T(d.refresh)},scroll:function(){T(function(){k.triggerHandler("scrollchange"+v,k.scrollTop())})},scrollchange:function(e,t){d.stick(t),h.onScroll.call(P)}},refresh:function(e){d.reset(),e&&(y=C.offsetParent()),d.save.positions(),d.stick(),h.onReposition.call(P)},supports:{sticky:function(){{var t=e("<div/>");t[0]}return t.addClass(g.supported),t.css("position").match("sticky")}},save:{lastScroll:function(e){d.lastScroll=e},elementScroll:function(e){d.elementScroll=e},positions:function(){var e={height:S.height()},t={margin:{top:parseInt(C.css("margin-top"),10),bottom:parseInt(C.css("margin-bottom"),10)},offset:C.offset(),width:C.outerWidth(),height:C.outerHeight()},o={offset:s.offset(),height:s.outerHeight(),bottomPadding:parseInt(s.css("padding-bottom"),10)};d.cache={fits:t.height<e.height,window:{height:e.height},element:{margin:t.margin,top:t.offset.top-t.margin.top,left:t.offset.left,width:t.width,height:t.height,bottom:t.offset.top+t.height},context:{top:o.offset.top,height:o.height,bottomPadding:o.bottomPadding,bottom:o.offset.top+o.height-o.bottomPadding}},d.set.containerSize(),d.set.size(),d.stick(),d.debug("Caching element positions",d.cache)}},get:{direction:function(e){var t="down";return e=e||k.scrollTop(),d.lastScroll!==n&&(d.lastScroll<e?t="down":d.lastScroll>e&&(t="up")),t},scrollChange:function(e){return e=e||k.scrollTop(),d.lastScroll?e-d.lastScroll:0},currentElementScroll:function(){return d.elementScroll?d.elementScroll:d.is.top()?Math.abs(parseInt(C.css("top"),10))||0:Math.abs(parseInt(C.css("bottom"),10))||0},elementScroll:function(e){e=e||k.scrollTop();var t=d.cache.element,o=d.cache.window,n=d.get.scrollChange(e),i=t.height-o.height+h.offset,s=d.get.currentElementScroll(),c=s+n;return s=d.cache.fits||0>c?0:c>i?i:c}},remove:{offset:function(){C.css("margin-top","")}},set:{offset:function(){d.verbose("Setting offset on element",h.offset),C.css("margin-top",h.offset)},containerSize:function(){var e=y.get(0).tagName;"HTML"===e||"body"==e?y=C.offsetParent():Math.abs(y.height()-d.cache.context.height)>5&&(d.debug("Contex