UNPKG

@lidorsystems/integralui-web

Version:

IntegralUI Web - Advanced UI Components for Angular

15 lines (12 loc) 15.5 kB
/* filename: integralui.slidebar.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 n(){this.constructor=t}t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}();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"),i0=require("@angular/core"),i1=require("../services/integralui.data.service"),i2=require("../services/integralui.common.service"),i3=require("@angular/common"),_c0=["*"],_c1=["control"],_c2=["block"],_c3=["arrow"];function IntegralUISlideBar_span_6_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"span",8);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);var e=t.index;return i0.ɵɵnextContext().selectSlideByIndex(e)});i0.ɵɵelementEnd()}if(2&e){var n=t.$implicit,l=i0.ɵɵnextContext();i0.ɵɵproperty("ngClass",l.getButtonClass(n))}}var _c4=function(e,t){return{display:e,top:t}};function IntegralUISlideBar_div_7_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"div",9,10);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().prevSlide()});i0.ɵɵelement(2,"span");i0.ɵɵelementEnd()}if(2&e){var n=i0.ɵɵnextContext();i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction2(1,_c4,n.arrowDisplay,n.arrowTopPos+"px"))}}function IntegralUISlideBar_div_8_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"div",11);i0.ɵɵlistener("click",function(){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext().nextSlide()});i0.ɵɵelement(1,"span");i0.ɵɵelementEnd()}if(2&e){var n=i0.ɵɵnextContext();i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction2(1,_c4,n.arrowDisplay,n.arrowTopPos+"px"))}}var _c5=function(e){return{width:e}},_c6=function(e,t,i){return{"margin-left":e,width:t,height:i}},IntegralUISlide=function(){function e(e){this.elemRef=e}e.prototype.size=function(){return{width:Math.floor(this.elemRef.nativeElement.firstElementChild.offsetWidth),height:Math.floor(this.elemRef.nativeElement.firstElementChild.offsetHeight)}};e.prototype.cloneElem=function(){return this.elemRef.nativeElement.firstElementChild.cloneNode(!0)};e.ɵfac=function(t){return new(t||e)(i0.ɵɵdirectiveInject(i0.ElementRef))};e.ɵcmp=i0.ɵɵdefineComponent({type:e,selectors:[["iui-slide"]],ngContentSelectors:_c0,decls:2,vars:0,consts:[["data-element","slide",1,"iui-slide"]],template:function(e,t){if(1&e){i0.ɵɵprojectionDef();i0.ɵɵelementStart(0,"li",0);i0.ɵɵprojection(1);i0.ɵɵelementEnd()}},encapsulation:2});return e}();exports.IntegralUISlide=IntegralUISlide;var IntegralUISlideBar=function(e){__extends(t,e);function t(t,i,n,l){var r=e.call(this,n)||this;r.dataService=t;r.elemRef=i;r.commonService=n;r.cmpResolver=l;r.animationTimeout=null;r.animationTimer=null;r.buttons=[];r.arrowTopPos=0;r.arrowDisplay="none";r.numSlides=0;r.cloneAdded=!1;r.cloneElem=null;r.blockMargin=0;r.elemSize={width:0,height:0};r.blockSize={width:0,height:0};r.slideSize={width:0,height:0};r.currentSelection=null;r.currentSelectedIndex=-1;r.selectedSlideComponent=null;r.removeIndex=-1;r.tRef=null;r.allowAnimation=!0;r.animationPause=2e3;r.animationSpeed=integralui_core_1.IntegralUISpeedMode.Normal;r.navigationButtons=!0;r.clear=new core_1.EventEmitter;r.slideAdding=new core_1.EventEmitter;r.slideAdded=new core_1.EventEmitter;r.slideChanged=new core_1.EventEmitter;r.slideRemoving=new core_1.EventEmitter;r.slideRemoved=new core_1.EventEmitter;return r}Object.defineProperty(t.prototype,"selectedIndex",{get:function(){return this.currentSelectedIndex},set:function(e){if(this.currentSelectedIndex!=e){this.currentSelectedIndex=e;this.selectSlideByIndex(e)}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"selectedSlide",{get:function(){return this.currentSelection},set:function(e){if(this.currentSelection!=e){this.currentSelection=e;if(this.slides)this.selectSlideByIndex(this.slides.indexOf(e))}},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.dataService.init([{data:this.slides}])};t.prototype.ngAfterViewInit=function(){var e=this,t=setTimeout(function(){var i=e.cmpResolver.resolveComponentFactory(integralui_core_1.IntegralUITComponent);if(i)e.tRef=e.blockRef.createComponent(i);clearTimeout(t)},100)};t.prototype.ngAfterContentInit=function(){this.slideList=this.contentSlideList.toArray();this.checkClone();this.numSlides=this.slideList.length;if(this.numSlides>0)if(this.selectedIndex>=0)this.selectSlideByIndex(this.selectedIndex);else if(this.selectedSlide&&this.slides)this.selectSlideByIndex(this.slides.indexOf(this.selectedSlide));this.updateLayout();this.changeSlide()};t.prototype.ngOnDestroy=function(){if(this.tRef)this.tRef.destroy()};t.prototype.ngAfterContentChecked=function(){if(this.contentSlideList){this.slideList=this.contentSlideList.toArray();if(this.numSlides!=this.slideList.length){if(this.numSlides>this.slideList.length&&this.slides&&this.slides.length>0){if(this.removeIndex==this.slides.length)this.removeIndex=this.slides.length-1;if(this.removeIndex>=0&&this.removeIndex<this.slides.length)if(this.isIndexInRange(this.removeIndex))this.selectSlideByIndex(this.removeIndex);else this.selectSlideByIndex(this.slideList.length-1)}this.numSlides=this.slideList.length;this.updateLayout()}if(0==this.numSlides){if(this.cloneElem){this.cloneElem.remove();this.cloneElem=null;this.cloneAdded=!1}this.selectedSlideComponent=null;this.arrowDisplay="none"}}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.checkClone=function(){if(this.slideList&&this.slideList.length>0&&!this.cloneAdded){this.cloneElem=this.slideList[0].cloneElem();this.blockElem.nativeElement.append(this.cloneElem);this.cloneAdded=!0}};t.prototype.clearSlides=function(){this.dataService.clear();this.clear.emit(null)};t.prototype.addSlide=function(e){this.callEventAdd("add",e)};t.prototype.insertSlideAt=function(e,t){this.callEventAdd("at",e,t)};t.prototype.insertSlideBefore=function(e,t){this.callEventAdd("ref",e,-1,t)};t.prototype.insertSlideAfter=function(e,t){this.callEventAdd("ref",e,-1,t,!0)};t.prototype.removeSlide=function(e){this.callEventRemove(e)};t.prototype.removeSlideAt=function(e){if(this.slides&&e>=0&&e<this.slides.length)this.callEventRemove(this.slides[e])};t.prototype.callEventAdd=function(e,t,i,n,l){var r={cancel:!1,slide:t};this.slideAdding.emit(r);if(1!=r.cancel){switch(e){case"at":this.dataService.insert(t,i);break;case"ref":this.dataService.insertByRef(t,n,l);break;default:this.dataService.insert(t)}this.slideAdded.emit({slide:t});if(!this.selectedSlideComponent)this.selectSlideByIndex(0)}};t.prototype.callEventRemove=function(e){var t={cancel:!1,slide:e};this.slideRemoving.emit(t);if(1!=t.cancel){this.removeIndex=this.slides?this.slides.indexOf(e):-1;this.dataService.removeAt(e);this.slideRemoved.emit({slide:e})}};t.prototype.getButtonClass=function(e){var t=this.getSlideCurrentIndex(this.selectedSlideComponent);if(e&&e.index==t)return"iui-slidebar-navigator-button-selected";else return""};t.prototype.getSlideCurrentIndex=function(e){this.slideList=this.contentSlideList.toArray();return e&&this.slideList?this.slideList.indexOf(e):-1};t.prototype.getSlideDataIndex=function(e){if(e){var t=this.getSlideCurrentIndex(e);if(this.slides&&t>=0&&t<this.slides.length)return t}return-1};t.prototype.getSlideData=function(e){return this.slides&&e>=0&&e<this.slides.length?this.slides[e]:null};t.prototype.isIndexInRange=function(e){return this.slideList?e>=0&&e<this.slideList.length:!1};t.prototype.ctrlMouseEnter=function(e){if(this.isEnabled)this.arrowDisplay="block"};t.prototype.ctrlMouseLeave=function(e){this.arrowDisplay="none"};t.prototype.prevSlide=function(){if(this.isEnabled){var e=this.getSlideCurrentIndex(this.selectedSlideComponent)-1;if(this.isIndexInRange(e))this.selectSlideByIndex(e);else this.selectSlideByIndex(this.slideList.length-1)}};t.prototype.nextSlide=function(){if(this.isEnabled){var e=this.getSlideCurrentIndex(this.selectedSlideComponent)+1;if(this.isIndexInRange(e))this.selectSlideByIndex(e);else this.selectSlideByIndex(0)}};t.prototype.updateLayout=function(){var e=this;e.slideList=e.contentSlideList.toArray();e.buttons.length=0;if(e.slideList&&e.slideList.length>0){e.blockSize.width=0;e.checkClone();if(!e.selectedSlideComponent)e.selectedSlideComponent=e.slideList[0];var t=0;e.slideList.forEach(function(i){var n=i.size();e.blockSize.width+=n.width;e.blockSize.height=n.height;if(i==e.slideList[0]){e.blockSize.width+=n.width;e.elemSize.width=n.width}e.slideSize.width=n.width;e.slideSize.height=n.height;e.buttons.push({index:t});t++});e.blockSize.width++;e.arrowTopPos=e.arrowElem?Math.floor((e.blockSize.height-e.arrowElem.nativeElement.offsetHeight)/2):-999}};t.prototype.cancelAnimation=function(){if(this.animationTimer)clearInterval(this.animationTimer);this.animationTimer=null};t.prototype.changeSlide=function(){var e=this.getSlideCurrentIndex(this.selectedSlideComponent);if(e>=0)this.blockMargin=-this.slideSize.width*e;this.startAnimation()};t.prototype.getSpeedFactor=function(){switch(this.animationSpeed){case integralui_core_1.IntegralUISpeedMode.VeryFast:return 25;case integralui_core_1.IntegralUISpeedMode.Fast:return 15;case integralui_core_1.IntegralUISpeedMode.Slow:return 5;case integralui_core_1.IntegralUISpeedMode.VerySlow:return 2}return 10};t.prototype.startAnimation=function(){var e=this;if(e.animationTimeout)clearTimeout(e.animationTimeout);e.animationTimeout=setTimeout(function(){e.cancelAnimation();if(0!=e.allowAnimation&&e.slideList.length>1){var t=e.getSlideCurrentIndex(e.selectedSlideComponent),i=0,n=e.getSpeedFactor();e.animationTimer=setInterval(function(){if(i<e.slideSize.width){i+=n;e.blockMargin-=n}else{i=0;e.cancelAnimation();t++;if(e.isIndexInRange(t))e.selectSlideByIndex(t);else e.selectSlideByIndex(0)}},15)}clearTimeout(e.animationTimeout)},e.animationPause)};t.prototype.stopAnimation=function(){this.cancelAnimation();var e=this.getSlideCurrentIndex(this.selectedSlideComponent);this.blockMargin=-this.slideSize.width*e};t.prototype.selectSlide=function(e){if(e){this.selectedSlideComponent=e;this.slideChanged.emit({index:this.getSlideCurrentIndex(e),slide:this.getSlideData(this.getSlideDataIndex(e))});this.changeSlide()}};t.prototype.selectSlideByIndex=function(e){if(this.isIndexInRange(e))this.selectSlide(this.slideList[e])};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(i1.IntegralUIDataService),i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i2.IntegralUICommonService),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-slidebar"]],contentQueries:function(e,t,i){if(1&e)i0.ɵɵcontentQuery(i,IntegralUISlide,!0);if(2&e){var n;i0.ɵɵqueryRefresh(n=i0.ɵɵloadQuery())&&(t.contentSlideList=n)}},viewQuery:function(e,t){if(1&e){i0.ɵɵviewQuery(_c1,!0,core_1.ViewContainerRef);i0.ɵɵviewQuery(_c2,!0,core_1.ViewContainerRef);i0.ɵɵstaticViewQuery(_c2,!0,core_1.ElementRef);i0.ɵɵviewQuery(_c3,!0,core_1.ElementRef)}if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.controlRef=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.blockRef=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.blockElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.arrowElem=i.first)}},inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",name:"name",size:"size",state:"state",allowAnimation:"allowAnimation",animationPause:"animationPause",animationSpeed:"animationSpeed",navigationButtons:"navigationButtons",slides:"slides",selectedIndex:"selectedIndex",selectedSlide:"selectedSlide"},outputs:{clear:"clear",slideAdding:"slideAdding",slideAdded:"slideAdded",slideChanged:"slideChanged",slideRemoving:"slideRemoving",slideRemoved:"slideRemoved"},features:[i0.ɵɵProvidersFeature([integralui_data_service_1.IntegralUIDataService]),i0.ɵɵInheritDefinitionFeature],ngContentSelectors:_c0,decls:9,vars:12,consts:[["data-element","slidebar",1,"iui-slidebar",3,"ngStyle","mouseenter","mouseleave"],["control",""],[1,"iui-slidebar-container",3,"ngStyle"],["block",""],[1,"iui-slidebar-navigator"],["class","iui-slidebar-navigator-button",3,"ngClass","click",4,"ngFor","ngForOf"],["class","iui-slidebar-arrow iui-slidebar-arrow-left",3,"ngStyle","click",4,"ngIf"],["class","iui-slidebar-arrow iui-slidebar-arrow-right",3,"ngStyle","click",4,"ngIf"],[1,"iui-slidebar-navigator-button",3,"ngClass","click"],[1,"iui-slidebar-arrow","iui-slidebar-arrow-left",3,"ngStyle","click"],["arrow",""],[1,"iui-slidebar-arrow","iui-slidebar-arrow-right",3,"ngStyle","click"]],template:function(e,t){if(1&e){i0.ɵɵprojectionDef();i0.ɵɵelementStart(0,"div",0,1);i0.ɵɵlistener("mouseenter",function(e){return t.ctrlMouseEnter(e)})("mouseleave",function(e){return t.ctrlMouseLeave(e)});i0.ɵɵelementStart(2,"ul",2,3);i0.ɵɵprojection(4);i0.ɵɵelementEnd();i0.ɵɵelementStart(5,"div",4);i0.ɵɵtemplate(6,IntegralUISlideBar_span_6_Template,1,1,"span",5);i0.ɵɵelementEnd();i0.ɵɵtemplate(7,IntegralUISlideBar_div_7_Template,3,4,"div",6);i0.ɵɵtemplate(8,IntegralUISlideBar_div_8_Template,2,4,"div",7);i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngStyle",t.getControlStyle())("ngStyle",i0.ɵɵpureFunction1(6,_c5,t.elemSize.width+"px"));i0.ɵɵadvance(2);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction3(8,_c6,t.blockMargin+"px",t.blockSize.width+"px",t.blockSize.height+"px"));i0.ɵɵadvance(4);i0.ɵɵproperty("ngForOf",t.buttons);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",t.navigationButtons);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",t.navigationButtons)}},directives:[i3.NgStyle,i3.NgForOf,i3.NgIf,i3.NgClass],encapsulation:2});return t}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUISlideBar=IntegralUISlideBar;