/*! * UI development toolkit for HTML5 (OpenUI5) * (c) Copyright 2009-2018 SAP SE or an SAP affiliate company. * Licensed under the Apache License, Version 2.0 - see LICENSE.txt. */ sap.ui.define(['./library','sap/ui/core/Control','sap/ui/core/theming/Parameters','./RatingIndicatorRenderer',"sap/ui/events/KeyCodes","sap/base/Log","sap/ui/thirdparty/jquery"],function(l,C,P,R,K,L,q){"use strict";var a=l.RatingIndicatorVisualMode;var b=C.extend("sap.m.RatingIndicator",{metadata:{interfaces:["sap.ui.core.IFormContent"],library:"sap.m",properties:{enabled:{type:"boolean",group:"Behavior",defaultValue:true},maxValue:{type:"int",group:"Behavior",defaultValue:5},value:{type:"float",group:"Behavior",defaultValue:0,bindable:"bindable"},iconSize:{type:"sap.ui.core.CSSSize",group:"Behavior",defaultValue:null},iconSelected:{type:"sap.ui.core.URI",group:"Behavior",defaultValue:null},iconUnselected:{type:"sap.ui.core.URI",group:"Behavior",defaultValue:null},iconHovered:{type:"sap.ui.core.URI",group:"Behavior",defaultValue:null},visualMode:{type:"sap.m.RatingIndicatorVisualMode",group:"Behavior",defaultValue:a.Half},displayOnly:{type:"boolean",group:"Behavior",defaultValue:false},editable:{type:"boolean",group:"Behavior",defaultValue:true}},associations:{ariaDescribedBy:{type:"sap.ui.core.Control",multiple:true,singularName:"ariaDescribedBy"},ariaLabelledBy:{type:"sap.ui.core.Control",multiple:true,singularName:"ariaLabelledBy"}},events:{change:{parameters:{value:{type:"int"}}},liveChange:{parameters:{value:{type:"float"}}}},designtime:"sap/m/designtime/RatingIndicator.designtime"}});b.prototype.init=function(){this.allowTextSelection(false);this._iIconCounter=0;this._fHoverValue=0;this._oResourceBundle=sap.ui.getCore().getLibraryResourceBundle('sap.m');};b.prototype.setValue=function(v){v=this.validateProperty("value",v);if(v<0){return this;}if(isNaN(v)){L.warning('Ignored new rating value "'+v+'" because it is NAN');}else if(this.$().length&&(v>this.getMaxValue())){L.warning('Ignored new rating value "'+v+'" because it is out of range (0-'+this.getMaxValue()+')');}else{v=this._roundValueToVisualMode(v);this.setProperty("value",v,true);this._fHoverValue=v;if(this.$().length){this._updateUI(v);}}return this;};b.prototype.setIconSize=function(i){if(this.$().length){this._iPxIconSize=this._toPx(i)||16;}this.setProperty("iconSize",i,false);return this;};b.prototype.onThemeChanged=function(e){this.invalidate();};b.prototype.onBeforeRendering=function(){var v=this.getValue(),m=this.getMaxValue(),i;if(v>m){this.setValue(m);L.warning("Set value to maxValue because value is > maxValue ("+v+" > "+m+").");}else if(v<0){this.setValue(0);L.warning("Set value to 0 because value is < 0 ("+v+" < 0).");}if(this.getIconSize()){this._iPxIconSize=this._toPx(this.getIconSize());i="sapUiRIIconPadding"+this._getIconSizeLabel(this._iPxIconSize);this._iPxPaddingSize=this._toPx(P.get(i));}else{if(this.getDisplayOnly()){this._iPxIconSize=this._toPx(P.get("sapUiRIIconSizeDisplayOnly"));this._iPxPaddingSize=this._toPx(P.get("sapUiRIIconPaddingDisplayOnly"));}else{var d=this._getDensityMode();this._iPxIconSize=this._toPx(P.get("sapUiRIIconSize"+d));this._iPxPaddingSize=this._toPx(P.get("sapUiRIIconPadding"+d));}}};b.prototype.onAfterRendering=function(){this._updateAriaValues();};b.prototype.exit=function(){this._iIconCounter=null;this._fStartValue=null;this._iPxIconSize=null;this._iPxPaddingSize=null;this._fHoverValue=null;this._oResourceBundle=null;};b.prototype._getDensityMode=function(){var d=[{name:"Cozy",style:"sapUiSizeCozy"},{name:"Compact",style:"sapUiSizeCompact"},{name:"Condensed",style:"sapUiSizeCondensed"}],D,s,i;for(i in d){D=d[i].style;if(q("html").hasClass(D)||q("."+D).length>0){s=d[i].name;}}return s||d[0].name;};b.prototype._getIconSizeLabel=function(p){switch(true){case(p>=32):return"L";case(this._iPxIconSize>=22):return"M";case(this._iPxIconSize>=16):return"S";case(this._iPxIconSize>=12):return"XS";default:return"M";}};b.prototype._toPx=function(c){var s=Math.round(c),d;if(isNaN(s)){if(RegExp("^(auto|0)$|^[+-]?[0-9].?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)$").test(c)){d=q('
').appendTo(sap.ui.getCore().getStaticAreaRef());s=d.width();d.remove();}else{return false;}}return Math.round(s);};b.prototype._updateUI=function(v,h){var s=this.$("sel"),u=this.$("unsel-wrapper"),H=this.$("hov"),i=this._iPxIconSize,I=this._iPxPaddingSize,c="px",S=this.getMaxValue(),d=v*i+(Math.round(v)-1)*I,w=S*(i+I)-I;this._fHoverValue=v;if(d<0){d=0;}this._updateAriaValues(v);u.width((w-d)+c);if(h){H.width(d+c);s.hide();H.show();}else{s.width(d+c);H.hide();s.show();}L.debug("Updated rating UI with value "+v+" and hover mode "+h);};b.prototype._updateAriaValues=function(n){var $=this.$();var v;if(n===undefined){v=this.getValue();}else{v=n;}var m=this.getMaxValue();$.attr("aria-valuenow",v);$.attr("aria-valuemax",m);var V=this._oResourceBundle.getText("RATING_VALUEARIATEXT",[v,m]);$.attr("aria-valuetext",V);};b.prototype._calculateSelectedValue=function(e){var s=-1.0,p=0.0,c=this.$(),f=(c.innerWidth()-c.width())/2,E,r=sap.ui.getCore().getConfiguration().getRTL();if(e.targetTouches){E=e.targetTouches[0];}else{E=e;}if(!E||!E.pageX){E=e;if((!E||!E.pageX)&&e.changedTouches){E=e.changedTouches[0];}}if(!E.pageX){return parseFloat(s);}if(E.pageX