-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsmart.checkbox.js
6 lines (4 loc) · 3.19 KB
/
smart.checkbox.js
1
2
3
4
5
6
/* Smart UI v15.2.0 (2023-04-20)
Copyright (c) 2011-2023 jQWidgets.
License: https://htmlelements.com/license/ */ //
Smart("smart-check-box",class extends Smart.ToggleButton{static get properties(){return{checkMode:{value:"both",allowedValues:["both","input","label"],type:"string"},type:{value:"checkbox",type:"string",defaultReflectToAttribute:!0,readonly:!0}}}template(){return"<div id='container' class='smart-container' role=\"presentation\">\n <div class='smart-overlay' role=\"presentation\"></div>\n <span id='checkBoxInput' class='smart-input' aria-hidden=\"true\"></span>\n <span id='checkBoxLabel' inner-h-t-m-l='[[innerHTML]]' class='smart-label'><content></content></span>\n <input id='hiddenInput' class='smart-hidden-input' type='hidden'>\n </div>"}static get listeners(){return{down:"_downHandler","document.up":"_documentUpHandler","checkBoxInput.mouseenter":"_mouseEnterHandler","checkBoxInput.mouseleave":"_mouseLeaveHandler",focus:"_focusHandler",blur:"_blurHandler"}}static get styleUrls(){return["smart.toggle.css"]}_focusHandler(){this.$.setAttributeValue("focus",!0)}_blurHandler(){this.$.setAttributeValue("focus",!1)}_mouseEnterHandler(){this.$.setAttributeValue("hover",!0)}_mouseLeaveHandler(){this.$.setAttributeValue("hover",!1)}ready(){const e=this;super.ready(),e.setAttribute("role","checkbox"),e.indeterminate&&(e._valueCache=e.checked,e.checked=null,e._setAriaState()),e.classList.add("smart-toggle-box"),e._updateHidenInputNameAndValue()}propertyChangedHandler(e,t,a){super.propertyChangedHandler(e,t,a);const n=this;switch(n._updateContentProperties(),e){case"indeterminate":a?(n._valueCache=n.checked,n.checked=null):n.checked=n._valueCache,n._setAriaState(),n._updateHidenInputNameAndValue();break;case"value":case"checked":n._updateHidenInputNameAndValue();break;case"name":n._updateHidenInputName()}}_documentUpHandler(e){const t=this;if(!t._pressed||"pointercancel"===e.originalEvent.type)return;const a=t.enableShadowDOM?e.originalEvent.composedPath()[0]:e.originalEvent.target;if(t._pressed=!1,t.$.setAttributeValue("active",!1),!(t.disabled||t.readonly||"input"===t.checkMode&&a!==t.$.checkBoxInput||"label"===t.checkMode&&a!==t.$.checkBoxLabel)){if("press"===t.clickMode)return e.preventDefault(),void e.stopPropagation();t._changeCheckState("pointer"),t.focus(),t._handleTextSelection(),t._updateHidenInputNameAndValue()}}_downHandler(e){const t=this,a=t.enableShadowDOM?e.originalEvent.composedPath()[0]:e.originalEvent.target;if(!(t.disabled||t.readonly||"input"===t.checkMode&&a!==t.$.checkBoxInput||"label"===t.checkMode&&a!==t.$.checkBoxLabel)){if(t.$.setAttributeValue("active",!0),t.hasRippleAnimation){const e=t.$.checkBoxInput.getBoundingClientRect(),a=window.scrollX||window.pageXOffset,n=window.scrollY||window.pageYOffset;Smart.Utilities.Animation.Ripple.animate(t.$.checkBoxInput,e.left+e.width/2+a,e.top+e.height/2+n)}t._pressed=!0,"press"!==t.clickMode&&"pressAndRelease"!==t.clickMode||(t._changeCheckState("pointer"),t.$.fireEvent("click"),t.focus(),t._updateHidenInputNameAndValue())}}_setAriaState(){const e=this,t=e.checked;null!==t?e.setAttribute("aria-checked",t):e.setAttribute("aria-checked","mixed")}});