{"version":3,"sources":["webpack:///./Scripts/buttons.js"],"names":["__webpack_require__","r","__webpack_exports__","_utils__WEBPACK_IMPORTED_MODULE_0__","element","Button","toggled","toggle","e","label","target","tagName","parentNode","eventTarget","labels","slice","call","getElementsByClassName","input","getElementsByTagName","type","checked","classList","remove","getAttribute","removeAttribute","add","setAttribute","customEvent","i","ll","length","otherLabel","otherInput","contains","setTimeout","addEventListener","querySelector","which","keyCode","document","activeElement","preventDefault","labelsToActivate","lbll","this","elements","querySelectorAll"],"mappings":"0FAAAA,EAAAC,EAAAC,GAAA,IAAAC,EAAAH,EAAA,GAEeE,EAAA,iBAAAE,GAsFd,IArFA,IAAIC,EAAS,SAAUD,GACtB,IAAIE,GAAU,EAYVC,EAAS,SAAUC,GACtB,IAAIC,EAA6B,UAArBD,EAAEE,OAAOC,QAAsBH,EAAEE,OAAyC,UAAhCF,EAAEE,OAAOE,WAAWD,QAAsBH,EAAEE,OAAOE,WAAa,KACtH,GAAKH,EAAL,CAEA,IAAII,EAAcL,EAAEE,OAChBI,KAAYC,MAAMC,KAAKH,EAAYD,WAAWA,WAAWK,uBAAuB,QAEhFC,EAAQT,EAAMU,qBAAqB,SAAS,GAChD,GAAKD,EAAL,CAwBA,GArBmB,aAAfA,EAAME,OACJF,EAAMG,SAMVZ,EAAMa,UAAUC,OAAO,UACvBL,EAAMM,aAAa,WACnBN,EAAMO,gBAAgB,WACtBP,EAAMG,SAAU,IARhBZ,EAAMa,UAAUI,IAAI,UACpBR,EAAMM,aAAa,WACnBN,EAAMS,aAAa,UAAW,WAC9BT,EAAMG,SAAU,GAQZf,IACJA,GAAU,EAEVsB,cAAYZ,KAAKE,EAAO,MAAO,QAC/BU,cAAYZ,KAAKZ,EAAS,MAAO,UAIhB,UAAfc,EAAME,OAAqBd,IACzBY,EAAMG,QAAS,CACnBZ,EAAMa,UAAUI,IAAI,UACpBR,EAAMS,aAAa,UAAW,WAC9BT,EAAMG,SAAU,EAChBO,cAAYZ,KAAKE,EAAO,MAAO,UAC/BU,cAAYZ,KAAKZ,EAAS,MAAO,UAEjCE,GAAU,EACV,IAAK,IAAIuB,EAAI,EAAGC,EAAKhB,EAAOiB,OAAQF,EAAIC,EAAID,IAAK,CAChD,IAAIG,EAAalB,EAAOe,GACpBI,EAAaD,EAAWb,qBAAqB,SAAS,GACtDa,IAAevB,GAASuB,EAAWV,UAAUY,SAAS,YACzDF,EAAWV,UAAUC,OAAO,UAC5BU,EAAWR,gBAAgB,WAC3BQ,EAAWZ,SAAU,IAKzBc,WAAW,WAAc7B,GAAU,GAAU,OAGxC,WAAYF,IACjBA,EAAQgC,iBAAiB,QAAS7B,GAAQ,GAC1CH,EAAQiC,cAAc,eAAiBjC,EAAQgC,iBAAiB,QAnEhD,SAAU5B,GAElB,MADEA,EAAE8B,OAAS9B,EAAE+B,UACT/B,EAAEE,SAAW8B,SAASC,eAAiBlC,EAAOC,KAiEyB,GACrFJ,EAAQgC,iBAAiB,UA/DN,SAAU5B,GAErB,MADEA,EAAE8B,OAAS9B,EAAE+B,UACT/B,EAAEkC,mBA6DmC,IAOpD,IAHA,IAAIC,KAAsB5B,MAAMC,KAAKZ,EAAQa,uBAAuB,QAChE2B,EAAOD,EAAiBZ,OAEnBF,EAAI,EAAGA,EAAIe,EAAMf,KACxBc,EAAiBd,GAAGP,UAAUY,SAAS,WAAaS,EAAiBd,GAAGQ,cAAc,kBAAoBM,EAAiBd,GAAGP,UAAUI,IAAI,UAE9ItB,EAAQC,OAASwC,MAGdC,EAAW1C,EAAQ2C,iBAAiB,2BAC/BlB,EAAI,EAAGA,EAAIiB,EAASf,OAAQF,IACpC,IAAIxB,EAAOyC,EAASjB","file":"1.js","sourcesContent":["import { customEvent } from './utils';\n\nexport default element => {\n\tvar Button = function (element) {\n\t\tvar toggled = false;\n\n\t\tvar keyHandler = function (e) {\n\t\t\tvar key = e.which || e.keyCode;\n\t\t\tkey === 32 && e.target === document.activeElement && toggle(e);\n\t\t};\n\n\t\tvar preventScroll = function (e) {\n\t\t\tvar key = e.which || e.keyCode;\n\t\t\tkey === 32 && e.preventDefault();\n\t\t};\n\n\t\tvar toggle = function (e) {\n\t\t\tvar label = e.target.tagName === 'LABEL' ? e.target : e.target.parentNode.tagName === 'LABEL' ? e.target.parentNode : null; // the .btn label\n\t\t\tif (!label) return; // react if a label or its immediate child is clicked\n\n\t\t\tvar eventTarget = e.target; // the button itself, the target of the handler function\n\t\t\tvar labels = [].slice.call(eventTarget.parentNode.parentNode.getElementsByClassName('btn'));\n\n\t\t\tvar input = label.getElementsByTagName('INPUT')[0];\n\t\t\tif (!input) return; //return if no input found\n\n\t\t\t// manage the dom manipulation\n\t\t\tif (input.type === 'checkbox') { //checkboxes\n\t\t\t\tif (!input.checked) {\n\t\t\t\t\tlabel.classList.add('active');\n\t\t\t\t\tinput.getAttribute('checked');\n\t\t\t\t\tinput.setAttribute('checked', 'checked');\n\t\t\t\t\tinput.checked = true;\n\t\t\t\t} else {\n\t\t\t\t\tlabel.classList.remove('active');\n\t\t\t\t\tinput.getAttribute('checked');\n\t\t\t\t\tinput.removeAttribute('checked');\n\t\t\t\t\tinput.checked = false;\n\t\t\t\t}\n\n\t\t\t\tif (!toggled) { // prevent triggering the event twice\n\t\t\t\t\ttoggled = true;\n\n\t\t\t\t\tcustomEvent.call(input, 'btn', 'show'); //trigger the change for the input\n\t\t\t\t\tcustomEvent.call(element, 'btn', 'show'); //trigger the change for the btn-group\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (input.type === 'radio' && !toggled) { // radio buttons\n\t\t\t\tif (!input.checked) { // don't trigger if already active\n\t\t\t\t\tlabel.classList.add('active');\n\t\t\t\t\tinput.setAttribute('checked', 'checked');\n\t\t\t\t\tinput.checked = true;\n\t\t\t\t\tcustomEvent.call(input, 'btn', 'change'); // trigger the change for the input\n\t\t\t\t\tcustomEvent.call(element, 'btn', 'change'); // trigger the change for the btn-group\n\n\t\t\t\t\ttoggled = true;\n\t\t\t\t\tfor (var i = 0, ll = labels.length; i < ll; i++) {\n\t\t\t\t\t\tvar otherLabel = labels[i];\n\t\t\t\t\t\tvar otherInput = otherLabel.getElementsByTagName('INPUT')[0];\n\t\t\t\t\t\tif (otherLabel !== label && otherLabel.classList.contains('active')) {\n\t\t\t\t\t\t\totherLabel.classList.remove('active');\n\t\t\t\t\t\t\totherInput.removeAttribute('checked');\n\t\t\t\t\t\t\totherInput.checked = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tsetTimeout(function () { toggled = false; }, 50);\n\t\t}\n\n\t\tif (!('Button' in element)) { // prevent adding event handlers twice\n\t\t\telement.addEventListener('click', toggle, false);\n\t\t\telement.querySelector('[tabindex]') && element.addEventListener('keyup', keyHandler, false);\n\t\t\telement.addEventListener('keydown', preventScroll, false);\n\t\t}\n\n\t\t// activate items on load\n\t\tvar labelsToActivate = [].slice.call(element.getElementsByClassName('btn'));\n\t\tvar lbll = labelsToActivate.length;\n\n\t\tfor (var i = 0; i < lbll; i++) {\n\t\t\t!labelsToActivate[i].classList.contains('active') && labelsToActivate[i].querySelector('input:checked') && labelsToActivate[i].classList.add('active');\n\t\t}\n\t\telement.Button = this;\n\t}\n\n\tvar elements = element.querySelectorAll('[data-toggle=\"buttons\"]');\n\tfor (var i = 0; i < elements.length; i++) {\n\t\tnew Button(elements[i]);\n\t};\n};"],"sourceRoot":""}