{"version":3,"sources":["webpack:///./cartridges/app_accelerator_core/cartridge/client/default/js/modules/module.floating-labels.js"],"names":["FloatingLabels","query","_classCallCheck","formRows","document","querySelectorAll","forEach","call","setupField","bind","_createClass","key","value","formRow","input","querySelector","addEventListener","setFloating","toggleFloating","window","SFRA","supportsPlaceholderShown","placeholder","matches","floatingLabel","unsetFloating","classList","add","remove","closest","trim"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAHA,IAKqBA,cAAc;EAC/B,SAAAA,eAAYC,KAAK,EAAE;IAAAC,eAAA,OAAAF,cAAA;IACf,IAAIG,QAAQ,GAAGC,QAAQ,CAACC,gBAAgB,CAACJ,KAAK,CAAC;IAE/C,EAAE,CAACK,OAAO,CAACC,IAAI,CAACJ,QAAQ,EAAE,IAAI,CAACK,UAAU,CAACC,IAAI,CAAC,IAAI,CAAC,CAAC;EACzD;EAAC,OAAAC,YAAA,CAAAV,cAAA;IAAAW,GAAA;IAAAC,KAAA,EAED,SAAAJ,UAAUA,CAACK,OAAO,EAAE;MAChB,IAAIC,KAAK,GAAGD,OAAO,CAACE,aAAa,CAAC,eAAe,CAAC;MAElDD,KAAK,CAACE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAACC,WAAW,CAACR,IAAI,CAAC,IAAI,EAAEI,OAAO,CAAC,CAAC;MACrEC,KAAK,CAACE,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAACC,WAAW,CAACR,IAAI,CAAC,IAAI,EAAEI,OAAO,CAAC,CAAC;MACrEC,KAAK,CAACE,gBAAgB,CAAC,QAAQ,EAAE,IAAI,CAACE,cAAc,CAACT,IAAI,CAAC,IAAI,EAAEK,KAAK,EAAED,OAAO,CAAC,CAAC;MAChFC,KAAK,CAACE,gBAAgB,CAAC,iBAAiB,EAAE,IAAI,CAACE,cAAc,CAACT,IAAI,CAAC,IAAI,EAAEK,KAAK,EAAED,OAAO,CAAC,CAAC;MACzFC,KAAK,CAACE,gBAAgB,CAAC,MAAM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ACtC;MACJ;IACJ;EAAC;AAAA","file":"module-floating-labels.js","sourcesContent":["/**\n * Handles displaying a \"floatingLabel\" label on fields,\n * which changes position when user focuses, changes, or adds input to a field.\n */\n\nexport default class FloatingLabels {\n constructor(query) {\n let formRows = document.querySelectorAll(query);\n\n [].forEach.call(formRows, this.setupField.bind(this));\n }\n\n setupField(formRow) {\n let input = formRow.querySelector('input, select');\n\n input.addEventListener('focus', this.setFloating.bind(this, formRow));\n input.addEventListener('input', this.setFloating.bind(this, formRow));\n input.addEventListener('change', this.toggleFloating.bind(this, input, formRow));\n input.addEventListener('external:change', this.toggleFloating.bind(this, input, formRow));\n input.addEventListener('blur', this.toggleFloating.bind(this, input, formRow));\n\n if (input.value || (window.SFRA.supportsPlaceholderShown && input.placeholder && !input.matches(':placeholder-shown'))) {\n this.setFloating(formRow);\n }\n\n //Sets methods on the input field itself.\n input.floatingLabel = {\n setFloating: this.setFloating.bind(this, formRow),\n unsetFloating: this.unsetFloating.bind(this, formRow),\n toggleFloating: this.toggleFloating.bind(this, input, formRow)\n };\n }\n\n setFloating(formRow) {\n formRow.classList.add('set--floating-label');\n }\n\n unsetFloating(formRow) {\n formRow.classList.remove('set--floating-label');\n }\n\n toggleFloating(input, formRow) {\n formRow = formRow || input.closest('[data-floating-label]');\n\n if (formRow) {\n if (input.value.trim()) {\n this.setFloating(formRow);\n } else {\n this.unsetFloating(formRow, input);\n }\n }\n }\n}\n"],"sourceRoot":""}