text: /**
   * @license
   * Copyright (c) 2014, 2019, Oracle and/or its affiliates.
   * The Universal Permissive License (UPL), Version 1.0
   */
  define(["ojs/ojcore","jquery","hammerjs","ojs/ojlogger","ojs/ojcontext","ojs/ojjquery-hammer","ojs/ojcomponentcore","ojs/ojpopup"],function(e,t,i,n,o){"use strict";var s={properties:{for:{type:"string"},help:{type:"object",value:{definition:null,source:null},properties:{definition:{type:"string"},source:{type:"string"}}},labelId:{type:"string"},showRequired:{type:"boolean",value:!1},translations:{type:"object",value:{},properties:{tooltipHelp:{type:"string"},tooltipRequired:{type:"string"}}}},methods:{refresh:{},setProperty:{},getProperty:{},setProperties:{},getNodeBySubId:{},getSubIdByNode:{}},extension:{}};e.__registerWidget("oj.ojLabel",t.oj.baseComponent,{version:"1.0.0",defaultElement:"<label>",widgetEventPrefix:"oj",options:{for:null,help:{definition:null,source:null},labelId:null,showRequired:!1,rootAttributes:null},_BUNDLE_KEY:{_TOOLTIP_HELP:"tooltipHelp",_TOOLTIP_REQUIRED:"tooltipRequired"},widget:function(){return this.uiLabel},refresh:function(){this._super(),this._refreshRequired(),this._refreshHelp(),this._addIdsToDom()},_InitOptions:function(e,t){this._super(e,t),this._isCustomElement=this._IsCustomElement(),this._checkRequiredOption()},_ComponentCreate:function(){this._super(),this._touchEatClickNamespace=this.eventNamespace+"TouchEatClick",this._touchEatContextMenuNamespace=this.eventNamespace+"TouchEatContextMenu",this._helpDefPopupNamespace=this.eventNamespace+"HelpDefPopup",this._bTouchSupported=e.DomUtils.isTouchSupported(),this._drawOnCreate()},_AfterCreate:function(){var e,t,i,s=this,r=this.options.for,l=this.options.showRequired;if(this.OuterWrapper&&(e=this.OuterWrapper.getAttribute("data-oj-input-id"),t=this.OuterWrapper.getAttribute("data-oj-set-id")),e?this.element[0].setAttribute("for",e):t&&(this._targetElement=document.getElementById(t),i=this._targetElement,this._needsHelpIcon()&&s._addHelpSpanIdOnTarget(s.helpSpanId,i),s.options.showRequired&&s._addRequiredDescribedByOnCustomFormElement(i)),r&&this._isCustomElement){var a=o.getContext(this.OuterWrapper).getBusyContext().addBusyState({description:"The oj-label id='"+this.OuterWrapper.id+"' is looking for its form component with id "+r});setTimeout(function(){if(s._targetElement=document.getElementById(r),s._targetElement){if(i=s._targetElement,s._needsHelpIcon()&&s._addHelpSpanIdOnTarget(s.helpSpanId,i),l&&s._addRequiredDescribedByOnCustomFormElement(i),!e)if(s._isElementCustomElement(i)){var t=s.OuterWrapper.id;s._addElementAttribute(i,t,"labelled-by")}else s.element[0].setAttribute("for",r)}else n.info("could not find an element with forOption "+r);a()},0)}else this._isCustomElement&&this.options.labelId&&(this._targetElement=this._getTargetElementFromLabelledAttr("aria-labelledby",this.options.labelId),(i=this._targetElement)&&this._needsHelpIcon()&&this._addHelpSpanIdOnTarget(this.helpSpanId,i))},_SaveAttributes:function(e){this._IsCustomElement()||(this._savedClasses=e.attr("class"))},_RestoreAttributes:function(){this._IsCustomElement()||(this._savedClasses?this.element.attr("class",this._savedClasses):this.element.removeAttr("class"))},_NotifyDetached:function(){this._superApply(arguments),this._handleCloseHelpDefPopup()},_NotifyHidden:function(){this._superApply(arguments),this._handleCloseHelpDefPopup()},_GetTranslationsSectionName:function(){return this._IsCustomElement(),"oj-ojLabel"},_WatchedAttributeChanged:function(e,t,i){switch(this._superApply(arguments),e){case"data-oj-input-id":this.element[0].setAttribute("for",i);break;case"data-oj-set-id":this._targetElement=document.getElementById(i);var n=this._targetElement,s=this._needsHelpIcon(),r=this.options.showRequired;if(s||r){var l=o.getContext(this.OuterWrapper).getBusyContext().addBusyState({description:"The oj-label is writing described-by on its target."}),a=this;setTimeout(function(){s&&a._addHelpSpanIdOnTarget(a.helpSpanId,n),a.options.showRequired&&a._addRequiredDescribedByOnCustomFormElement(n),l()},0)}}},_drawOnCreate:function(){var e,i=null;this.OuterWrapper?(this.uiLabel=t(this.OuterWrapper).append(this.element.wrap(this._createOjLabelGroupDom()).parent()),this.uiLabel.addClass("oj-label oj-component")):this.uiLabel=this.element.wrap(this._createRootDomElement()).closest(".oj-component"),this._addIdsToDom(),e=this.element[0].id,this.helpSpanId=e+"_helpIcon",this.requiredSpanId=e+"_requiredIcon",this._isCustomElement||this._moveLabelStyleClassesToRootDom(),this.options.showRequired&&this._createRequiredIconSpanDom(),this._needsHelpIcon()&&(i=this._createIconSpan(this.helpSpanId,!0),this._createHelp(i))},_addRequiredDescribedByOnCustomFormElement:function(e){e&&this._isElementCustomElementAriaRequiredUnsupported(e)&&this._addElementAttribute(e,this.requiredSpanId,"described-by")},_removeRequiredDescribedByOnCustomFormElement:function(e){e&&this._isElementCustomElementAriaRequiredUnsupported(e)&&this._removeElementAttribute(e,this.requiredSpanId,"described-by")},_addHelpSpanIdOnTarget:function(e,t){var i;i=this._getAriaAttributeForTarget(t),this._addElementAttribute(t,e,i)},_removeHelpSpanIdOnTarget:function(e,t){var i;i=this._getAriaAttributeForTarget(t),this._removeElementAttribute(t,e,i)},_getAriaAttributeForTarget:function(e){return this._isElementCustomElement(e)?"described-by":"group"===e.getAttribute("role")?"aria-labelledby":"aria-describedby"},_getTargetElementFromLabelledAttr:function(e,t){var i;return i="["+e+"~='"+t+"']",document.querySelector(i)},_isElementCustomElement:function(t){return e.Assert.assertDomElement(t),-1!==t.tagName.indexOf("-")},_isElementCustomElementAriaRequiredUnsupported:function(t){var i;e.Assert.assertDomElement(t);var n,o=["oj-radioset","oj-checkboxset"],s=o.length,r=!1;n=t.tagName.toLowerCase();for(var l=0;l<s&&!r;l++)i=o[l],0===n.indexOf(i)&&(r=!0);return r},_addElementAttribute:function(e,t,i){var n,o,s=e.getAttribute(i);-1===(o=s?s.split(/\s+/):[]).indexOf(t)&&o.push(t),n=o.join(" ").trim(),e.setAttribute(i,n)},_removeElementAttribute:function(e,t,i){var n,o,s,r=e.getAttribute(i);-1!==(o=(s=r?r.split(/\s+/):[]).indexOf(t))&&s.splice(o,1),(n=s.join(" ").trim())?e.setAttribute(i,n):e.setAttribute(i,"")},_createHelp:function(e){var i=this.options.help.definition,n=this.options.help.source,o=this._createHelpIconAnchorDomElement(i,n);t(e).prepend(o),this._attachHelpDefToIconAnchor(),this._focusable({element:o,applyHighlight:!0})},_createRequiredIconSpanDom:function(){this._createIconSpan(this.requiredSpanId,!1).appendChild(this._createRequiredIconDomElement())},_checkRequiredOption:function(){var e=this.options.showRequired;if("boolean"!=typeof e)throw new Error("Option 'showRequired' has invalid value set: "+e)},_addIdsToDom:function(){this._isCustomElement&&(this.OuterWrapper.id||t(this.OuterWrapper).uniqueId(),this._refreshLabelId()),null==this.element.attr("id")&&this.element.uniqueId()},_moveLabelStyleClassesToRootDom:function(){var e,t,i,n=this.element.attr("class");if(n){i=(e=n.split(/\s+/)).length;for(var o=0;o<i;o++)(t=e[o]).indexOf("-label")>0&&(this.uiLabel.addClass(t),this.element.removeClass(t))}},_createIconSpan:function(e,t){var i=document.createElement("span");return i.setAttribute("id",e),t?this.uiLabel.find(".oj-label-group").prepend(i):this.element.before(i),i},_createRootDomElement:function(){var e,t,i=this.options.rootAttributes,n="oj-label oj-component";return i&&(e=i.class),e&&(n=n+" "+e),(t=document.createElement("div")).className=n,t.appendChild(this._createOjLabelGroupDom()),t},_createOjLabelGroupDom:function(){var e;return(e=document.createElement("div")).className="oj-label-group",e},_createRequiredIconDomElement:function(){var e=this.getTranslatedString(this._BUNDLE_KEY._TOOLTIP_REQUIRED),t=document.createElement("span");return t.className="oj-label-required-icon oj-component-icon",t.setAttribute("role","img"),t.setAttribute("title",e),t.setAttribute("aria-label",e),t},_createHelpIconAnchorDomElement:function(t,i){var n;if((n=document.createElement("a")).setAttribute("tabindex","0"),n.setAttribute("target","_blank"),n.className="oj-label-help-icon-anchor oj-label-help-icon oj-component-icon oj-clickable-icon-nocontext",i)try{e.DomUtils.validateURL(i),n.setAttribute("href",i)}catch(e){throw new Error(e+". The source option ("+i+") is invalid.")}else n.setAttribute("role","img");return t?n.setAttribute("aria-label",t):n.setAttribute("aria-label",this.getTranslatedString(this._BUNDLE_KEY._TOOLTIP_HELP)),n},_attachHelpDefToIconAnchor:function(){var e,t,i,n=this;0!==(t=this.widget().find(".oj-label-help-icon-anchor")).length&&(this._bTouchSupported&&(this._eatClickOnHelpIconListener&&this.widget().off(this._touchEatClickNamespace),this._eatClickOnHelpIconListener=function(){return!1},t.on("contextmenu"+this._touchEatContextMenuNamespace,!1)),this._openPopupForHelpDefCallbackListener=function(o){null==e&&(e=n._createHelpDefPopupDiv(),i={my:"start bottom",at:"end top",collision:"flipcenter",of:t},e.ojPopup({position:i,modality:"modeless",animation:{open:null,close:null}})),n._handleOpenHelpDefPopup(o,e,t)},this._closePopupForHelpDefCallbackListener=function(){n._handleCloseHelpDefPopup()},this._addShowHelpDefinitionEventHandlers(t))},_createHelpDefPopupDiv:function(){var e,i,n,o,s=this.options.help.definition;return o=s||this.getTranslatedString(this._BUNDLE_KEY._TOOLTIP_HELP),this._helpDefPopupDivId?(n=t(document.getElementById(this._helpDefPopupDivId))).length&&n.find(".oj-help-popup-container").first().text(o):((i=document.createElement("div")).className="oj-help-popup",i.style.display="none",(n=t(i)).uniqueId(),this._helpDefPopupDivId=n.prop("id"),(e=document.createElement("div")).className="oj-help-popup-container",i.appendChild(e),t(e).text(o),document.getElementsByTagName("body")[0].appendChild(i)),n},_addShowHelpDefinitionEventHandlers:function(t){var n;t.on("focusin"+this._helpDefPopupNamespace+" mouseenter"+this._helpDefPopupNamespace,this._openPopupForHelpDefCallbackListener),t.on("mouseleave"+this._helpDefPopupNamespace,this._closePopupForHelpDefCallbackListener),this._bTouchSupported&&(this.options.help.source?(n={recognizers:[[i.Press,{time:e.DomUtils.PRESS_HOLD_THRESHOLD}]]},t.ojHammer(n),this._on(t,{press:this._openPopupForHelpDefCallbackListener})):(n={recognizers:[[i.Tap],[i.Press,{time:e.DomUtils.PRESS_HOLD_THRESHOLD}]]},t.ojHammer(n),this._on(t,{press:this._openPopupForHelpDefCallbackListener,tap:this._openPopupForHelpDefCallbackListener})))},_handleOpenHelpDefPopup:function(t,i,n){if(!i.ojPopup("isOpen"))if(this._bTouchSupported){if("press"===t.type){var o=this.widget();o.on("click"+this._touchEatClickNamespace,this._eatClickOnHelpIconListener);var s=this;i.on("ojclose",function(){o.off(s._touchEatClickNamespace)})}else i.off("ojclose");"press"!==t.type&&"tap"!==t.type&&(e.DomUtils.recentTouchStart()||"focusin"!==t.type&&"mouseenter"!==t.type)||i.ojPopup("open",n)}else i.ojPopup("open",n)},_handleCloseHelpDefPopup:function(){null!=this._helpDefPopupDivId&&t(document.getElementById(this._helpDefPopupDivId)).ojPopup("close")},_removeHelpDefIconEventListeners:function(e){this._bTouchSupported&&(this.widget().off(this._touchEatClickNamespace),e.off(this._touchEatContextMenuNamespace),this._eatClickOnHelpIconListener=null,this._eatContextMenuOnHelpIconListener=null,e.ojHammer("destroy")),e.off(this._helpDefPopupNamespace),this._openPopupForHelpDefCallbackListener=null,this._closePopupForHelpDefCallbackListener=null},_removeHelpDefPopup:function(){var e;null!=this._helpDefPopupDivId&&((e=t(document.getElementById(this._helpDefPopupDivId)))&&(e.ojPopup("destroy"),e.remove()),this._helpDefPopupDivId=null)},_needsHelpIcon:function(){var e,t,i=this.options,n=i.help.source;return(t=""!==n&&null!=n)||(t=""!==(e=i.help.definition)&&null!=e),t},_refreshHelp:function(){var e,t,i=this.helpSpanId,n=this._targetElement;1===(t=this.uiLabel.find(".oj-label-help-icon")).length&&(this._removeHelpDefIconEventListeners(t),this._removeHelpDefPopup(),t.remove()),e=document.getElementById(i),this._needsHelpIcon()?(null==e&&(e=this._createIconSpan(i,!0)),this._createHelp(e),this._isCustomElement&&this._addHelpSpanIdOnTarget(i,n)):null!==e&&(e.parentNode.removeChild(e),this._isCustomElement&&this._removeHelpSpanIdOnTarget(i,n))},_refreshRequired:function(){var e,t,i=this.requiredSpanId;e=document.getElementById(i),this.options.showRequired?e?(t=this.getTranslatedString(this._BUNDLE_KEY._TOOLTIP_REQUIRED),this.uiLabel.find(".oj-label-required-icon").attr("title",t)):(this._createRequiredIconSpanDom(),this._isCustomElement&&this._addRequiredDescribedByOnCustomFormElement(this._targetElement)):(null!==(e=document.getElementById(i))&&e.parentNode.removeChild(e),this._isCustomElement&&this._removeRequiredDescribedByOnCustomFormElement(this._targetElement))},_refreshFor:function(e,t){var i=this.element[0],n=this.OuterWrapper.id;if(e){i.removeAttribute("for"),this.OuterWrapper.removeAttribute("data-oj-input-id");var o=document.getElementById(e);if(o){var s=o.getAttribute("labelled-by");if(s)if(s===n)o.removeAttribute("labelled-by");else{var r=s.split(/\s+/).filter(function(e){return e!==n}).join(" ");o.setAttribute("labelled-by",r)}}}if(this._targetElement=document.getElementById(this.options.for),this._targetElement){var l=this._targetElement;this._isElementCustomElement(l)?(this._addElementAttribute(l,n,"labelled-by"),this._needsHelpIcon()&&this._addHelpSpanIdOnTarget(this.helpSpanId,l),this.options.showRequired&&this._addRequiredDescribedByOnCustomFormElement(l)):i.setAttribute("for",t)}},_refreshLabelId:function(){var e,t;(e=this.options.labelId)?this.element.attr("id",e):(t=this.uiLabel.attr("id"))&&this.element.attr("id",t+"|label")},_setOption:function(e,t){var i=this.options[e];switch(this._superApply(arguments),e){case"showRequired":this._refreshRequired();break;case"help":this._refreshHelp();break;case"for":this._isCustomElement&&this._refreshFor(i,t);break;case"labelId":this._refreshLabelId()}},getNodeBySubId:function(e){var t;return(t=this._super(e))||"oj-label-help-icon"===e.subId&&(t=this.widget().find(".oj-label-help-icon")[0]),t||null},getSubIdByNode:function(e){var t=null;return null!=e&&e===this.widget().find(".oj-label-help-icon")[0]&&(t={subId:"oj-label-help-icon"}),t||this._superApply(arguments)},_destroy:function(){var t=this.uiLabel.find(".oj-label-help-icon");return this._removeHelpDefIconEventListeners(t),this._removeHelpDefPopup(),this.helpSpanId=null,this.requiredSpanId=null,this._isCustomElement=null,e.DomUtils.unwrap(this.element,this.uiLabel),this._super()}}),s.extension._WIDGET_NAME="ojLabel",s.extension._INNER_ELEM="label",s.extension._GLOBAL_TRANSFER_ATTRS=["accesskey"],s.extension._WATCHED_ATTRS=["data-oj-input-id","data-oj-set-id"],e.CustomElementBridge.register("oj-label",{metadata:s})});