@atlassian/aui
Version:
Atlassian User Interface Framework
20 lines • 19.2 kB
JavaScript
/*!!
* @atlassian/aui - Atlassian User Interface Framework
* @version v8.0.0-alpha.1
* @link https://aui.atlassian.com
* @license SEE LICENSE IN LICENSE.md
* @author Atlassian Pty Ltd.
*/
exports.ids=[41],exports.modules={48:
/*!*********************************!*\
!*** ../src/js/aui/debounce.js ***!
\*********************************/
/*! no static exports found */
/*! all exports used */
/*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(e,t,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=d,t.debounceImmediate=o;var i,n=a(/*! ./internal/globalize */1),r=(i=n)&&i.__esModule?i:{default:i};function d(e,t){var a,i;return function(){var n=arguments,r=this;return clearTimeout(a),a=setTimeout(function(){i=e.apply(r,n),r=n=null},t),i}}function o(e,t){var a,i=null;return function(){var n=this,r=arguments;return null===i&&(a=e.apply(n,r)),clearTimeout(i),i=setTimeout(function(){i=n=r=null},t),a}}(0,r.default)("debounce",d),(0,r.default)("debounceImmediate",o)},72:
/*!**********************************!*\
!*** ../src/js/aui/dropdown2.js ***!
\**********************************/
/*! no static exports found */
/*! all exports used */
/*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(e,t,a){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.DropdownSubTriggerEl=t.DropdownTriggerEl=t.SectionEl=t.ItemCheckboxEl=t.ItemRadioEl=t.ItemLinkEl=t.DropdownRadioEl=t.DropdownCheckboxEl=t.DropdownEl=void 0,a(/*! ./i18n */10),a(/*! ./spinner */49);var i=m(a(/*! ./jquery */0)),n=m(a(/*! skatejs-template-html */18)),r=b(a(/*! ./internal/deprecation */9)),d=b(a(/*! ./internal/log */6)),o=a(/*! ./debounce */48),u=a(/*! ./internal/browser */47),s=m(a(/*! ./internal/alignment */32)),l=m(a(/*! ./polyfills/custom-event */19)),c=m(a(/*! ./key-code */8)),f=m(a(/*! ./layer */20)),h=m(a(/*! ./internal/state */46)),p=m(a(/*! ./internal/skate */5));function b(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t.default=e,t}function m(e){return e&&e.__esModule?e:{default:e}}function g(e){return(0,i.default)(e).is('.checked, .aui-dropdown2-checked, [aria-checked="true"]')}function v(e,t){var a,i=(a=e)._triggeringElement||document.querySelector('[aria-controls="'+a.id+'"]');i&&t(i)}function w(e,t){var a=(0,i.default)(e);t?(a.attr("aria-expanded","true"),a.addClass("active aui-dropdown2-active")):(a.attr("aria-expanded","false"),a.removeClass("active aui-dropdown2-active"))}var k="unloaded",A="loading",y="error",C="success";function E(e){(0,h.default)(e).set("loading-state",y),(0,h.default)(e).set("hasErrorBeenShown",e.isVisible()),n.default.wrap(e).innerHTML='\n <div class="aui-message aui-message-error aui-dropdown-error">\n <p>'+AJS.I18n.getText("aui.dropdown.async.error")+"</p>\n </div>\n "}function S(e){e.src&&(0,h.default)(e).get("loading-state")!==A&&(!function(e){(0,h.default)(e).set("loading-state",A),(0,h.default)(e).set("hasErrorBeenShown",!1),v(e,function(e){e.setAttribute("aria-busy","true")}),n.default.wrap(e).innerHTML='\n <div class="aui-dropdown-loading">\n <aui-spinner size="small"></aui-spinner> '+AJS.I18n.getText("aui.dropdown.async.loading")+"\n </div>\n "}(e),i.default.ajax(e.src).done(function(t,a,i){200===i.status?function(e,t){(0,h.default)(e).set("loading-state",C),n.default.wrap(e).innerHTML=function(e){return e.map(function(e){var t=e.items.map(function(e){function t(t){return e[t]?t+' ="true"':""}function a(t){return e[t]?t+'="'+e[t]+'"':""}var i="aui-item-"+e.type;return"\n <"+i+" "+a("for")+" "+a("href")+" "+t("interactive")+"\n "+t("checked")+" "+t("disabled")+" "+t("hidden")+">\n "+e.content+"\n </"+i+">"}).join("");return"\n <aui-section "+(e.label?'label="'+e.label+'"':"")+">\n "+t+"\n </aui-section>"}).join("\n")}(t),p.default.init(e)}(e,t):E(e)}).fail(function(){E(e)}).always(function(){!function(e){v(e,function(e){e.setAttribute("aria-busy","false")})}(e)}))}var x=(0,p.default)("aui-dropdown2-trigger",{type:p.default.type.CLASSNAME,created:function(e){var t=e.getAttribute("aria-controls");function a(a){if(a.preventDefault(),e.isEnabled()){var n=document.getElementById(t),r=(0,i.default)(e);return r.parent().hasClass("aui-buttons")&&n.classList.add("aui-dropdown2-in-buttons"),r.parents().hasClass("aui-header")&&n.classList.add("aui-dropdown2-in-header"),n.toggle(a),n.isSubmenu=e.hasSubmenu(),n}}t||((t=e.getAttribute("aria-owns"))?(e.removeAttribute("aria-owns"),e.setAttribute("aria-controls",t)):d.error('Dropdown triggers need either a "aria-owns" or "aria-controls" attribute')),e.setAttribute("aria-haspopup",!0),e.setAttribute("aria-expanded",!1),"A"===e.nodeName&&!e.href&&e.setAttribute("href","#"+t),(0,i.default)(e).on("aui-button-invoke",a).on("click",a).on("keydown",function(t){var i=t.keyCode===c.default.ENTER||t.keyCode===c.default.SPACE,n=t.keyCode===c.default.RIGHT&&e.hasSubmenu(),r=(t.keyCode===c.default.UP||t.keyCode===c.default.DOWN)&&!e.hasSubmenu();if(i||n||r){var d=a(t);d&&d.focusItem(0)}}).on("mouseenter",function(a){if(a.preventDefault(),e.isEnabled()){var i=document.getElementById(t);return function(e){var t=(0,h.default)(e).get("loading-state")===k,a=(0,h.default)(e).get("hasErrorBeenShown");(t||a&&!e.isVisible())&&S(e)}(i),e.hasSubmenu()&&(i.show(a),i.isSubmenu=e.hasSubmenu()),i}})},prototype:{disable:function(){this.setAttribute("aria-disabled","true")},enable:function(){this.setAttribute("aria-disabled","false")},isEnabled:function(){return"true"!==this.getAttribute("aria-disabled")},hasSubmenu:function(){return-1!==(this.className||"").split(/\s+/).indexOf("aui-dropdown2-sub-trigger")}}});(0,i.default)(document).on("mousedown",".aui-dropdown2-trigger",function(){this.hasAttribute("resolved")||(p.default.init(this),r.getMessageLogger("Dropdown2 lazy initialisation",{removeInVersion:"8.0.0",alternativeName:"initialisation on DOM insertion",sinceVersion:"5.8.0",extraInfo:"Dropdown2 triggers should have all necessary attributes on DOM insertion",deprecationType:"JS"})())});var N=(0,p.default)("aui-dropdown2-sub-trigger",{type:p.default.type.CLASSNAME,created:function(e){e.className+=" aui-dropdown2-trigger",p.default.init(e)}});function T(e,t){return(0,i.default)(e).find(["> ul > li","> .aui-dropdown2-section > ul > li",'> div[role] > .aui-dropdown2-section > div[role="group"] > ul[role] > li[role]',"aui-item-link","aui-item-checkbox","aui-item-radio"].join(", ")).filter(t).children('a, button, [role="checkbox"], [role="menuitemcheckbox"], [role="radio"], [role="menuitemradio"]')}function D(e){return T(e,function(){return-1===this.className.indexOf("hidden")&&!this.hasAttribute("hidden")})}function _(e){(function(e){return T(e,function(){return!0})})(e).each(function(){var e,t;e=this,(t=(0,i.default)(e)).attr("tabindex","-1"),(t.hasClass("aui-dropdown2-disabled")||t.parent().hasClass("aui-dropdown2-hidden"))&&t.attr("aria-disabled",!0)})}function I(e,t){var a=t&&t.hasSubmenu&&t.hasSubmenu(),n="submenu auto"===e.getAttribute("data-aui-alignment");!a&&n&&function(e){var t=(0,i.default)(e),a=t.data("previous-data-aui-alignment");a?e.setAttribute("data-aui-alignment",a):e.removeAttribute("data-aui-alignment");t.removeData("previous-data-aui-alignment"),t.data("had-data-aui-alignment-static")||e.removeAttribute("data-aui-alignment-static");t.removeData("had-data-aui-alignment-static")}(e);var r=e.hasAttribute("data-aui-alignment");a&&!n?(!function(e){var t=(0,i.default)(e);e.hasAttribute("data-aui-alignment")&&t.data("previous-data-aui-alignment",e.getAttribute("data-aui-alignment"));t.data("had-data-aui-alignment-static",e.hasAttribute("data-aui-alignment-static"))}(e),e.setAttribute("data-aui-alignment","submenu auto"),e.setAttribute("data-aui-alignment-static",!0)):r||(e.setAttribute("data-aui-alignment","bottom auto"),e.setAttribute("data-aui-alignment-static",!0)),e._auiAlignment&&e._auiAlignment.destroy(),e._auiAlignment=new s.default(e,t),e._auiAlignment.enable()}(0,i.default)(document).on("mouseenter",".aui-dropdown2-trigger-group a, .aui-dropdown2-trigger-group button",function(e){var t=(0,i.default)(e.currentTarget);if(!t.is(".aui-dropdown2-active")&&!t.closest(".aui-dropdown2").length){var a=t.closest(".aui-dropdown2-trigger-group"),n=a.find(".aui-dropdown2-active");n.length&&t.is(".aui-dropdown2-trigger")&&(n.blur(),t.trigger("aui-button-invoke"),e.preventDefault());var r=a.find(":focus");r.length&&t.is(".aui-dropdown2-trigger")&&r.blur()}});var L=!1;function M(){L=!0}function O(e){(0,f.default)(e),e.addEventListener("aui-layer-show",function(){(0,i.default)(e).trigger("aui-dropdown2-show"),e._syncClasses=function(e){var t=(0,i.default)(e),a=t.find(".hidden").addClass("aui-dropdown2-hidden"),n=t.find(".disabled").addClass("aui-dropdown2-disabled"),r=t.find(".interactive").addClass("aui-dropdown2-interactive");return function(){a.removeClass("aui-dropdown2-hidden"),n.removeClass("aui-dropdown2-disabled"),r.removeClass("aui-dropdown2-interactive")}}(e),_(this),v(e,function(t){w(t,!0),e._returnTo=function(e,t){var a=t.getAttribute("data-dropdown2-hide-location");return document.getElementById(a)||e.parentNode}(e,t)})}),e.addEventListener("aui-layer-hide",function(){(0,i.default)(e).trigger("aui-dropdown2-hide"),e._syncClasses&&(e._syncClasses(),delete e._syncClasses),e._auiAlignment&&(e._auiAlignment.disable(),e._auiAlignment.destroy()),e._returnTo&&e.parentNode&&e.parentNode!==e._returnTo&&e._returnTo.appendChild(e),(0,i.default)(e).removeClass("aui-dropdown2-in-buttons"),D(e).removeClass("active aui-dropdown2-active"),v(e,function(e){var t;t=!0===L,L=!1,t?(e.focus(),w(e,e.hasSubmenu&&e.hasSubmenu())):w(e,!1)}),delete e.isSubmenu,e._triggeringElement=null})}function P(e){var t=(0,i.default)(e);t.on("keydown",function(t){t.keyCode===c.default.DOWN?(e.focusNext(),t.preventDefault()):t.keyCode===c.default.UP?(e.focusPrevious(),t.preventDefault()):t.keyCode===c.default.LEFT?e.isSubmenu&&(M(),e.hide(t),t.preventDefault()):t.keyCode===c.default.ESCAPE?M():t.keyCode===c.default.TAB&&(M(),e.hide(t))});t.on("click keydown",'a, button, [role="menuitem"], [role="menuitemcheckbox"], [role="checkbox"], [role="menuitemradio"], [role="radio"]',function(t){var a=t.currentTarget,n=(0,i.default)(a),r=t.keyCode,d=r===c.default.ENTER,o=r===c.default.SPACE;d&&n.is("a[href], button")||"click"!==t.type&&!d&&!o||function(t){var a=(0,i.default)(t.currentTarget);if("true"!==a.attr("aria-disabled")){if(!(t.currentTarget.hasSubmenu&&t.currentTarget.hasSubmenu()||a.is(".aui-dropdown2-interactive"))){var n=e;do{var r=(0,f.default)(n);n=(0,f.default)(n).below(),r.$el.is(".aui-dropdown2")&&r.hide(t)}while(n)}}else t.preventDefault()}(t)}),t.on("mouseenter",'a, button, [role="menuitem"], [role="menuitemcheckbox"], [role="checkbox"], [role="menuitemradio"], [role="radio"]',function(t){var a=t.currentTarget,i=a.hasSubmenu&&a.hasSubmenu();if(!t.isDefaultPrevented()&&!i){var n=(0,f.default)(e).above();n&&(0,f.default)(n).hide()}})}function V(e){var t=(0,i.default)(e);t.addClass("aui-dropdown2"),(0,u.supportsVoiceOver)()&&t.find('> div[role="application"]').attr("role","presentation"),e.hasAttribute("data-container")&&(t.attr("data-aui-alignment-container",t.attr("data-container")),t.removeAttr("data-container")),O(e),P(e),e.hide(),(0,i.default)(e).delegate(".aui-dropdown2-checkbox:not(.disabled):not(.aui-dropdown2-disabled)","click keydown",function(e){if("click"===e.type||e.keyCode===c.default.ENTER||e.keyCode===c.default.SPACE){if(e.isDefaultPrevented())return;this.isInteractive()&&e.preventDefault(),this.isEnabled()&&(this.isChecked()?this.uncheck():this.check())}}),(0,i.default)(e).delegate(".aui-dropdown2-radio:not(.checked):not(.aui-dropdown2-checked):not(.disabled):not(.aui-dropdown2-disabled)","click keydown",function(e){if("click"===e.type||e.keyCode===c.default.ENTER||e.keyCode===c.default.SPACE){if(e.isDefaultPrevented())return;this.isInteractive()&&e.preventDefault();var t=(0,i.default)(this);this.isEnabled()&&!1===this.isChecked()&&(t.closest("ul,[role=group]").find(".aui-dropdown2-checked").not(this).each(function(){this.uncheck()}),this.check())}})}(0,i.default)(window).on("resize",(0,o.debounceImmediate)(function(){(0,i.default)(".aui-dropdown2").each(function(e,t){p.default.init(t),t.isVisible()&&t.hide()})},1e3));var B={toggle:function(e){this.isVisible()?this.hide(e):this.show(e)},show:function(e){e&&e.currentTarget&&e.currentTarget.classList.contains("aui-dropdown2-trigger")&&(this._triggeringElement=e.currentTarget),(0,f.default)(this).show();var t=this;return v(t,function(e){I(t,e)}),this},hide:function(){return(0,f.default)(this).hide(),this},focusNext:function(){var e,t=D(this),a=document.activeElement;t.last()[0]!==a&&(e=t.toArray().indexOf(a),this.focusItem(t.get(e+1)))},focusPrevious:function(){var e,t=D(this),a=document.activeElement;t.first()[0]!==a&&(e=t.toArray().indexOf(a),this.focusItem(t.get(e-1)))},focusItem:function(e){var t,a=D(this);"number"==typeof e&&(e=a.get(e)),(t=(0,i.default)(e)).focus(),a.removeClass("active aui-dropdown2-active"),t.addClass("active aui-dropdown2-active")},isVisible:function(){return(0,f.default)(this).isVisible()}},R={created:function(e){var t=e.children[0];t.setAttribute("aria-disabled","true"),t.className+=" aui-dropdown2-disabled"},removed:function(e){var t=e.children[0];t.setAttribute("aria-disabled","false"),(0,i.default)(t).removeClass("aui-dropdown2-disabled")}},j={created:function(e){e.children[0].className+=" aui-dropdown2-interactive"},removed:function(e){var t=e.children[0];(0,i.default)(t).removeClass("aui-dropdown2-interactive")}},H={created:function(e){var t=e.children[0];(0,i.default)(t).addClass("checked aui-dropdown2-checked"),t.setAttribute("aria-checked",!0),e.dispatchEvent(new l.default("change",{bubbles:!0}))},removed:function(e){var t=e.children[0];(0,i.default)(t).removeClass("checked aui-dropdown2-checked"),t.setAttribute("aria-checked",!1),e.dispatchEvent(new l.default("change",{bubbles:!0}))}},z={created:function(e){R.created(e)},removed:function(e){R.removed(e)}},J=function(e){return{fallback:function(t,a){t.children[0].setAttribute(e,a.newValue)},removed:function(t){t.children[0].removeAttribute(e)}}},U=(0,p.default)("aui-item-link",{template:(0,n.default)('<a role="menuitem" tabindex="-1"><content></content></a>'),attributes:{disabled:R,interactive:j,hidden:z,href:J("href"),"item-id":J("id"),for:{created:function(e){var t=e.children[0];t.setAttribute("aria-controls",e.getAttribute("for")),(0,i.default)(t).addClass("aui-dropdown2-sub-trigger")},updated:function(e){e.children[0].setAttribute("aria-controls",e.getAttribute("for"))},removed:function(e){var t=e.children[0];t.removeAttribute("aria-controls"),(0,i.default)(t).removeClass("aui-dropdown2-sub-trigger")}}}}),W=(0,p.default)("aui-item-checkbox",{template:(0,n.default)('<span role="checkbox" class="aui-dropdown2-checkbox" tabindex="-1"><content></content></span>'),attributes:{"item-id":J("id"),disabled:R,interactive:j,checked:H,hidden:z}}),q=(0,p.default)("aui-item-radio",{template:(0,n.default)('<span role="radio" class="aui-dropdown2-radio" tabindex="-1"><content></content></span>'),attributes:{"item-id":J("id"),disabled:R,interactive:j,checked:H,hidden:z}}),F=(0,p.default)("aui-section",{template:(0,n.default)('\n <strong aria-role="presentation" class="aui-dropdown2-heading"></strong>\n <div role="group">\n <content></content>\n </div>\n '),attributes:{label:function(e,t){var a=e.children[0],i=e.children[1];a.textContent=t.newValue,i.setAttribute("aria-label",t.newValue)}},created:function(e){e.className+=" aui-dropdown2-section",e.setAttribute("role","presentation")}}),G=(0,p.default)("aui-dropdown-menu",{template:(0,n.default)('\n <div role="application">\n <content></content>\n </div>\n '),created:function(e){e.setAttribute("role","menu"),e.className="aui-dropdown2 aui-style-default aui-layer",(0,h.default)(e).set("loading-state",k),p.default.init(e)},attributes:{src:{}},prototype:B,events:{"aui-layer-show":function(e){var t=(0,h.default)(e).get("loading-state")===k,a=(0,h.default)(e).get("hasErrorBeenShown");(t||a)&&S(e),(0,h.default)(e).get("loading-state")===y&&(0,h.default)(e).set("hasErrorBeenShown",!0)}}});(0,p.default)("aui-dropdown2",{type:p.default.type.CLASSNAME,created:V,prototype:B}),(0,p.default)("data-aui-dropdown2",{type:p.default.type.ATTRIBUTE,created:V,prototype:B});var $=(0,p.default)("aui-dropdown2-checkbox",{type:p.default.type.CLASSNAME,created:function(e){var t=g(e);t&&(0,i.default)(e).addClass("checked aui-dropdown2-checked"),e.setAttribute("aria-checked",t),e.setAttribute("tabindex","0"),(0,u.supportsVoiceOver)()&&e.setAttribute("role","checkbox")},prototype:{isEnabled:function(){return!(null!==this.getAttribute("aria-disabled")&&"true"===this.getAttribute("aria-disabled"))},isChecked:function(){return null!==this.getAttribute("aria-checked")&&"true"===this.getAttribute("aria-checked")},isInteractive:function(){return(0,i.default)(this).hasClass("aui-dropdown2-interactive")},uncheck:function(){"aui-item-checkbox"===this.parentNode.tagName.toLowerCase()&&this.parentNode.removeAttribute("checked"),this.setAttribute("aria-checked","false"),(0,i.default)(this).removeClass("checked aui-dropdown2-checked"),(0,i.default)(this).trigger("aui-dropdown2-item-uncheck")},check:function(){"aui-item-checkbox"===this.parentNode.tagName.toLowerCase()&&this.parentNode.setAttribute("checked",""),this.setAttribute("aria-checked","true"),(0,i.default)(this).addClass("checked aui-dropdown2-checked"),(0,i.default)(this).trigger("aui-dropdown2-item-check")}}}),K=(0,p.default)("aui-dropdown2-radio",{type:p.default.type.CLASSNAME,created:function(e){var t=g(e);t&&(0,i.default)(e).addClass("checked aui-dropdown2-checked"),e.setAttribute("aria-checked",t),e.setAttribute("tabindex","0"),(0,u.supportsVoiceOver)()&&e.setAttribute("role","radio")},prototype:{isEnabled:function(){return!(null!==this.getAttribute("aria-disabled")&&"true"===this.getAttribute("aria-disabled"))},isChecked:function(){return null!==this.getAttribute("aria-checked")&&"true"===this.getAttribute("aria-checked")},isInteractive:function(){return(0,i.default)(this).hasClass("aui-dropdown2-interactive")},uncheck:function(){"aui-item-radio"===this.parentNode.tagName.toLowerCase()&&this.parentNode.removeAttribute("checked"),this.setAttribute("aria-checked","false"),(0,i.default)(this).removeClass("checked aui-dropdown2-checked"),(0,i.default)(this).trigger("aui-dropdown2-item-uncheck")},check:function(){"aui-item-radio"===this.parentNode.tagName.toLowerCase()&&this.parentNode.setAttribute("checked",""),this.setAttribute("aria-checked","true"),(0,i.default)(this).addClass("checked aui-dropdown2-checked"),(0,i.default)(this).trigger("aui-dropdown2-item-check")}}});t.DropdownEl=G,t.DropdownCheckboxEl=$,t.DropdownRadioEl=K,t.ItemLinkEl=U,t.ItemRadioEl=q,t.ItemCheckboxEl=W,t.SectionEl=F,t.DropdownTriggerEl=x,t.DropdownSubTriggerEl=N}};