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
9.3 KiB

10 years ago
10 years ago
10 years ago
9 years ago
  1. /*
  2. * # Semantic UI - 1.9.1
  3. * https://github.com/Semantic-Org/Semantic-UI
  4. * http://www.semantic-ui.com/
  5. *
  6. * Copyright 2014 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),r=s.selector||"",c=(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.extend(!0,{},e.fn.sticky.settings,o),g=h.className,p=h.namespace,b=h.error,v="."+p,x="module-"+p,C=e(this),S=e(t),y=C.offsetParent(),k=e(h.scrollContext),T=(C.selector||"",C.data(x)),w=t.requestAnimationFrame||t.mozRequestAnimationFrame||t.webkitRequestAnimationFrame||t.msRequestAnimationFrame||function(e){setTimeout(e,0)},z=this;d={initialize:function(){return s=h.context?e(h.context):y,0===s.length?void d.error(b.invalidContext,h.context,C):(d.verbose("Initializing sticky",h,y),d.save.positions(),d.is.hidden()&&d.error(b.visible,C),d.cache.element.height>d.cache.context.height?(d.reset(),void d.error(b.elementSize,C)):(S.on("resize"+v,d.event.resize),k.on("scroll"+v,d.event.scroll),d.observeChanges(),void d.instantiate()))},instantiate:function(){d.verbose("Storing instance of module",d),T=d,C.data(x,d)},destroy:function(){d.verbose("Destroying previous module"),d.reset(),u&&u.disconnect(),S.off("resize"+v,d.event.resize),k.off("scroll"+v,d.event.scroll),C.removeData(x)},observeChanges:function(){var e=s[0];h.observeChanges&&"MutationObserver"in t&&(u=new MutationObserver(function(){clearTimeout(d.timer),d.timer=setTimeout(function(){d.verbose("DOM tree modified, updating sticky menu"),d.refresh()},200)}),u.observe(z,{childList:!0,subtree:!0}),u.observe(e,{childList:!0,subtree:!0}),d.debug("Setting up mutation observer",u))},event:{resize:function(){w(function(){d.refresh(),d.stick()})},scroll:function(){w(function(){d.stick(),h.onScroll.call(z)})}},refresh:function(e){d.reset(),e&&(y=C.offsetParent()),d.save.positions(),d.stick(),h.onReposition.call(z)},supports:{sticky:function(){{var t=e("<div/>");t.get()}return t.addClass(g.supported),t.css("position").match("sticky")}},save:{scroll:function(e){d.lastScroll=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()};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,bottom:o.offset.top+o.height}},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.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,o=d.cache.element,n=d.cache.window,i=d.get.scrollChange(e),s=o.height-n.height+h.offset,r=d.get.currentElementScroll(),c=r+i;return t=d.cache.fits||0>c?0:c>s?s: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():(d.debug("Settings container size",d.cache.context.height),Math.abs(y.height()-d.cache.context.height)>5&&y.height(d.cache.context.height))},scroll:function(e){d.debug("Setting scroll on element",e),d.is.top()&&C.css("bottom","").css("top",-e),d.is.bottom()&&C.css("top","").css("bottom",e)},size:function(){0!==d.cache.element.height&&0!==d.cache.element.width&&C.css({width:d.cache.element.width,height:d.cache.element.height})}},is:{top:function(){return C.hasClass(g.top)},bottom:function(){return C.hasClass(g.bottom)},initialPosition:function(){return!d.is.fixed()&&!d.is.bound()},hidden:function(){return!C.is(":visible")},bound:function(){return C.hasClass(g.bound)},fixed:function(){return C.hasClass(g.fixed