UNPKG

@atlassian/aui

Version:

Atlassian User Interface Framework

26 lines 5.58 kB
/*!! * @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=[76],exports.modules={148: /*!*******************************!*\ !*** ../src/js/aui/toggle.js ***! \*******************************/ /*! no static exports found */ /*! all exports used */ /*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),i(/*! ./spin */57),i(/*! ./tooltip */40);var n=i(/*! ./internal/attributes */70),u=d(i(/*! ./jquery */0)),a=d(i(/*! ./internal/enforcer */44)),l=d(i(/*! ./key-code */8)),o=d(i(/*! skatejs-template-html */18)),s=d(i(/*! ./internal/skate */5)),r=i(/*! ./internal/constants */34),c=d(i(/*! ./polyfills/custom-event */19));function d(t){return t&&t.__esModule?t:{default:t}}function f(t){t._canFireEventsNow&&t.dispatchEvent(new c.default("change",{bubbles:!0}))}function b(t){return t._input||(t._input=t.querySelector("input"))}function h(t,e){b(e).removeAttribute(t)}function p(t,e,i){b(e).setAttribute(t,i.newValue)}function g(t){return{removed:h.bind(this,t),fallback:p.bind(this,t)}}var _={removed:function(t){h.call(this,"form",t),t._formId=null},fallback:function(t,e){p.call(this,"form",t,e),t._formId=e.newValue}},v={removed:h.bind(void 0,"id"),fallback:function(t,e){b(t).setAttribute("id",""+e.newValue+r.INPUT_SUFFIX)}},k={removed:function(t){b(t).checked=!1,f(t)},fallback:function(t){b(t).checked=!0,f(t)}},m={removed:function(t){b(t).removeAttribute("aria-label")},fallback:function(t,e){b(t).setAttribute("aria-label",e.newValue)}};var A=(0,s.default)("aui-toggle",{template:(0,o.default)('<input type="checkbox" class="aui-toggle-input assistive">','<span class="aui-toggle-view">','<span class="aui-toggle-tick aui-icon aui-icon-small aui-iconfont-success"></span>','<span class="aui-toggle-cross aui-icon aui-icon-small aui-iconfont-close-dialog"></span>',"</span>"),created:function(t){t._input=b(t),t._tick=t.querySelector(".aui-toggle-tick"),t._cross=t.querySelector(".aui-toggle-cross"),(0,u.default)(t._input).tooltip({title:function(){return this.checked?this.getAttribute("tooltip-on"):this.getAttribute("tooltip-off")},gravity:"s",hoverable:!1}),function(t){t._input.addEventListener("keydown",function(e){t.busy&&e.keyCode===l.default.SPACE&&e.preventDefault()}),navigator.userAgent.toLowerCase().indexOf("firefox")>-1&&t._input.addEventListener("click",function(e){t.busy&&e.preventDefault()})}(t),t.hasAttribute("checked")&&b(t).setAttribute("checked",""),t._canFireEventsNow=!0},attached:function(t){(0,a.default)(t).attributeExists("label")},events:{click:function(t,e){t.disabled||t.busy||e.target===t._input||(t._input.checked=!t._input.checked),(0,n.setBooleanAttribute)(t,"checked",b(t).checked)}},attributes:{id:v,checked:k,disabled:g("disabled"),form:_,name:g("name"),value:g("value"),"tooltip-on":{value:AJS.I18n.getText("aui.toggle.on"),fallback:function(t,e){b(t).setAttribute("tooltip-on",e.newValue||AJS.I18n.getText("aui.toggle.on"))}},"tooltip-off":{value:AJS.I18n.getText("aui.toggle.off"),fallback:function(t,e){b(t).setAttribute("tooltip-off",e.newValue||AJS.I18n.getText("aui.toggle.off"))}},label:m},prototype:{focus:function(){return this._input.focus(),this},get checked(){return this._input.checked},set checked(t){this._input.checked!==t&&(this._input.checked=t,(0,n.setBooleanAttribute)(this,"checked",t))},get disabled(){return this._input.disabled},set disabled(t){return(0,n.setBooleanAttribute)(this,"disabled",t)},get form(){return document.getElementById(this._formId)},set form(t){return _.fallback.call(this,this,{newValue:t||null}),this.form},get name(){return this._input.name},set name(t){return this.setAttribute("name",t),t},get value(){return this._input.value},set value(t){return this.setAttribute("value",null===t?"":t),t},get busy(){return"true"===this._input.getAttribute("aria-busy")},set busy(t){var e,i;return(0,n.setBooleanAttribute)(this,"busy",t),t?(this._input.setAttribute("aria-busy","true"),this._input.indeterminate=!0,this.checked?((0,u.default)(this._input).addClass("indeterminate-checked"),(0,u.default)(this._tick).spin({zIndex:null})):(0,u.default)(this._cross).spin({zIndex:null,color:"black"})):((0,u.default)(this._input).removeClass("indeterminate-checked"),this._input.indeterminate=!1,this._input.removeAttribute("aria-busy"),(0,u.default)(this._cross).spinStop(),(0,u.default)(this._tick).spinStop()),i=!!t,(e=this).id&&Array.prototype.forEach.call(document.querySelectorAll('aui-label[for="'+e.id+'"]'),function(t){t.disabled=i}),t}}});e.default=A,t.exports=e.default},150: /*!***********************************!*\ !*** ../src/less/aui-toggle.less ***! \***********************************/ /*! no static exports found */ /*! all exports used */ /*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(t,e,i){},151: /*!**************************************!*\ !*** ./aui.component.form.toggle.js ***! \**************************************/ /*! no static exports found */ /*! all exports used */ /*! ModuleConcatenation bailout: Module is not an ECMAScript module */function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ToggleEl=void 0,i(/*! ./styles/aui.pattern.forms */12),i(/*! ./aui.component.spinner */64),i(/*! @atlassian/aui/src/less/aui-toggle.less */150);var n,u=i(/*! @atlassian/aui/src/js/aui/toggle */148),a=(n=u)&&n.__esModule?n:{default:n};e.ToggleEl=a.default}};