@lidorsystems/integralui-web
Version:
IntegralUI Web - Advanced UI Components for Angular
15 lines (12 loc) • 17 kB
JavaScript
/*
filename: integralui.menuitem.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("./integralui.core"),i4=require("@angular/common"),_c0=["block"],_c1=["content"];function IntegralUIMenuItem_div_1_span_1_span_2_Template(e,t){if(1&e)i0.ɵɵelement(0,"span",7);if(2&e){var i=i0.ɵɵnextContext(3);i0.ɵɵstyleProp("display",i.getIconStatus());i0.ɵɵproperty("ngClass",i.icon)}}function IntegralUIMenuItem_div_1_span_1_img_3_Template(e,t){if(1&e)i0.ɵɵelement(0,"img",8);if(2&e){var i=i0.ɵɵnextContext(3);i0.ɵɵpropertyInterpolate("src",i.iconUrl,i0.ɵɵsanitizeUrl)}}function IntegralUIMenuItem_div_1_span_1_span_4_Template(e,t){if(1&e){i0.ɵɵelementStart(0,"span",9);i0.ɵɵtext(1);i0.ɵɵelementEnd()}if(2&e){var i=i0.ɵɵnextContext(3);i0.ɵɵadvance(1);i0.ɵɵtextInterpolate(i.text)}}function IntegralUIMenuItem_div_1_span_1_Template(e,t){if(1&e){i0.ɵɵelementStart(0,"span",null,3);i0.ɵɵtemplate(2,IntegralUIMenuItem_div_1_span_1_span_2_Template,1,3,"span",4);i0.ɵɵtemplate(3,IntegralUIMenuItem_div_1_span_1_img_3_Template,1,1,"img",5);i0.ɵɵtemplate(4,IntegralUIMenuItem_div_1_span_1_span_4_Template,2,1,"span",6);i0.ɵɵelementEnd()}if(2&e){var i=i0.ɵɵnextContext(2);i0.ɵɵadvance(2);i0.ɵɵproperty("ngIf",i.icon);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",i.iconUrl);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",i.text)}}var _c2=function(e){return{$implicit:e}};function IntegralUIMenuItem_div_1_span_2_Template(e,t){if(1&e){i0.ɵɵelementStart(0,"span",null,3);i0.ɵɵelement(2,"span",10);i0.ɵɵelementEnd()}if(2&e){var i=i0.ɵɵnextContext(2);i0.ɵɵadvance(2);i0.ɵɵproperty("iuiTemplateOutlet",i.templateRef)("iuiTemplateOutletContext",i0.ɵɵpureFunction1(2,_c2,i.data))}}function IntegralUIMenuItem_div_1_ul_3_iui_menuitem_2_Template(e,t){if(1&e){var i=i0.ɵɵgetCurrentView();i0.ɵɵelementStart(0,"iui-menuitem",14);i0.ɵɵlistener("mouseDown",function(e){i0.ɵɵrestoreView(i);return i0.ɵɵnextContext(3).onChildItemMouseDown(e)});i0.ɵɵelementEnd()}if(2&e){var n=t.$implicit,a=i0.ɵɵnextContext(3);i0.ɵɵproperty("data",n)("items",n.items)("enabled",n.enabled)("icon",n.icon)("iconUrl",n.iconUrl)("text",n.text)("level",a.getItemLevel())("templateRef",a.templateRef)("showAnimation",a.showAnimation)}}var _c3=function(e,t,i,n,a,o){return{display:e,top:t,left:i,height:n,overflow:a,opacity:o}};function IntegralUIMenuItem_div_1_ul_3_Template(e,t){if(1&e){i0.ɵɵelementStart(0,"ul",11,12);i0.ɵɵtemplate(2,IntegralUIMenuItem_div_1_ul_3_iui_menuitem_2_Template,1,9,"iui-menuitem",13);i0.ɵɵelementEnd()}if(2&e){var i=i0.ɵɵnextContext(2);i0.ɵɵproperty("ngStyle",i0.ɵɵpureFunction6(2,_c3,i.blockDisplay,i.blockPos.top+"px",i.blockPos.left+"px",i.blockElemHeight,i.blockOverflow,i.blockOpacity));i0.ɵɵadvance(2);i0.ɵɵproperty("ngForOf",i.items)}}function IntegralUIMenuItem_div_1_Template(e,t){if(1&e){i0.ɵɵelementStart(0,"div");i0.ɵɵtemplate(1,IntegralUIMenuItem_div_1_span_1_Template,5,3,"span",1);i0.ɵɵtemplate(2,IntegralUIMenuItem_div_1_span_2_Template,3,4,"span",1);i0.ɵɵtemplate(3,IntegralUIMenuItem_div_1_ul_3_Template,3,9,"ul",2);i0.ɵɵelementEnd()}if(2&e){var i=i0.ɵɵnextContext();i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",!i.templateRef);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",i.templateRef);i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf",i.items&&i.items.length>0)}}function IntegralUIMenuItem_hr_2_Template(e,t){if(1&e)i0.ɵɵelement(0,"hr")}var IntegralUIMenuItem=function(e){__extends(t,e);function t(t,i,n,a){var o=e.call(this,i,n)||this;o.dataService=t;o.elemRef=i;o.commonService=n;o.baseService=a;o.contentAnimation={display:"none",left:0,width:0,height:0};o.eventList=[];o.expandState="none";o.isItemHovered=!1;o.blockPos={top:0,left:0};o.popupOrder=999;o.blockDisplay="none";o.blockElemWidth="0";o.blockElemHeight="0";o.blockOverflow="hidden";o.blockOpacity=0;o.pauseTimer=null;o.parentCtrl=null;o.parentItem=null;o.pause=300;o.showAnimation=!0;return o}Object.defineProperty(t.prototype,"expanded",{get:function(){return this.isExpanded},set:function(e){if(this.isExpanded!=e&&this.isEnabled){if(e)this.expandState="expand";else this.expandState="collapse";this.isExpanded=e;this.toggleContent()}},enumerable:!0,configurable:!0});t.prototype.ngOnInit=function(){this.parentCtrl=this.baseService.getComponent();this.dataService.init([{data:this.items}]);this.isExpanded=this.data&&void 0!=this.data.expanded?this.data.expanded:!1;this.blockElemHeight="0";this.generalClassName=this.data&&!this.data.pid?"iui-menuitem-root":"iui-menuitem";this.blockClassName="iui-menuitem-block";this.contentClassName=this.generalClassName+"-content";this.expandBoxClassName="iui-menu-marker-expand";this.expandBoxSpaceClassName=this.expandBoxClassName+"-space";this.separatorClassName=this.generalClassName+"-separator";this.initStyle();this.enabled=this.data&&0!=this.data.enabled?!0:!1};t.prototype.initStyle=function(){this.defaultStyle={general:{disabled:this.generalClassName+"-disabled",focused:this.generalClassName+"-focused",normal:this.generalClassName,hovered:this.generalClassName+"-hovered",selected:this.generalClassName+"-selected"},expandBox:{general:this.expandBoxClassName,animated:this.expandBoxClassName+"-load",expanded:this.expandBoxClassName+"-open",collapsed:this.expandBoxClassName+"-close"},content:{disabled:this.contentClassName+"-disabled",focused:this.contentClassName+"-focused",normal:this.contentClassName,hovered:this.contentClassName+"-hovered",selected:this.contentClassName+"-selected"},separator:this.separatorClassName};this.updateStyle(this.controlStyle);this.updateControlClass()};t.prototype.ngOnDestroy=function(){};t.prototype.ngAfterContentInit=function(){this.updateLayout()};t.prototype.collapse=function(){this.expanded=!1};t.prototype.expand=function(){this.expanded=!0};t.prototype.toggle=function(){this.expanded=!this.expanded};t.prototype.onExpandBoxMouseDown=function(e){if(this.isEnabled)this.toggle()};t.prototype.getDataType=function(){return this.data&&this.data.type?this.data.type:"item"};t.prototype.getItemLevel=function(){return void 0!=this.level?this.level+1:0};t.prototype.isThereChildren=function(){return this.items&&this.items.length>0};t.prototype.isBlockVisible=function(){return this.isItemHovered&&this.isThereChildren()};t.prototype.updateLayout=function(){var e=this,t=setTimeout(function(){if(e.data)if(e.data.pid||"vertical"==e.orientation){if(e.elemRef.nativeElement.parentElement)e.blockPos={top:e.level>0?-2:-1,left:e.elemRef.nativeElement.parentElement.offsetWidth-3}}else if(e.elemRef.nativeElement.parentElement)e.blockPos={top:e.elemRef.nativeElement.parentElement.offsetHeight-8,left:-1};clearTimeout(t)},1)};t.prototype.onMouseEnter=function(e){if(this.isEnabled){this.state|=integralui_core_1.IntegralUIObjectState.hovered;this.isItemHovered=!0;this.updateLayout();this.expand();this.mouseEnter.emit(e)}e.stopPropagation()};t.prototype.onMouseLeave=function(e){if(this.isEnabled){this.state&=~integralui_core_1.IntegralUIObjectState.hovered;this.removePauseTimer();this.isItemHovered=!1;this.collapse();this.mouseLeave.emit(e)}e.stopPropagation()};t.prototype.onMouseUp=function(e){if(this.isEnabled){if(1==e.which&&this.parentCtrl)this.parentCtrl.invokeMethod("ITEM_CLICK",{event:e,cmp:this,item:this.data});this.mouseUp.emit(e)}e.stopPropagation()};t.prototype.onContextMenu=function(e){e.preventDefault();e.stopPropagation()};t.prototype.onChildItemMouseDown=function(e){this.collapse()};t.prototype.removePauseTimer=function(){if(this.pauseTimer)clearTimeout(this.pauseTimer)};t.prototype.toggleContent=function(){var e=this;if(e.items){var t=e.elemRef.nativeElement.firstElementChild.offsetHeight/2*e.items.length,i=0,n=0;if(e.showAnimation)if(e.expanded){e.removePauseTimer();e.pauseTimer=setTimeout(function(){if(e.pauseTimer){e.blockDisplay="block";var a=setInterval(function(){if(i<t){i+=n=0==n?1:n+2;e.blockElemHeight=i+"px";e.blockOpacity=i/t}else{e.blockElemHeight="auto";e.blockOverflow="visible";e.blockOpacity=1;e.expandState="none";clearInterval(a)}},25)}e.removePauseTimer()},300)}else{e.blockOverflow="hidden";if(e.blockElem)i=e.blockElem.nativeElement.offsetHeight;var a=setInterval(function(){if(i>0){i-=n=0==n?1:n+2;e.blockElemHeight=i+"px";e.blockOpacity=i/t}else{e.blockDisplay="none";e.blockElemHeight="0";e.blockOpacity=0;e.expandState="none";clearInterval(a)}},25)}else if(e.expanded){e.removePauseTimer();e.pauseTimer=setTimeout(function(){if(e.pauseTimer){e.blockDisplay="block";e.blockElemHeight="auto";e.blockOverflow="visible";e.blockOpacity=1;e.expandState="none"}e.removePauseTimer()},300)}else{e.blockOverflow="hidden";e.blockDisplay="none";e.blockElemHeight="0";e.blockOpacity=0;e.expandState="none"}}};t.prototype.getControlStyle=function(){var e={};if(this.data)e=this.data.style||{};e.display=this.getItemDisplay();return e};t.prototype.getItemDisplay=function(){var e="block";if(void 0!=this.data.pid)e=this.orientation?"vertical"==this.orientation?"block":"inline-block":"block";else e=this.orientation?"vertical"==this.orientation?"block":"inline-block":"inline-block";return e};t.prototype.updateControlClass=function(){this.ctrlClass.length=0;this.ctrlClass.push(this.generalClassName);if("separator"==this.getDataType())this.ctrlClass.push(this.getSeparatorClass());else if(this.options.currentStyle){this.ctrlClass.push(this.options.currentStyle.general.normal);if(this.state&integralui_core_1.IntegralUIObjectState.disabled)this.ctrlClass.push(this.options.currentStyle.general.disabled);else if(this.state&integralui_core_1.IntegralUIObjectState.focused)this.ctrlClass.push(this.options.currentStyle.general.focused);else if(this.state&integralui_core_1.IntegralUIObjectState.selected)this.ctrlClass.push(this.options.currentStyle.general.selected);else if(this.state&integralui_core_1.IntegralUIObjectState.hovered)this.ctrlClass.push(this.options.currentStyle.general.hovered);if(this.isThereChildren()){var e=this.getExpandBoxClass();if(this.data.pid||"vertical"==this.orientation)e+="-right";else e+="-down";this.ctrlClass.push(e);this.ctrlClass.push(this.getExpandBoxSpaceClass())}}};t.prototype.getExpandBoxSpaceClass=function(){var e="";if(this.isThereChildren())e=this.expandBoxSpaceClassName;return e};t.prototype.getSeparatorClass=function(){return this.options.currentStyle?this.options.currentStyle.separator:this.defaultStyle.separator};t.prototype.getBlockClass=function(){var e=this.blockClassName;if(this.isThereChildren())if(0!=this.expanded)e+=" "+this.blockClassName+"-open";else e+=" "+this.blockClassName+"-close";return e};t.prototype.getGeneralClass=function(){return this.generalClassName};t.prototype.getExpandBoxClass=function(){var e="";if(this.isThereChildren())e+=" "+this.options.currentStyle.expandBox.general;return e};t.prototype.getExpandBoxStyle=function(e){if(this.commonService.isString(e))return e;else if(e)return{general:this.commonService.isFieldAvailable(e.general,this.expandBoxClassName),animated:this.commonService.isFieldAvailable(e.animated,this.expandBoxClassName+"-load"),expanded:this.commonService.isFieldAvailable(e.expanded,this.expandBoxClassName+"-open"),collapsed:this.commonService.isFieldAvailable(e.collapsed,this.expandBoxClassName+"-close")};else return{general:this.defaultStyle.expandBox.general,animated:this.defaultStyle.expandBox.animated,expanded:this.defaultStyle.expandBox.expanded,collapsed:this.defaultStyle.expandBox.collapsed}};t.prototype.updateStyle=function(e){if(e)this.options.currentStyle={content:this.getContentStyle(e.content),expandBox:this.getExpandBoxStyle(e.expandBox),general:this.getGeneralStyle(e.general),separator:this.commonService.isFieldAvailable(e.separator,this.separatorClassName)};else this.options.currentStyle={content:{disabled:this.defaultStyle.content.disabled,focused:this.defaultStyle.content.focused,hovered:this.defaultStyle.content.hovered,normal:this.defaultStyle.content.normal,selected:this.defaultStyle.content.selected},expandBox:{general:this.defaultStyle.expandBox.general,animated:this.defaultStyle.expandBox.animated,expanded:this.defaultStyle.expandBox.expanded,collapsed:this.defaultStyle.expandBox.collapsed},general:{disabled:this.defaultStyle.general.disabled,focused:this.defaultStyle.general.focused,hovered:this.defaultStyle.general.hovered,normal:this.defaultStyle.general.normal,selected:this.defaultStyle.general.selected},separator:this.defaultStyle.separator}};t.ɵfac=function(e){return new(e||t)(i0.ɵɵdirectiveInject(i1.IntegralUIDataService),i0.ɵɵdirectiveInject(i0.ElementRef),i0.ɵɵdirectiveInject(i2.IntegralUICommonService),i0.ɵɵdirectiveInject(i3.IntegralUIBaseService))};t.ɵcmp=i0.ɵɵdefineComponent({type:t,selectors:[["iui-menuitem"]],contentQueries:function(e,i,n){if(1&e)i0.ɵɵcontentQuery(n,t,!0);if(2&e){var a;i0.ɵɵqueryRefresh(a=i0.ɵɵloadQuery())&&(i.contentList=a)}},viewQuery:function(e,t){if(1&e){i0.ɵɵviewQuery(_c0,!0,core_1.ElementRef);i0.ɵɵviewQuery(_c1,!0,core_1.ElementRef)}if(2&e){var i;i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.blockElem=i.first);i0.ɵɵqueryRefresh(i=i0.ɵɵloadQuery())&&(t.contentElem=i.first)}},inputs:{controlStyle:"controlStyle",data:"data",enabled:"enabled",icon:"icon",name:"name",state:"state",text:"text",iconUrl:"iconUrl",items:"items",level:"level",orientation:"orientation",pause:"pause",showAnimation:"showAnimation",templateRef:"templateRef",expanded:"expanded"},outputs:{click:"click",mouseDown:"mouseDown",mouseEnter:"mouseEnter",mouseLeave:"mouseLeave",mouseMove:"mouseMove",mouseUp:"mouseUp"},features:[i0.ɵɵProvidersFeature([integralui_data_service_1.IntegralUIDataService]),i0.ɵɵInheritDefinitionFeature],decls:3,vars:4,consts:[[3,"ngClass","ngStyle","click","mousedown","mouseup","mouseenter","mousemove","mouseleave","contextmenu"],[4,"ngIf"],["class","iui-menuitem-block",3,"ngStyle",4,"ngIf"],["content",""],["class","iui-item-icon",3,"ngClass","display",4,"ngIf"],["class","iui-item-icon-url",3,"src",4,"ngIf"],["class","iui-item-label",4,"ngIf"],[1,"iui-item-icon",3,"ngClass"],[1,"iui-item-icon-url",3,"src"],[1,"iui-item-label"],[3,"iuiTemplateOutlet","iuiTemplateOutletContext"],[1,"iui-menuitem-block",3,"ngStyle"],["block",""],[3,"data","items","enabled","icon","iconUrl","text","level","templateRef","showAnimation","mouseDown",4,"ngFor","ngForOf"],[3,"data","items","enabled","icon","iconUrl","text","level","templateRef","showAnimation","mouseDown"]],template:function(e,t){if(1&e){i0.ɵɵelementStart(0,"li",0);i0.ɵɵlistener("click",function(e){return t.onClick(e)})("mousedown",function(e){return t.onMouseDown(e)})("mouseup",function(e){return t.onMouseUp(e)})("mouseenter",function(e){return t.onMouseEnter(e)})("mousemove",function(e){return t.onMouseMove(e)})("mouseleave",function(e){return t.onMouseLeave(e)})("contextmenu",function(e){return t.onContextMenu(e)});i0.ɵɵtemplate(1,IntegralUIMenuItem_div_1_Template,4,3,"div",1);i0.ɵɵtemplate(2,IntegralUIMenuItem_hr_2_Template,1,0,"hr",1);i0.ɵɵelementEnd()}if(2&e){i0.ɵɵproperty("ngClass",t.getControlClass())("ngStyle",t.getControlStyle());i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf","item"==t.getDataType());i0.ɵɵadvance(1);i0.ɵɵproperty("ngIf","separator"==t.getDataType())}},directives:[i4.NgClass,i4.NgStyle,i4.NgIf,i3.IntegralUITemplateOutlet,i4.NgForOf,t],encapsulation:2});return t}(integralui_core_1.IntegralUIItem);exports.IntegralUIMenuItem=IntegralUIMenuItem;