@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
15 lines (12 loc) • 16.6 kB
JavaScript
/*
filename: integralui.listbar.js
version : 20.2.0
Copyright © 2016-2020 Lidor Systems. All rights reserved.
This file is part of the "IntegralUI Web" Library.
The contents of this file are subject to the IntegralUI Web License, and may not be used except in compliance with the License.
A copy of the License should have been installed in the product's root installation directory or it can be found at
http://www.lidorsystems.com/products/web/studio/license-agreement.aspx.
This SOFTWARE is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language
governing rights and limitations under the License. Any infringement will be prosecuted under applicable laws.
*/
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)if(t.hasOwnProperty(i))e[i]=t[i]})(t,i)};return function(t,i){e(t,i);function o(){this.constructor=t}t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0});var core_1=require("@angular/core"),integralui_core_1=require("./integralui.core"),integralui_common_service_1=require("../services/integralui.common.service"),integralui_data_service_1=require("../services/integralui.data.service"),integralui_listgroup_1=require("./integralui.listgroup"),i0=require("@angular/core"),i1=require("../services/integralui.data.service"),i2=require("../services/integralui.common.service"),i3=require("./integralui.core"),i4=require("@angular/common"),_c0=["buttonUp"],_c1=["buttonDown"],_c2=["content"],_c3=function(e){return{display:e}},_c4=function(e){return{display:e}},_c5=function(e){return{"margin-top":e}},_c6=["*"],IntegralUIListBar=function(e){__extends(t,e);function t(t,i,o,n,r){var s=e.call(this,o)||this;s.elemRef=t;s.dataService=i;s.commonService=o;s.cmpResolver=n;s.baseService=r;s.numGroups=0;s.blockMarginTop=0;s.scrollPos={x:0,y:0};s.maxScrollPos={x:0,y:0};s.groupEventList=[];s.initScrollPos=0;s.isScrollActive=!1;s.isScrollVisible=!1;s.scrollCount=0;s.scrollTimer=null;s.stopScrolling=!1;s.currentSelection=null;s.currentSelectedIndex=-1;s.selectedComponent=null;s.prevComponent=null;s.removeIndex=-1;s.tRef=null;s.mouseWheelSpeed=integralui_core_1.IntegralUISpeedMode.Normal;s.afterCollapse=new core_1.EventEmitter;s.afterExpand=new core_1.EventEmitter;s.afterSelect=new core_1.EventEmitter;s.beforeCollapse=new core_1.EventEmitter;s.beforeExpand=new core_1.EventEmitter;s.beforeSelect=new core_1.EventEmitter;s.groupAdding=new core_1.EventEmitter;s.groupAdded=new core_1.EventEmitter;s.clear=new core_1.EventEmitter;s.groupRemoving=new core_1.EventEmitter;s.groupRemoved=new core_1.EventEmitter;s.selectionChanged=new core_1.EventEmitter;s.groupList=[];return s}Object.defineProperty(t.prototype,"selectedIndex",{get:function(){return this.currentSelectedIndex},set:function(e){if(this.currentSelectedIndex!=e){this.currentSelectedIndex=e;this.selectComponentByIndex(e)}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"selectedGroup",{get:function(){return this.currentSelection},set:function(e){if(this.currentSelection!=e){this.currentSelection=e;this.selectGroup(e)}},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.baseService.setComponent(this);this.dataService.init([{data:this.groups}]);this.generalClassName="iui-listbar";this.defaultStyle={general:{disabled:this.generalClassName+"-disabled",focused:this.generalClassName+"-focused",normal:this.generalClassName,hovered:this.generalClassName+"-hovered",selected:this.generalClassName+"-selected"}};this.updateStyle(this.controlStyle);this.updateControlClass()};t.prototype.ngAfterViewInit=function(){var e=this,t=setTimeout(function(){var i=e.cmpResolver.resolveComponentFactory(integralui_core_1.IntegralUITComponent);if(i&&e.contentRef)e.tRef=e.contentRef.createComponent(i);clearTimeout(t)},100)};t.prototype.ngAfterContentInit=function(){this.groupList=this.contentList.toArray();this.numGroups=this.groupList.length;this.attachGroupEvents();if(this.numGroups>0)if(this.selectedIndex>=0)this.selectComponentByIndex(this.selectedIndex);else if(this.selectedGroup&&this.groups)this.selectComponentByIndex(this.groups.indexOf(this.selectedGroup));this.updateLayout()};t.prototype.ngOnDestroy=function(){if(this.tRef)this.tRef.destroy()};t.prototype.ngAfterContentChecked=function(){if(this.contentList){this.groupList=this.contentList.toArray();if(this.numGroups!=this.groupList.length){this.attachGroupEvents();this.numGroups=this.groupList.length;this.selectComponentByIndex(this.selectedIndex)}if(0==this.numGroups)this.selectedComponent=null}this.clientRect={width:this.elemRef.nativeElement.firstElementChild.clientWidth,height:this.elemRef.nativeElement.firstElementChild.clientHeight};if(this.clientRect.width!=this.prevClientRect.width){this.updateLayout();this.prevClientRect.width=this.clientRect.width}else if(this.clientRect.height!=this.prevClientRect.height){this.updateLayout();this.prevClientRect.height=this.clientRect.height}this.updateLayout()};t.prototype.clearGroups=function(){this.dataService.clear();this.clear.emit(null)};t.prototype.addGroup=function(e){this.callEventAdd("add",e)};t.prototype.insertGroupAt=function(e,t){this.callEventAdd("at",e,t)};t.prototype.insertGroupBefore=function(e,t){this.callEventAdd("ref",e,-1,t)};t.prototype.insertGroupAfter=function(e,t){this.callEventAdd("ref",e,-1,t,!0)};t.prototype.removeGroup=function(e){this.callEventRemove(e)};t.prototype.removeGroupAt=function(e){if(this.groups&&e>=0&&e<this.groups.length)this.callEventRemove(this.groups[e])};t.prototype.callEventAdd=function(e,t,i,o,n){var r={cancel:!1,group:t};this.groupAdding.emit(r);if(1!=r.cancel){switch(e){case"at":this.dataService.insert(t,i);break;case"ref":this.dataService.insertByRef(t,o,n);break;default:this.dataService.insert(t)}this.groupAdded.emit({group:t});if(!this.selectedComponent)this.selectComponentByIndex(0)}};t.prototype.callEventRemove=function(e){var t={cancel:!1,group:e};this.groupRemoving.emit(t);if(1!=t.cancel){this.removeIndex=this.groups?this.groups.indexOf(e):-1;this.dataService.removeAt(e);this.groupRemoved.emit({group:e})}};t.prototype.closeGroups=function(e){this.groupList=this.contentList.toArray();this.groupList.forEach(function(t,i){if(t!=e){t.selected=!1;t.collapse()}})};t.prototype.toggleGroups=function(){var e=this;if(e.selectedComponent)var t=setTimeout(function(){var i=0,o=0,n=0,r=e.selectedComponent.getContentHeight();if(e.selectedComponent.expanded){if(e.prevComponent)i=e.prevComponent.getContentHeight();var s=setInterval(function(){if(o<r){o+=n=0==n?1:n+2;i=(i-=n)>0?i:0;e.selectedComponent.setContentHeight(o+"px");if(e.prevComponent)e.prevComponent.setContentHeight(i+"px")}else{e.selectedComponent.setContentHeight("auto");if(e.prevComponent){e.prevComponent.setContentHeight("0");e.prevComponent.expanded=!1;e.invokeEvent("AFTER_COLLAPSE",e.prevComponent)}e.invokeEvent("AFTER_EXPAND",e.selectedComponent);clearInterval(s)}},25)}else{e.selectedComponent.setContentHeight("0");if(e.prevComponent)e.prevComponent.setContentHeight("auto")}clearInterval(t)},100)};t.prototype.getGroupCurrentIndex=function(e){this.groupList=this.contentList.toArray();return e&&this.groupList?this.groupList.indexOf(e):-1};t.prototype.getGroupDataIndex=function(e){if(e){var t=this.getGroupCurrentIndex(e);if(this.groups&&t>=0&&t<this.groups.length)return t}return-1};t.prototype.getGroupData=function(e){return this.groups&&e>=0&&e<this.groups.length?this.groups[e]:null};t.prototype.getGroupIndex=function(e){return e&&this.groups?this.groups.indexOf(e):-1};t.prototype.getComponentData=function(e){if(e)if(e.data)return e.data;else{var t=this.getGroupDataIndex(e);if(this.groups&&t>=0&&t<this.groups.length)return this.groups[t]}return null};t.prototype.invokeEvent=function(e,t,i){var o=!0,n=this.getComponentData(t),r={cancel:!1,group:n};switch(e){case"AFTER_COLLAPSE":this.afterCollapse.emit({group:n});break;case"AFTER_EXPAND":this.afterExpand.emit({group:n});if(!i)this.closeGroups(t);break;case"BEFORE_COLLAPSE":this.beforeCollapse.emit(r);o=!r.cancel;break;case"BEFORE_EXPAND":this.beforeExpand.emit(r);o=!r.cancel}return o};t.prototype.invokeMethod=function(e,t){var i=!0;switch(e){case"SELECT_GROUP":i=this.selectComponent(t)}return i};t.prototype.isIndexInRange=function(e){if(this.contentList)this.groupList=this.contentList.toArray();return this.groupList?e>=0&&e<this.groupList.length:!1};t.prototype.attachGroupEvents=function(){var e=this;this.groupList=this.contentList.toArray();if(e.groupEventList){e.groupEventList.forEach(function(e){e.forEach(function(e){e.unsubscribe()})});e.groupEventList.length=0}if(this.groupList&&this.groupList.length>0)this.groupList.forEach(function(t){var i=[];i.push(t.beforeSelect.subscribe(function(i){var o={cancel:!1,group:e.getComponentData(t)};e.beforeSelect.emit(o);i.cancel=o.cancel}));i.push(t.afterSelect.subscribe(function(i){e.clearSelection(t)}));i.push(t.selectedChanged.subscribe(function(i){if(t.selected)e.clearSelection(t)}));e.groupEventList.push(i)})};t.prototype.updateLayout=function(){if(this.contentElem){this.isScrollVisible=this.elemRef.nativeElement.firstElementChild.offsetHeight<this.contentElem.nativeElement.offsetHeight;this.maxScrollPos={x:0,y:this.isScrollVisible?this.elemRef.nativeElement.firstElementChild.offsetHeight-this.contentElem.nativeElement.offsetHeight-(this.buttonUpElem.nativeElement.offsetHeight+this.buttonDownElem.nativeElement.offsetHeight)-2:0};this.initScrollPos=this.isScrollVisible?this.buttonUpElem.nativeElement.offsetHeight:0;if(!this.isScrollVisible)this.scrollPos.y=0}};t.prototype.scrollUpPressed=function(){if(this.isEnabled)this.startScroll(!1)};t.prototype.scrollUpReleased=function(){if(this.isEnabled)this.stopScroll()};t.prototype.scrollDownPressed=function(){if(this.isEnabled)this.startScroll(!0)};t.prototype.scrollDownReleased=function(){if(this.isEnabled)this.stopScroll()};t.prototype.startScroll=function(e){var t=this;if(t.scrollTimer)clearInterval(t.scrollTimer);t.scrollCount=0;t.isScrollActive=!0;t.scrollTimer=setInterval(function(){t.scrollTimerElapsed(e)},100)};t.prototype.stopScroll=function(){if(this.scrollTimer)clearInterval(this.scrollTimer);this.isScrollActive=!1};t.prototype.scrollTimerElapsed=function(e){if(0==this.scrollCount)this.scrollCount=1;this.scrollCount+=5;this.stopScrolling=!1;this.processScroll(e);if(this.stopScrolling)this.stopScroll()};t.prototype.processScroll=function(e){if(e)if(this.scrollPos.y-this.scrollCount>this.maxScrollPos.y)this.scrollPos.y-=this.scrollCount;else{this.stopScrolling=!0;this.scrollPos.y=this.maxScrollPos.y}else if(this.scrollPos.y+this.scrollCount<0)this.scrollPos.y+=this.scrollCount;else{this.stopScrolling=!0;this.scrollPos.y=0}};t.prototype.listMouseWheel=function(e){if(this.isEnabled){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),i=5;switch(this.mouseWheelSpeed){case integralui_core_1.IntegralUISpeedMode.VerySlow:i=15;break;case integralui_core_1.IntegralUISpeedMode.Slow:i=9;break;case integralui_core_1.IntegralUISpeedMode.Fast:i=3;break;case integralui_core_1.IntegralUISpeedMode.VeryFast:i=1}var o=Math.floor(this.clientRect.height/i);this.setScrollPos({x:0,y:this.scrollPos.y-o*t*-1})}};t.prototype.setScrollPos=function(e){var t=e;if(t.y<this.maxScrollPos.y)t.y=this.maxScrollPos.y;if(t.y>0)t.y=0;this.scrollPos={x:0,y:t.y}};t.prototype.clearSelection=function(e){this.groupList=this.contentList.toArray();this.groupList.forEach(function(t,i){if(t!=e){t.selected=!1;t.clearSelection()}})};t.prototype.selectComponent=function(e){var t=this.getComponentData(e),i={cancel:!1,group:t};this.beforeSelect.emit(i);if(1!=i.cancel)if(e&&e!=this.selectedComponent){var o=this.getGroupCurrentIndex(e);this.currentSelectedIndex=o;if(this.groups&&o>=0&&o<this.groups.length)this.currentSelection=this.groups[o];this.prevComponent=this.selectedComponent;this.selectedComponent=e;this.clearSelection(e);e.selected=!0;e.expanded=!0;this.afterSelect.emit({group:t});this.selectionChanged.emit({index:o,group:this.getGroupData(this.getGroupDataIndex(e))});return!0}return!1};t.prototype.selectComponentByIndex=function(e){if(this.isIndexInRange(e))this.selectComponent(this.groupList[e])};t.prototype.selectGroup=function(e){if(this.groups){this.currentSelectedIndex=this.groups.indexOf(e);this.selectComponentByIndex(this.currentSelectedIndex)}};t.prototype.getControlStyle=function(){var e={};if(this.ctrlSize.width>0)e.width=this.ctrlSize.width+"px";if(this.ctrlSize.height>0)e.height=this.ctrlSize.height+"px";return e};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i1.IntegralUIDataService),i0.ɵɵdirectiveInject(i2.IntegralUICommonService),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver),i0.ɵɵdirectiveInject(i3.IntegralUIBaseService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-listbar"]],contentQueries:function(e,t,i){if(1&e)i0.ɵɵcontentQuery(i,integralui_listgroup_1.IntegralUIListGroup,!0);if(2&e){var o;i0.ɵɵqueryRefresh(o=i0.ɵɵloadQuery())&&(t.contentList=o)}},viewQuery:function(e,t){if(1&e){i0.ɵɵviewQuery(_c0,!0,core_1.ElementRef);i0.ɵɵviewQuery(_c1,!0,core_1.ElementRef);i0.ɵɵviewQuery(_c2,!0,core_1.ViewContainerRef);i0.ɵɵviewQuery(_c2,!0,core_1.ElementRef)}if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.buttonUpElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.buttonDownElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.contentRef=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.contentElem=i.first)}},inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",size:"size",state:"state",groups:"groups",mouseWheelSpeed:"mouseWheelSpeed",selectedIndex:"selectedIndex",selectedGroup:"selectedGroup"},outputs:{afterCollapse:"afterCollapse",afterExpand:"afterExpand",afterSelect:"afterSelect",beforeCollapse:"beforeCollapse",beforeExpand:"beforeExpand",beforeSelect:"beforeSelect",groupAdding:"groupAdding",groupAdded:"groupAdded",clear:"clear",groupRemoving:"groupRemoving",groupRemoved:"groupRemoved",selectionChanged:"selectionChanged"},features:[i0.ɵɵProvidersFeature([integralui_core_1.IntegralUIBaseService,integralui_data_service_1.IntegralUIDataService]),i0.ɵɵInheritDefinitionFeature],ngContentSelectors:_c6,decls:10,vars:17,consts:[[3,"ngClass","ngStyle","DOMMouseScroll","mousewheel"],[1,"iui-listbar-button-up",3,"ngStyle","mousedown","mouseup"],["buttonUp",""],[1,"iui-listbar-button-up-icon",3,"ngStyle"],[1,"iui-listbar-content",3,"ngStyle"],["content",""],[1,"iui-listbar-button-down",3,"ngStyle","mousedown","mouseup"],["buttonDown",""],[1,"iui-listbar-button-down-icon",3,"ngStyle"]],template:function(e,t){if(1&e){i0.ɵɵprojectionDef();i0.ɵɵelementStart(0,"div",0);i0.ɵɵlistener("DOMMouseScroll",function(e){return t.listMouseWheel(e)})("mousewheel",function(e){return t.listMouseWheel(e)});i0.ɵɵelementStart(1,"div",1,2);i0.ɵɵlistener("mousedown",function(){return t.scrollUpPressed()})("mouseup",function(){return t.scrollUpReleased()});i0.ɵɵelement(3,"span",3);i0.ɵɵelementEnd();i0.ɵɵelementStart(4,"div",4,5);i0.ɵɵprojection(6);i0.ɵɵelementEnd();i0.ɵɵelementStart(7,"div",6,7);i0.ɵɵlistener("mousedown",function(){return t.scrollDownPressed()})("mouseup",function(){return t.scrollDownReleased()});i0.ɵɵelement(9,"span",8);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",t.getControlStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(7,_c3,t.isScrollVisible?"block":"none"));i0.ɵɵadvance(2);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(9,_c4,0!=t.scrollPos.y?"inline-block":"none"));i0.ɵɵadvance(1);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(11,_c5,t.scrollPos.y+t.initScrollPos-1+"px"));i0.ɵɵadvance(3);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(13,_c3,t.isScrollVisible?"block":"none"));i0.ɵɵadvance(2);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction1(15,_c4,t.scrollPos.y!=t.maxScrollPos.y?"inline-block":"none"))}},directives:[i4.NgClass,i4.NgStyle],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUIListBar=IntegralUIListBar;