UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 3.58 kB
this.primevue=this.primevue||{},this.primevue.scrolltop=function(e,t,n){"use strict";function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o={name:"ScrollTop",scrollListener:null,container:null,props:{target:{type:String,default:"window"},threshold:{type:Number,default:400},icon:{type:String,default:void 0},behavior:{type:String,default:"smooth"}},data:()=>({visible:!1}),mounted(){"window"===this.target?this.bindDocumentScrollListener():"parent"===this.target&&this.bindParentScrollListener()},beforeUnmount(){"window"===this.target?this.unbindDocumentScrollListener():"parent"===this.target&&this.unbindParentScrollListener(),this.container&&(t.ZIndexUtils.clear(this.container),this.overlay=null)},methods:{onClick(){("window"===this.target?window:this.$el.parentElement).scroll({top:0,behavior:this.behavior})},checkVisibility(e){e>this.threshold?this.visible=!0:this.visible=!1},bindParentScrollListener(){this.scrollListener=()=>{this.checkVisibility(this.$el.parentElement.scrollTop)},this.$el.parentElement.addEventListener("scroll",this.scrollListener)},bindDocumentScrollListener(){this.scrollListener=()=>{this.checkVisibility(t.DomHandler.getWindowScrollTop())},window.addEventListener("scroll",this.scrollListener)},unbindParentScrollListener(){this.scrollListener&&(this.$el.parentElement.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)},unbindDocumentScrollListener(){this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener),this.scrollListener=null)},onEnter(e){t.ZIndexUtils.set("overlay",e,this.$primevue.config.zIndex.overlay)},onAfterLeave(e){t.ZIndexUtils.clear(e)},containerRef(e){this.container=e}},computed:{containerClass(){return["p-scrolltop p-link p-component",{"p-scrolltop-sticky":"window"!==this.target}]},scrollTopAriaLabel(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.scrollTop:void 0}},components:{ChevronUpIcon:i(e).default}};const l=["aria-label"];return function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&i.firstChild?i.insertBefore(o,i.firstChild):i.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.p-scrolltop {\n position: fixed;\n bottom: 20px;\n right: 20px;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n.p-scrolltop-sticky {\n position: sticky;\n}\n.p-scrolltop-sticky.p-link {\n margin-left: auto;\n}\n.p-scrolltop-enter-from {\n opacity: 0;\n}\n.p-scrolltop-enter-active {\n transition: opacity 0.15s;\n}\n.p-scrolltop.p-scrolltop-leave-to {\n opacity: 0;\n}\n.p-scrolltop-leave-active {\n transition: opacity 0.15s;\n}\n"),o.render=function(e,t,i,o,r,s){return n.openBlock(),n.createBlock(n.Transition,{name:"p-scrolltop",appear:"",onEnter:s.onEnter,onAfterLeave:s.onAfterLeave},{default:n.withCtx((()=>[r.visible?(n.openBlock(),n.createElementBlock("button",{key:0,ref:s.containerRef,class:n.normalizeClass(s.containerClass),onClick:t[0]||(t[0]=(...e)=>s.onClick&&s.onClick(...e)),type:"button","aria-label":s.scrollTopAriaLabel},[n.renderSlot(e.$slots,"icon",{},(()=>[(n.openBlock(),n.createBlock(n.resolveDynamicComponent(i.icon?"span":"ChevronUpIcon"),{class:n.normalizeClass(["p-scrolltop-icon",i.icon])},null,8,["class"]))]))],10,l)):n.createCommentVNode("",!0)])),_:3},8,["onEnter","onAfterLeave"])},o}(primevue.icons.chevronup,primevue.utils,Vue);