wishthis/node_modules/fomantic-ui/dist/components/sticky.min.js

11 lines
12 KiB
JavaScript
Raw Normal View History

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