@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
15 lines (12 loc) • 11.4 kB
JavaScript
/*
filename: integralui.dropdown.js
version : 20.2.1
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 t=function(e,o){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)if(e.hasOwnProperty(o))t[o]=e[o]})(e,o)};return function(e,o){t(e,o);function i(){this.constructor=e}e.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}}();Object.defineProperty(exports,"__esModule",{value:!0});var core_1=require("@angular/core"),integralui_core_1=require("../components/integralui.core"),integralui_common_service_1=require("../services/integralui.common.service"),i0=require("@angular/core"),i1=require("../services/integralui.common.service"),i2=require("@angular/common");function IntegralUIDropDownComponent_ng_template_1_Template(t,e){}var _c0=function(t,e){return{top:t,left:e}},_c1=function(t){return[t]},IntegralUIDropDownComponent=function(t){__extends(e,t);function e(e,o){var i=t.call(this,o)||this;i.elemRef=e;i.commonService=o;i.templateObj={};i.showTimer=null;i.popupTimer=null;i.mousePos={x:0,y:0};i.dropdownDisplay="none";i.dropdownPos={top:0,left:0};i.dropdownSize={width:0,height:0};i.closed=new core_1.EventEmitter;i.updateOptions();return i}Object.defineProperty(e.prototype,"settings",{get:function(){return this.dropdownOptions},set:function(t){this.updateOptions(t)},enumerable:!0,configurable:!0});e.prototype.ngAfterContentInit=function(){var t=this,e=setTimeout(function(){t.elemRef.nativeElement.firstElementChild.focus();clearTimeout(e)},500)};e.prototype.ngOnDestroy=function(){};e.prototype.updateAdjustment=function(t){if(t)return{top:this.commonService.isFieldAvailable(t.top,0),right:this.commonService.isFieldAvailable(t.right,0),bottom:this.commonService.isFieldAvailable(t.bottom,0),left:this.commonService.isFieldAvailable(t.left,0)};else return{top:0,right:0,bottom:0,left:0}};e.prototype.updateOptions=function(t){if(t){this.dropdownOptions={adjustment:this.updateAdjustment(t.adjustment),autoClose:this.commonService.isFieldAvailable(t.autoClose,!0),autoPopDelay:this.commonService.isFieldAvailable(t.autoPopDelay,5e3),enabled:this.commonService.isFieldAvailable(t.enabled,!0),initialDelay:this.commonService.isFieldAvailable(t.initialDelay,500),position:this.commonService.isFieldAvailable(t.position,"auto"),showMarker:this.commonService.isFieldAvailable(t.showMarker,!0),title:this.commonService.isFieldAvailable(t.title,"")};this.updateDropDownSize(t.dropDownSize)}else this.dropdownOptions={adjustment:this.updateAdjustment(),autoClose:!0,autoPopDelay:5e3,enabled:!0,initialDelay:500,position:"auto",showMarker:!0,title:""}};e.prototype.updateDropDownSize=function(t){if(t)this.dropdownOptions.dropDownSize={width:this.commonService.isFieldAvailable(t.width,0),height:this.commonService.isFieldAvailable(t.height,0)}};e.prototype.onBlur=function(t){if(0!=this.dropdownOptions.autoClose)this.closed.emit(null)};e.prototype.onMouseDown=function(t){if(1==t.buttons)this.closed.emit(null)};e.prototype.removeTimers=function(){if(this.showTimer){clearTimeout(this.showTimer);this.showTimer=null}if(this.popupTimer){clearTimeout(this.popupTimer);this.popupTimer=null}};e.prototype.open=function(t,e,o){var i=this;i.removeTimers();i.dropdownPos.top=-9999999;i.dropdownDisplay="none";var n=setTimeout(function(){i.dropdownSize=i.getSize();if(i.dropdownOptions.enabled)i.show(t,e,o);clearTimeout(n)},10)};e.prototype.show=function(t,e,o){this.dropdownPos={top:this.mousePos.y+24,left:this.mousePos.x};var i=this.commonService.getShiftPos();switch(this.dropdownOptions.position){case"above":this.dropdownPos={top:t.top+i.y-4-this.dropdownSize.height,left:t.left+i.x+this.dropdownOptions.adjustment.left};break;case"left":this.dropdownPos={top:t.top+i.y-4,left:t.left+i.x-4-this.dropdownSize.width};break;case"right":this.dropdownPos={top:t.top+i.y-4,left:t.right+i.x+4};break;case"below":this.dropdownPos={top:t.bottom+i.y+4+this.dropdownOptions.adjustment.top,left:t.left+i.x+this.dropdownOptions.adjustment.left};break;default:this.dropdownPos={top:t.bottom+i.y+4+this.dropdownOptions.adjustment.top,left:t.left+i.x+this.dropdownOptions.adjustment.left};if(o)if(this.dropdownPos.top+this.dropdownSize.height>o.height){var n=this.dropdownPos.top+this.dropdownSize.height-o.height;this.dropdownPos.top-=n}}this.dropdownDisplay="block"};e.prototype.getSize=function(){var t={width:this.elemRef.nativeElement.firstElementChild.offsetWidth,height:this.elemRef.nativeElement.firstElementChild.offsetHeight};if(this.dropdownOptions.dropDownSize){t.width=this.commonService.isFieldAvailable(this.dropdownOptions.dropDownSize.width,t.width);t.height=this.commonService.isFieldAvailable(this.dropdownOptions.dropDownSize.height,t.height)}return t};e.prototype.updateMousePos=function(t){if(this.mousePos!=t)this.mousePos=t};e.prototype.updateControlClass=function(){this.ctrlClass.length=0;this.ctrlClass.push("iui-dropdown");if(this.dropdownOptions.showMarker)switch(this.dropdownOptions.position){case"above":this.ctrlClass.push("iui-dropdown-marker-bottom");break;case"right":this.ctrlClass.push("iui-dropdown-marker-left");break;case"below":this.ctrlClass.push("iui-dropdown-marker-top");break;case"left":this.ctrlClass.push("iui-dropdown-marker-right")}};e.ɵfac=function(t){return new(t||e)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i1.IntegralUICommonService))};e.ɵcmp=i0.ɵɵdefineComponent({type:e,selectors:[["iui-dropdown"]],inputs:{controlStyle:"controlStyle",data:"data",state:"state",settings:"settings"},outputs:{closed:"closed"},features:[i0.ɵɵInheritDefinitionFeature],decls:2,vars:9,consts:[["tabindex","999",1,"iui-dropdown",3,"ngClass","ngStyle","blur","mousedown"],["ngFor","",3,"ngForOf","ngForTemplate"]],template:function(t,e){if(1&t){i0.ɵɵelementStart(0,"div",0);i0.ɵɵlistener("blur",function(t){return e.onBlur(t)})("mousedown",function(t){return e.onMouseDown(t)});i0.ɵɵtemplate(1,IntegralUIDropDownComponent_ng_template_1_Template,0,0,"ng-template",1);i0.ɵɵelementEnd()}if(2&t){i0.ɵɵproperty("ngClass",e.getControlClass())("ngStyle",i0.ɵɵpureFunction2(4,_c0,e.dropdownPos.top+"px",e.dropdownPos.left+"px"));i0.ɵɵadvance(1);i0.ɵɵproperty("ngForOf",i0.ɵɵpureFunction1(7,_c1,e.templateObj.data))("ngForTemplate",e.templateObj.template)}},directives:[i2.NgClass,i2.NgStyle,i2.NgForOf],encapsulation:2});return e}(integralui_core_1.IntegralUIBaseComponent);exports.IntegralUIDropDownComponent=IntegralUIDropDownComponent;var IntegralUIDropDown=function(){function t(t,e,o){this.elemRef=t;this.cmpResolver=e;this.commonService=o;this.currentSettings=!1;this.eventList=[];this.templateData=[];this.isDropDownOpen=!1;this.isTouchProcessed=!1;this.winScrollPos={top:0,left:0};this.cmpRef=null;this.templateList=[];this.dropDownOpen=new core_1.EventEmitter;this.dropDownOpening=new core_1.EventEmitter;this.dropDownClose=new core_1.EventEmitter}Object.defineProperty(t.prototype,"settings",{get:function(){return this.currentSettings},set:function(t){if(this.currentSettings!=t){this.currentSettings=t;this.updateTemplate()}},enumerable:!0,configurable:!0});Object.defineProperty(t.prototype,"showDropDown",{get:function(){return this.isDropDownOpen},set:function(t){if(this.isDropDownOpen!=t){this.isDropDownOpen=t;this.isDropDownOpen?this.open():this.close()}},enumerable:!0,configurable:!0});t.prototype.ngAfterContentInit=function(){this.updateTemplate()};t.prototype.updateTemplate=function(){this.templateData.length=0;if(this.templates){this.templateList=this.templates.toArray();for(var t=0;t<this.templateList.length;t++)if(this.templateList[t].settings)switch(this.templateList[t].settings.type){case"dropdown":this.templateData.push(this.templateList[t].getTemplate())}}};t.prototype.closeDropDown=function(){if(this.cmpRef){if(this.eventList)this.eventList.forEach(function(t){return t.unsubscribe()});this.cmpRef.destroy()}this.cmpRef=null;this.isDropDownOpen=!1;this.dropDownClose.emit(null)};t.prototype.close=function(){this.closeDropDown()};t.prototype.open=function(t,e){var o=this;o.winScrollPos={top:document.documentElement.scrollTop,left:document.documentElement.scrollLeft};var i=o.dropDownRef?o.dropDownRef:o.settings?o.settings.appRef:null;if(i){var n={cancel:!1,event:t};o.dropDownOpening.emit(n);if(1!=n.cancel){var s=o.cmpResolver.resolveComponentFactory(IntegralUIDropDownComponent);if(s){o.cmpRef=i.createComponent(s);if(o.cmpRef){var r=null;if(o.cmpRef.instance)r=o.cmpRef.instance;if(r){r.settings=o.settings;r.templateObj={data:o.settings.data,template:o.templateData[0]};if(t){var p=t;if(e){var l=this.commonService.getTouchData(t);if(l&&l.length>0)p={pageX:l[0].pageX,pageY:l[0].pageY}}r.updateMousePos(o.commonService.getMousePos(p))}this.dropDownOpen.emit(null);var a=o.settings.appSize?o.settings.appSize:{width:window.innerWidth,height:window.innerHeight},c=this.elemRef.nativeElement.getBoundingClientRect();r.open(c,o.getSize(),a);setTimeout(function(){window.scrollTo(o.winScrollPos.left,o.winScrollPos.top)},5);o.eventList.push(r.closed.subscribe(function(t){o.closeDropDown()}));if(t)t.stopPropagation()}}}}}};t.prototype.getSize=function(){return{width:this.elemRef.nativeElement.offsetWidth,height:this.elemRef.nativeElement.offsetHeight}};t.prototype.onMouseDown=function(t){if(!this.isTouchProcessed)this.processOpen(t)};t.prototype.onTouchStart=function(t){this.isTouchProcessed=!0;this.processOpen(t,!0)};t.prototype.onTouchEnd=function(t){t.stopPropagation()};t.prototype.processOpen=function(t,e){var o=this,i=o.settings?1==o.settings.manual:!1;if((e||1==t.which)&&!i){o.closeDropDown();o.open(t,e)}setTimeout(function(){o.isTouchProcessed=!1},500)};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i0.ComponentFactoryResolver),i0.ɵɵdirectiveInject(i1.IntegralUICommonService))};t.ɵdir=i0.ɵɵdefineDirective({type:t,selectors:[["","iuiDropDown",""]],contentQueries:function(t,e,o){if(1&t)i0.ɵɵcontentQuery(o,integralui_core_1.IntegralUITemplate,!0);if(2&t){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(e.templates=i)}},hostBindings:function(t,e){if(1&t)i0.ɵɵlistener("mousedown",function(t){return e.onMouseDown(t)})("touchstart",function(t){return e.onTouchStart(t)})("touchend",function(t){return e.onTouchEnd(t)})},inputs:{settings:["iuiDropDown","settings"],dropDownRef:"dropDownRef",showDropDown:"showDropDown"},outputs:{dropDownOpen:"dropDownOpen",dropDownOpening:"dropDownOpening",dropDownClose:"dropDownClose"}});return t}();exports.IntegralUIDropDown=IntegralUIDropDown;