UNPKG

@lidorsystems/integralui-web

Version:

IntegralUI Web - Advanced UI Components for Angular

15 lines (12 loc) 13.4 kB
/* filename: integralui.accordion.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,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)if(t.hasOwnProperty(n))e[n]=t[n]})(t,n)};return function(t,n){e(t,n);function i(){this.constructor=t}t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();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_groupbox_1=require("./integralui.groupbox"),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=["content"],_c1=["*"],IntegralUIAccordion=function(e){__extends(t,e);function t(t,n,i,o,r){var s=e.call(this,i)||this;s.dataService=t;s.elemRef=n;s.commonService=i;s.cmpResolver=o;s.baseService=r;s.numGroups=0;s.currentSelection=null;s.currentSelectedIndex=-1;s.selectedComponent=null;s.prevComponent=null;s.removeIndex=-1;s.toggleTimer=null;s.tRef=null;s.expandMode=integralui_core_1.IntegralUIExpandMode.Single;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-accordion";this.initStyle()};t.prototype.ngAfterViewInit=function(){var e=this,t=setTimeout(function(){var n=e.cmpResolver.resolveComponentFactory(integralui_core_1.IntegralUITComponent);if(n&&e.contentRef)e.tRef=e.contentRef.createComponent(n);clearTimeout(t)},100)};t.prototype.ngAfterContentInit=function(){this.groupList=this.contentList.toArray();this.numGroups=this.groupList.length;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));else this.selectComponentByIndex(0);this.updateLayout()};t.prototype.ngOnDestroy=function(){if(this.toggleTimer)clearInterval(this.toggleTimer);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.numGroups=this.groupList.length;this.selectComponentByIndex(this.selectedIndex)}if(0==this.numGroups){this.selectedComponent=null;this.currentSelection=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}};t.prototype.addGroup=function(e){this.callEventAdd("add",e)};t.prototype.clearGroups=function(){this.dataService.clear();this.clear.emit(null)};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,n,i,o){var r={cancel:!1,group:t};this.groupAdding.emit(r);if(1!=r.cancel){switch(e){case"at":this.dataService.insert(t,n);break;case"ref":this.dataService.insertByRef(t,i,o);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.collapse=function(e){var t=this.getComponentFromGroup(e);if(t)t.expanded=!1};t.prototype.expand=function(e){var t=this.getComponentFromGroup(e);if(t)t.expanded=!0};t.prototype.closeGroups=function(e){var t=this;t.groupList=t.contentList.toArray();t.groupList.forEach(function(n){if(n!=e){n.selected=!1;if(t.expandMode===integralui_core_1.IntegralUIExpandMode.Single)n.collapse()}})};t.prototype.collapseComponent=function(e){if(e)var t=this,n=setTimeout(function(){var i=0,o=e.getContentHeight();if(t.allowAnimation)var r=setInterval(function(){if(o>0){o=(o-=i=0==i?1:i+2)>0?o:0;e.setContentHeight(o+"px")}else{e.setContentHeight("0");e.expanded=!1;t.invokeEvent("AFTER_COLLAPSE",e);clearInterval(r)}},25);else{e.setContentHeight("0");e.expanded=!1;t.invokeEvent("AFTER_COLLAPSE",e)}clearInterval(n)},100)};t.prototype.toggleGroups=function(){var e=this;if(e.toggleTimer){e.endToggle();clearInterval(e.toggleTimer)}if(e.selectedComponent)e.toggleTimer=setTimeout(function(){var t=0,n=0,i=0,o=e.selectedComponent.getContentHeight(),r=0;if(e.selectedComponent.expanded){if(e.prevComponent)t=e.prevComponent.getContentHeight();if(e.allowAnimation)var s=setInterval(function(){if(n<o){t=(t-=i=0==i?1:i+2)>0?t:0;r=.75*(n+=i)/o;e.selectedComponent.setOpacity(r);e.selectedComponent.setContentHeight(n+"px");if(e.prevComponent&&e.expandMode===integralui_core_1.IntegralUIExpandMode.Single)e.prevComponent.setContentHeight(t+"px")}else{r=1;e.endToggle();clearInterval(s)}},25);else{r=1;e.endToggle()}}else{e.selectedComponent.setContentHeight("0");if(e.prevComponent&&e.expandMode===integralui_core_1.IntegralUIExpandMode.Single)e.prevComponent.setContentHeight("auto")}clearTimeout(e.toggleTimer);e.toggleTimer=null},100)};t.prototype.endToggle=function(){this.selectedComponent.setOpacity(1);this.selectedComponent.setContentHeight("auto");if(this.prevComponent&&this.expandMode===integralui_core_1.IntegralUIExpandMode.Single){this.prevComponent.setContentHeight("0");this.prevComponent.expanded=!1;this.invokeEvent("AFTER_COLLAPSE",this.prevComponent)}this.invokeEvent("AFTER_EXPAND",this.selectedComponent)};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.getComponentFromGroup=function(e){var t=null;if(e){this.groupList=this.contentList.toArray();for(var n=0;n<this.groupList.length;n++)if(this.groupList[n].data&&this.groupList[n].data==e){t=this.groupList[n];break}}return t};t.prototype.invokeEvent=function(e,t,n){var i=!0;if(this.isEnabled){var o=this.getComponentData(t),r={cancel:!1,group:o};switch(e){case"AFTER_COLLAPSE":this.afterCollapse.emit({group:o});break;case"AFTER_EXPAND":this.afterExpand.emit({group:o});this.closeGroups(t);break;case"AFTER_SELECT":this.afterSelect.emit({group:o});break;case"BEFORE_COLLAPSE":this.beforeCollapse.emit(r);i=!r.cancel;break;case"BEFORE_EXPAND":this.beforeExpand.emit(r);i=!r.cancel;break;case"BEFORE_SELECT":this.beforeSelect.emit(r);i=!r.cancel}}return i};t.prototype.invokeMethod=function(e,t){var n=!0;if(this.isEnabled){switch(e){case"COLLAPSE_GROUP":this.collapseComponent(t);break;case"SELECT_GROUP":if(this.invokeEvent("BEFORE_SELECT",t))if(n=this.selectComponent(t))this.invokeEvent("AFTER_SELECT",t);break;case"TOGGLE_GROUPS":this.selectComponent(t);this.toggleGroups();n=!1}}return n};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.updateLayout=function(){};t.prototype.clearSelection=function(){this.clearCmpSelection()};t.prototype.clearCmpSelection=function(e){var t=this;t.groupList=t.contentList.toArray();t.groupList.forEach(function(n){if(n!=e){n.selected=!1;if(t.expandMode===integralui_core_1.IntegralUIExpandMode.Single)n.expanded=!1}});if(!e)t.selectedComponent=null;if(t.prevComponent&&!t.prevComponent.expanded)t.prevComponent=null};t.prototype.selectComponent=function(e){if(e&&e!=this.selectedComponent){var t=this.getGroupCurrentIndex(e);this.currentSelectedIndex=t;if(this.groups&&t>=0&&t<this.groups.length)this.currentSelection=this.groups[t];this.prevComponent=this.selectedComponent;this.selectedComponent=e;this.clearCmpSelection(e);e.selected=!0;e.expanded=this.expandMode!==integralui_core_1.IntegralUIExpandMode.Single?!e.expanded:!0;this.selectionChanged.emit({index:t,group:this.getGroupData(this.getGroupDataIndex(e))});return!0}return!1};t.prototype.selectComponentByIndex=function(e){var t=this,n=setTimeout(function(){if(t.isIndexInRange(e))t.selectComponent(t.groupList[e]);clearTimeout(n)},100)};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.prototype.refresh=function(){this.updateStyle(this.controlStyle);this.updateControlClass()};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i1.IntegralUIDataService),i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i2.IntegralUICommonService),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver),i0.ɵɵdirectiveInject(i3.IntegralUIBaseService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-accordion"]],contentQueries:function(e,t,n){if(1&e)i0.ɵɵcontentQuery(n,integralui_groupbox_1.IntegralUIGroupBox,!0);if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.contentList=i)}},viewQuery:function(e,t){if(1&e)i0.ɵɵviewQuery(_c0,!0,core_1.ViewContainerRef);if(2&e){var n;i0.ɵɵqueryRefresh(n=i0.ɵɵloadQuery())&&(t.contentRef=n.first)}},inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",size:"size",state:"state",expandMode:"expandMode",groups:"groups",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:_c1,decls:4,vars:2,consts:[[3,"ngClass","ngStyle"],["content",""]],template:function(e,t){if(1&e){i0.ɵɵprojectionDef();i0.ɵɵelementStart(0,"div",0);i0.ɵɵelementStart(1,"div",null,1);i0.ɵɵprojection(3);i0.ɵɵelementEnd();i0.ɵɵelementEnd()}if(2&e)i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",t.getControlStyle())},directives:[i4.NgClass,i4.NgStyle],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUIAccordion=IntegralUIAccordion;