/*!
* 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/delegate/ItemNavigation','sap/ui/core/Item','./SelectListRenderer',"sap/ui/thirdparty/jquery","sap/ui/dom/jquery/control"],function(l,C,I,a,S,q){"use strict";var t=l.touch;var b=l.SelectListKeyboardNavigationMode;var c=C.extend("sap.m.SelectList",{metadata:{library:"sap.m",properties:{enabled:{type:"boolean",group:"Behavior",defaultValue:true},width:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:"auto"},maxWidth:{type:"sap.ui.core.CSSSize",group:"Dimension",defaultValue:"100%"},selectedKey:{type:"string",group:"Data",defaultValue:""},selectedItemId:{type:"string",group:"Misc",defaultValue:""},showSecondaryValues:{type:"boolean",group:"Misc",defaultValue:false},keyboardNavigationMode:{type:"sap.m.SelectListKeyboardNavigationMode",group:"Behavior",defaultValue:b.Delimited}},defaultAggregation:"items",aggregations:{items:{type:"sap.ui.core.Item",multiple:true,singularName:"item",bindable:"bindable"}},associations:{selectedItem:{type:"sap.ui.core.Item",multiple:false},ariaLabelledBy:{type:"sap.ui.core.Control",multiple:true,singularName:"ariaLabelledBy"}},events:{selectionChange:{parameters:{selectedItem:{type:"sap.ui.core.Item"}}},itemPress:{parameters:{item:{type:"sap.ui.core.Item"}}}}}});c.prototype._setSelectedIndex=function(i,_){var o;_=_||this.getItems();i=(i>_.length-1)?_.length-1:Math.max(0,i);o=_[i];if(o){this.setSelection(o);}};c.prototype.updateItems=function(r){this.bItemsUpdated=false;this.destroyItems();this.updateAggregation("items");this.bItemsUpdated=true;this.synchronizeSelection({forceSelection:false});setTimeout(this.synchronizeSelection.bind(this),0);};c.prototype.refreshItems=function(){this.bItemsUpdated=false;this.refreshAggregation("items");};c.prototype._activateItem=function(i){if(i instanceof a&&i&&i.getEnabled()){this.fireItemPress({item:i});if(this.getSelectedItem()!==i){this.setSelection(i);this.fireSelectionChange({selectedItem:i});}}};c.prototype._queryEnabledItemsDomRefs=function(d){var e="."+this.getRenderer().CSS_CLASS+"ItemBase";d=d||this.getDomRef();return d?Array.prototype.slice.call(d.querySelectorAll(e+":not("+e+"Disabled)")):[];};c.prototype._handleARIAActivedescendant=function(){var A=q(document.activeElement).control(0),d=this.getDomRef();if(A&&d){d.setAttribute("aria-activedescendant",A.getId());}};c.prototype.init=function(){this._iStartTimeout=0;this._iActiveTouchId=0;this._fStartX=0;this._fStartY=0;this._oItemNavigation=null;this._$ItemPressed=null;};c.prototype.onBeforeRendering=function(){this.synchronizeSelection();};c.prototype.onAfterRendering=function(){if(this.getKeyboardNavigationMode()===b.None){this.destroyItemNavigation();}else{this.createItemNavigation();}};c.prototype.exit=function(){this.destroyItemNavigation();this._$ItemPressed=null;};c.prototype.ontouchstart=function(e){if(t.countContained(e.touches,this.getId())>1||!this.getEnabled()){return;}e.setMarked();var T=e.targetTouches[0];this._iActiveTouchId=T.identifier;this._fStartX=T.pageX;this._fStartY=T.pageY;this._iStartTimeout=setTimeout(function(){var i=e.srcControl.$();if(i){i.addClass(this.getRenderer().CSS_CLASS+"ItemBasePressed");this._$ItemPressed=i;}}.bind(this),100);};c.prototype.ontouchmove=function(e){var T=null;if(!this.getEnabled()){return;}T=t.find(e.changedTouches,this._iActiveTouchId);if(T&&((Math.abs(T.pageX-this._fStartX)>10)||(Math.abs(T.pageY-this._fStartY)>10))){clearTimeout(this._iStartTimeout);if(this._$ItemPressed){this._$ItemPressed.removeClass(this.getRenderer().CSS_CLASS+"ItemBasePressed");this._$ItemPressed=null;}}};c.prototype.ontouchend=function(e){var T=null;if(!this.getEnabled()){return;}e.setMarked();T=t.find(e.changedTouches,this._iActiveTouchId);if(T){setTimeout(function(){if(this._$ItemPressed){this._$ItemPressed.removeClass(this.getRenderer().CSS_CLASS+"ItemBasePressed");this._$ItemPressed=null;}this._iStartTimeout=null;}.bind(this),100);}};c.prototype.ontouchcancel=c.prototype.ontouchend;c.prototype.ontap=function(e){if(this.getEnabled()){e.setMarked();this._activateItem(e.srcControl);}};c.prototype.onsapselect=function(e){if(this.getEnabled()){e.setMarked();e.preventDefault();this._activateItem(e.srcControl);}};c.prototype.onAfterFocus=function(o){this._handleARIAActivedescendant();};c.prototype.findFirstEnabledItem=function(d){d=d||this.getItems();for(var i=0;i