wishthis/semantic/dist/components/sticky.min.js

11 lines
12 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
* # Fomantic UI - 2.8.8
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
* Copyright 2022 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
2022-02-23 21:46:34 +00:00
!function(T,w,B,F){"use strict";T.isFunction=T.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},w=void 0!==w&&w.Math==Math?w:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),T.fn.sticky=function(b){var v,e=T(this),x=e.selector||"",C=(new Date).getTime(),S=[],y=b,k="string"==typeof y,z=[].slice.call(arguments,1);return e.each(function(){var t,s,r,e,l=T.isPlainObject(b)?T.extend(!0,{},T.fn.sticky.settings,b):T.extend({},T.fn.sticky.settings),o=l.className,u=l.namespace,d=l.error,n="."+u,h="module-"+u,i=T(this),g=T(w),a=T(l.scrollContext),c=i.data(h),p=w.requestAnimationFrame||w.mozRequestAnimationFrame||w.webkitRequestAnimationFrame||w.msRequestAnimationFrame||function(e){setTimeout(e,0)},f=this,m={initialize:function(){m.determineContainer(),m.determineContext(),m.verbose("Initializing sticky",l,t),m.save.positions(),m.checkErrors(),m.bind.events(),l.observeChanges&&m.observeChanges(),m.instantiate()},instantiate:function(){m.verbose("Storing instance of module",m),c=m,i.data(h,m)},destroy:function(){m.verbose("Destroying previous instance"),m.reset(),r&&r.disconnect(),e&&e.disconnect(),g.off("load"+n,m.event.load).off("resize"+n,m.event.resize),a.off("scrollchange"+n,m.event.scrollchange),i.removeData(h)},observeChanges:function(){"MutationObserver"in w&&(r=new MutationObserver(m.event.documentChanged),e=new MutationObserver(m.event.changed),r.observe(B,{childList:!0,subtree:!0}),e.observe(f,{childList:!0,subtree:!0}),e.observe(s[0],{childList:!0,subtree:!0}),m.debug("Setting up mutation observer",e))},determineContainer:function(){t=l.container?T(l.container):i.offsetParent()},determineContext:function(){0===(s=l.context?T(l.context):t).length&&m.error(d.invalidContext,l.context,i)},checkErrors:function(){m.is.hidden()&&m.error(d.visible,i),m.cache.element.height>m.cache.context.height&&(m.reset(),m.error(d.elementSize,i))},bind:{events:function(){g.on("load"+n,m.event.load).on("resize"+n,m.event.resize),a.off("scroll"+n).on("scroll"+n,m.event.scroll).on("scrollchange"+n,m.event.scrollchange)}},event:{changed:function(e){clearTimeout(m.timer),m.timer=setTimeout(function(){m.verbose("DOM tree modified, updating sticky menu",e),m.refresh()},100)},documentChanged:function(e){[].forEach.call(e,function(e){e.removedNodes&&[].forEach.call(e.removedNodes,function(e){(e==f||0<T(e).find(f).length)&&(m.debug("Element removed from DOM, tearing down events"),m.destroy())})})},load:function(){m.verbose("Page contents finished loading"),p(m.refresh)},resize:function(){m.verbose("Window resized"),p(m.refresh)},scroll:function(){p(function(){a.triggerHandler("scrollchange"+n,a.scrollTop())})},scrollchange:function(e,t){m.stick(t),l.onScroll.call(f)}},refresh:function(e){m.reset(),l.context||m.determineContext(),e&&m.determineContainer(),m.save.positions(),m.stick(),l.onReposition.call(f)},supports:{sticky:function(){var e=T("<div/>");return e.addClass(o.supported),e.css("position").match("sticky")}},save:{lastScroll:function(e){m.lastScroll=e},elementScroll:function(e){m.elementScroll=e},positions:function(){var e={height:a.height()},t={margin:{top:parseInt(i.css("margin-top"),10),bottom:parseInt(i.css("margin-bottom"),10)},offset:i.offset(),width:i.outerWidth(),height:i.outerHeight()},o={offset:s.offset(),height:s.outerHeight()};m.is.standardScroll()||(m.debug("Non-standard scroll. Removing scroll offset from element offset"),e.top=a.scrollTop(),e.left=a.scrollLeft(),t.offset.top+=e.top,o.offset.top+=e.top,t.offset.left+=e.left,o.offset.left+=e.left),m.cache={fits:t.height+l.offset<=e.height,sameHeight:t.height==o.height,scrollContext:{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}},m.set.containerSize(),m.stick(),m.debug("Caching element positions",m.cache)}},get:{direction:function(e){var t="down";return e=e||a.scrollTop(),m.lastScroll!==F&&(m.lastScroll<e?t="down":m.lastScroll>e&&(t="up")),t},scrollChan