File: /volume1/@appstore/SynologyDrive/drive/public_share_base.js
/* Copyright (c) 2026 Synology Inc. All rights reserved. */
Ext.ns("SYNO.SDS.Utils.DataView"),SYNO.SDS.Utils.DataView.FlexcrollDataView=Ext.extend(Ext.DataView,{scrollCls:" ux-scroll",overScrollCls:" ux-scroll-over",autoFlexcroll:!0,trackResetOnLoad:!0,initComponent:function(){var t=this;SYNO.SDS.Utils.DataView.FlexcrollDataView.superclass.initComponent.call(t),t.addEvents("refresh","updateScrollbar"),t.mon(t,"beforerender",(function(){t.cls=t.cls?t.cls+t.scrollCls:t.scrollCls,t.overCls=t.overCls?t.overCls+t.overScrollCls:t.overScrollCls}),t)},onStoreException:function(){this.el.unmask()},onStoreLoad:function(){var t=this;t.updateScrollbar(t.trackResetOnLoad),t.fireEvent("afterUpdateScrollbar",t)},onStoreClear:function(){this.updateScrollbar(this.trackResetOnLoad)},bindStore:function(t,e){var l=this;SYNO.SDS.Utils.DataView.FlexcrollDataView.superclass.bindStore.apply(l,arguments),!e&&this.store&&(t!==this.store&&this.store.autoDestroy?this.store.destroy():(l.mun(t,"loadexception",l.onStoreException,l),l.mun(t,"load",l.onStoreLoad,l),l.mun(t,"clear",l.onStoreClear,l),l.mun(t,"datachanged",l.updateScrollbar,l),l.mun(t,"update",l.updateScrollbar,l)),t||(this.store=null)),t&&(t=Ext.StoreMgr.lookup(t),l.mon(t,"loadexception",l.onStoreException,l),l.mon(t,"load",l.onStoreLoad,l),l.mon(t,"clear",l.onStoreClear,l),l.mon(t,"datachanged",l.updateScrollbar,l),l.mon(t,"update",l.updateScrollbar,l))},afterRender:function(){var t=this;SYNO.SDS.Utils.DataView.FlexcrollDataView.superclass.afterRender.call(t),t.mon(t,"resize",t.updateScrollbar,t),t.mon(t,"afterrender",t.updateScrollbar,t),t.mon(t,"afterlayout",t.updateScrollbar,t),t.mon(t,"updateScrollbar",t.onUpdateScrollbar,t,{buffer:100}),t.updateScrollbar()},getTemplateTarget:function(){var t=this;if(t.el.dom)return t.scrollBar=t.scrollBar||t.el.createChild({tag:"div",style:"display:inline-block;width:100%;"}),t.scrollBar},updateScrollbar:function(t){(t=!!Ext.isBoolean(t)&&t)?this.onUpdateScrollbar(t):this.fireEvent("updateScrollbar",t)},onUpdateScrollbar:function(t){var e=this;if(e.isVisible()){var l=e.el.dom;l&&l.fleXcroll?(t&&l.fleXcroll.setScrollPos(!1,0),l.fleXcroll.updateScrollBars(),t||l.fleXcroll.setScrollPos(0,0,!0)):l&&(fleXenv.fleXcrollMain(l,this.disableTextSelect),l.onfleXcroll=function(){this.fireEvent("flexcroll",this,this.getFleXcrollInfo(e.el.dom))}.createDelegate(this),l.fleXcroll&&this.fireEvent("flexcrollInitDone")),l=null}},refresh:function(){SYNO.SDS.Utils.DataView.FlexcrollDataView.superclass.refresh.call(this),this.fireEvent("refresh")},onDestroy:function(){var t=this;t.scrollBar&&(Ext.destroy(t.scrollBar),delete t.scrollBar),SYNO.SDS.Utils.DataView.FlexcrollDataView.superclass.onDestroy.apply(t,arguments)}}),SYNO.SDS.Utils.DataView.SquenceStrategy=function(){var t=this;t.isDestroyed||0!==t.all.getCount()&&t.all.each((function(t){this.updateItem(t)}),t)},SYNO.SDS.Utils.DataView.BinarySearchStrategy=function(){var t=this,e=null,l=-1,i=-1,s=-1,o=0;if(!t.isDestroyed&&0!==t.all.getCount())if(l=(e=t.all.first())&&!0===t.isIntens(e,t.getEl())?0:(e=t.all.last())&&!0===t.isIntens(e,t.getEl())?t.all.getCount()-1:function(){for(var e=null,l=0,i=0,s=t.all.getCount()-1,o=-1;i<=s;){if(o=Math.floor((i+s)/2),e=t.all.item(o),l=t.isIntens(e,t.getEl()),e&&!0===l)return o;!1===l?i=o+1:l<0&&(s=o-1)}return-1}(),-1===l)t.all.each((function(t){this.onUnLoadItem(t)}),t);else{for(o=l;o<t.all.getCount();o++){if(!0!==t.isIntens(t.all.item(o),t.getEl())){s=o;break}t.onLoadItem(e)}for(o=l-1;o>=0;o--){if(!0!==t.isIntens(t.all.item(o),t.getEl())){i=o;break}t.onLoadItem(e)}if(-1!==i)for(o=i;o>=0;o--)t.onUnLoadItem(e);if(-1!==s)for(o=s;o<t.all.getCount();o++)t.onUnLoadItem(e)}},SYNO.SDS.Utils.DataView.ConstantSearchStrategy=function(){var t=this,e=null,l=-1,i=-1,s=-1,o=0;if(!t.isDestroyed&&0!==t.all.getCount())if(-1===(l=(e=t.all.first())&&!0===t.isIntens(e,t.getEl())?0:(e=t.all.last())&&!0===t.isIntens(e,t.getEl())?t.all.getCount()-1:function(e){var l=e.getSize(),i=e.getMargins(),s=t.el.dom.fleXdata?t.el.dom.fleXdata.scrollPosition[1][0]:0;return Math.floor(s/(l.height+i.top+i.bottom))*Math.floor(t.el.getWidth()/(l.width+i.right+i.left))}(t.all.first())))t.all.each((function(t){this.onUnLoadItem(t)}),t);else{for(o=l;o<t.all.getCount();o++){if(!0!==t.isIntens(t.all.item(o),t.getEl())){s=o;break}t.onLoadItem(e)}for(o=l-1;o>=0;o--){if(!0!==t.isIntens(t.all.item(o),t.getEl())){i=o;break}t.onLoadItem(e)}if(-1!==i)for(o=i;o>=0;o--)t.onUnLoadItem(t.all.item(o));if(-1!==s)for(o=s;o<t.all.getCount();o++)t.onUnLoadItem(t.all.item(o))}},SYNO.SDS.Utils.DataView.LazyDataView=Ext.extend(SYNO.SDS.Utils.DataView.FlexcrollDataView,{delay:600,widthThreshold:0,heightThreshold:0,autoHeightThreshold:!0,constructor:function(t){this.itemCls=t.itemCls||void 0,this.searchStrategy=this.searchStrategy||SYNO.SDS.Utils.DataView.SquenceStrategy.createDelegate(this),this.addPlugins(SYNO.ux.DataViewARIA,t),SYNO.SDS.Utils.DataView.LazyDataView.superclass.constructor.apply(this,[t]),this.last=!1},initKeyNav:function(){new Ext.KeyNav(this.el,{down:function(t){this.onKeyDown(t)},up:function(t){this.onKeyUp(t)},left:function(t){this.onKeyLeft(t)},right:function(t){this.onKeyRight(t)},scope:this})},focusNode:function(t){var e=this,l=e.getNode(t);e.autoFlexcroll&&e.fleXcrollTo(l)},getFirstSelItemIdx:function(){return this.getSelectedIndexes()[0]},getLastSelItemIdx:function(){return this.getSelectedIndexes()[this.getSelectedIndexes().length-1]},getThumbnailRowNum:function(t){var e=t.getTemplateTarget(),l=getComputedStyle(t.selected.elements[0]),i=parseInt(l.width,10)+parseInt(l.marginLeft,10)+parseInt(l.marginRight,10);return Math.floor(e.getWidth()/i)},isNeedToShift:function(){return!!this.selected.elements[0]},selectItem:function(t,e){e?this.select(t,!0,!0):this.select(t),this.focusNode(t)},selectPreItem:function(){var t,e=this.getFirstSelItemIdx();t=0===e?0:e-1,this.selectItem(t)},selectNextItem:function(){var t,e=this.getFirstSelItemIdx(),l=this.store.getCount()-1;t=e==l?l:e+1,this.selectItem(t)},selectPreRowItem:function(t){var e,l=this.getFirstSelItemIdx();l<t?this.selectItem(l):(e=l-t,this.selectItem(e))},selectNextRowItem:function(t){var e,l=this.getFirstSelItemIdx();(e=l+t)>this.store.getCount()-1?this.selectItem(l):this.selectItem(e)},selectPreItemIn:function(){var t,e=this.last;t=0===this.getLastSelItemIdx()?0:this.getLastSelItemIdx()-1,this.selectRange(e,t),this.last=e},selectNextItemIn:function(){var t,e=this.last,l=this.store.getCount()-1;t=this.getLastSelItemIdx()+1>l?l:this.getLastSelItemIdx()+1,this.selectRange(e,t),this.last=e},selectPreRowItemIn:function(t){var e,l=this.last;e=this.getLastSelItemIdx()<t?0:this.getLastSelItemIdx()-t,this.selectRange(l,e),this.last=l},selectNextRowItemIn:function(t){var e,l=this.last,i=this.store.getCount()-1;e=this.getLastSelItemIdx()+t>i?i:this.getLastSelItemIdx()+t,this.selectRange(l,e),this.last=l},onKeyUp:function(t){if(!0===this.isNeedToShift()){var e=this,l=e.getThumbnailRowNum(e);t.shiftKey?e.selectPreRowItemIn(l):e.selectPreRowItem(l)}else this.selectItem(0)},onKeyDown:function(t){if(!0===this.isNeedToShift()){var e=this,l=e.getThumbnailRowNum(e);t.shiftKey?e.selectNextRowItemIn(l):e.selectNextRowItem(l)}else this.selectItem(0)},onKeyRight:function(t){if(!0===this.isNeedToShift()){t.shiftKey?this.selectNextItemIn():this.selectNextItem()}else this.selectItem(0)},onKeyLeft:function(t){if(!0===this.isNeedToShift()){t.shiftKey?this.selectPreItemIn():this.selectPreItem()}else this.selectItem(0)},setSearchStategy:function(t){this.searchStrategy=t},onLoadItem:function(t){},onUnLoadItem:function(t){},belowthefold:function(t,e,l){return(l||e.getY())+e.dom.scrollTop+e.getHeight()-(t.getY()-this.heightThreshold)},rightoffold:function(t,e,l){return(l||e.getX())+e.dom.scrollLeft+e.getWidth()-(t.getX()-this.widthThreshold)},abovethetop:function(t,e,l){return(l||e.getY())+e.dom.scrollTop>=t.getY()+this.heightThreshold+t.getHeight()},leftofbegin:function(t,e,l){return(l||e.getX())+e.dom.scrollLeft>=t.getX()+this.widthThreshold+t.getWidth()},isIntens:function(t,e){var l=this,i=0,s=0,o=e.getX(),a=e.getY();return!!l.isVisible()&&(!!t&&(!l.abovethetop(t,e,a)&&!l.leftofbegin(t,e,o)&&((s=l.belowthefold(t,e,a))>=0&&(i=l.rightoffold(t,e,o))>=0||i+s)))},fitWidth:function(){var t,e,l,i,s=this,o=s.getTemplateTarget(),a=s.all.item(0),r=!0;if(Ext.isObject(a)&&s.itemCls&&(Ext.util.CSS.getRule(s.itemCls)&&(s.marginLeft=s.marginLeft||a.getMargins("l")||0,s.marginRight=s.marginRight||a.getMargins("r")||0,i=s.marginLeft+s.marginRight,Ext.isNumber(i)&&(l=a.getWidth()+i,0!==(e=Math.floor(o.getWidth()/l))))))return t=Math.floor(o.getWidth()%l),a.getMargins("l")!==Math.floor(s.marginLeft+t/2/e)&&(r=(r=r&&Ext.util.CSS.updateRule(s.itemCls,"margin-left",Math.floor(s.marginLeft+t/2/e)+"px"))&&Ext.util.CSS.updateRule(s.itemCls,"margin-right",Math.floor(s.marginRight+t/2/e)+"px")),r},updateScrollbar:function(t){(t=!!Ext.isBoolean(t)&&t)?this.onUpdateScrollbar(t):this.fireEvent("updateScrollbar",t)},onUpdateScrollbar:function(t){var e=this;if(e.isVisible()){var l=e.el.dom;l&&l.fleXcroll?(t&&l.fleXcroll.setScrollPos(!1,0),l.fleXcroll.updateScrollBars(),t||l.fleXcroll.setScrollPos(0,0,!0)):l&&(fleXenv.fleXcrollMain(l,this.disableTextSelect),l.onfleXcroll=function(){e.isVisible()&&e.onUpdateView&&e.onUpdateView(),this.fireEvent("flexcroll",this,this.getFleXcrollInfo(e.el.dom))}.createDelegate(this),l.fleXcroll&&this.fireEvent("flexcrollInitDone")),l=null}},afterRender:function(){var t=this;SYNO.SDS.Utils.DataView.LazyDataView.superclass.afterRender.call(t),t.mon(t,{resize:t.onResize,scope:t}),t.initKeyNav(),this.updateHeightThreshold()},onUserResize:function(){this.updateScrollbar(),this.updateHeightThreshold(),this.fitWidth.createSequence((function(){this.updateScrollbar.defer(300,this)}),this).defer(330,this)},onResize:function(){this.resizeTask||(this.resizeTask=new Ext.util.DelayedTask(this.onUserResize,this)),this.resizeTask.delay(350)},updateHeightThreshold:function(){!this.autoHeightThreshold||Ext.isIE&&!Ext.isModernIE||(this.heightThreshold=this.getEl().getHeight())},onUpdateView:function(){this.delay?(this.renderTask||(this.renderTask=new Ext.util.DelayedTask(this.searchStrategy,this)),this.renderTask.delay(this.delay)):this.searchStrategy()},updateItem:function(t){var e=this;t.isVisible()&&!0===e.isIntens(t,e.getEl())?e.onLoadItem(t):e.onUnLoadItem(t)},lazyLoadItem:function(t){this.updateItem(Ext.fly(t))},onBeforeLoad:function(){this.loadingText&&(this.clearSelections(!1,!0),this.getEl().mask(this.loadingText,"x-mask-loading"),this.all.clear())},refresh:function(){this.loadingText&&this.getEl().unmask(),SYNO.SDS.Utils.DataView.LazyDataView.superclass.refresh.call(this),this.onUpdateView()},removeTask:function(t){var e=this[t];e&&e.cancel&&(e.cancel(),this[t]=null)},destroy:function(){this.removeTask("renderTask"),this.removeTask("resizeTask"),SYNO.SDS.Utils.DataView.LazyDataView.superclass.destroy.call(this)}});