{"version":3,"file":"../fc-utils-313.min.js","sources":["fc-utils-313.js"],"sourcesContent":["/**\n * Utility resources shared across the scripts of Fluid Checkout.\n */\n(function (root, factory) {\n\tif ( typeof define === 'function' && define.amd ) {\n\t\tdefine([], factory(root));\n\t} else if ( typeof exports === 'object' ) {\n\t\tmodule.exports = factory(root);\n\t} else {\n\t\troot.FCUtils = factory(root);\n\t}\n})(typeof global !== 'undefined' ? global : this.window || this.global, function (root) {\n\n\t'use strict';\n\n\tvar _publicMethods = { }\n\tvar _settings = {\n\t\tselect2FormRowSelector: '.form-row.fc-select2-field',\n\t\tselect2FocusElementSelector: '.select2-selection, input[type=\"text\"]',\n\t}\n\n\n\n\t/**\n\t * PROPERTIES\n\t */\n\n\n\n\t/**\n\t * Mapping of keyboard keys based on and comparable with `event.key` values.\n\t */\n\t_publicMethods.keyboardKeys = {\n\t\tESC: 'Escape',\n\t\tENTER: 'Enter',\n\t\tSPACE: ' ',\n\t\tTAB: 'Tab',\n\t\tCAPS: 'CapsLock',\n\t\tSHIFT: 'Shift',\n\t\tFUNCTION: 'Fn',\n\t\tCONTROL: 'Control',\n\t\tCOMMAND_OR_WINDOWS: 'Meta', // This is the `Windows` logo key, or the `Command` or `⌘` key on Mac keyboards.\n\t\tALT: 'Alt',\n\t\tARROW_LEFT: 'ArrowLeft',\n\t\tARROW_RIGHT: 'ArrowRight',\n\t\tARROW_UP: 'ArrowUp',\n\t\tARROW_DOWN: 'ArrowDown',\n\t}\n\n\n\n\t/**\n\t * Determine which `animationend` event is supported.\n\t */\n\t_publicMethods.animationEndEvent = window.whichAnimationEnd ? window.whichAnimationEnd() : 'animationend';\n\n\n\n\n\t/**\n\t * METHODS\n\t */\n\n\n\n\t/*!\n\t* Merge two or more objects together.\n\t* (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com\n\t* @param {Boolean} deep If true, do a deep (or recursive) merge [optional]\n\t* @param {Object} objects The objects to merge together\n\t* @returns {Object} Merged values of defaults and options\n\t*/\n\t_publicMethods.extendObject = function () {\n\t\t// Variables\n\t\tvar extended = {};\n\t\tvar deep = false;\n\t\tvar i = 0;\n\n\t\t// Check if a deep merge\n\t\tif ( Object.prototype.toString.call( arguments[0] ) === '[object Boolean]' ) {\n\t\t\tdeep = arguments[0];\n\t\t\ti++;\n\t\t}\n\n\t\t// Merge the object into the extended object\n\t\tvar merge = function (obj) {\n\t\t\tfor (var prop in obj) {\n\t\t\t\tif (obj.hasOwnProperty(prop)) {\n\t\t\t\t\t// If property is an object, merge properties\n\t\t\t\t\tif (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {\n\t\t\t\t\t\textended[prop] = _publicMethods.extendObject(extended[prop], obj[prop]);\n\t\t\t\t\t} else {\n\t\t\t\t\t\textended[prop] = obj[prop];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// Loop through each object and conduct a merge\n\t\tfor (; i < arguments.length; i++) {\n\t\t\tvar obj = arguments[i];\n\t\t\tmerge(obj);\n\t\t}\n\n\t\treturn extended;\n\t};\n\n\n\n\t/**\n\t * Returns a function, that, as long as it continues to be invoked, will not\n\t * be triggered. The function will be called after it stops being called for\n\t * N milliseconds. If `immediate` is passed, trigger the function on the\n\t * leading edge, instead of the trailing.\n\t *\n\t * @param {[type]} func Function to be executed.\n\t * @param {[type]} wait Wait time in milliseconds.\n\t * @param {[type]} immediate Trigger the function on the leading edge.\n\t *\n\t * @return function Function to be executed, incapsulated in a timed function.\n\t */\n\t_publicMethods.debounce = function ( func, wait, immediate ) {\n\t\tvar timeout;\n\n\t\treturn function() {\n\t\t\tvar context = this, args = arguments;\n\t\t\tvar later = function() {\n\t\t\t\ttimeout = null;\n\t\t\t\tif (!immediate) func.apply( context, args );\n\t\t\t};\n\n\t\t\tvar callNow = immediate && !timeout;\n\t\t\tclearTimeout( timeout );\n\t\t\ttimeout = setTimeout( later, wait );\n\n\t\t\tif ( callNow ) func.apply( context, args );\n\t\t};\n\t};\n\n\n\n\n\n\t/**\n\t * Maybe set focus back to the element that was focused before an update.\n\t * \n\t * @param {HTMLElement} currentFocusedElement The element that was currently focused before an update.\n\t * @param {mixed} currentValue The value of the element in focus before an update.\n\t */\n\t_publicMethods.maybeRefocusElement = function( currentFocusedElement, currentValue ) {\n\t\t// Bail if no element to focus\n\t\tif ( null === currentFocusedElement ) { return; }\n\n\t\t// Bail if focus is set to the document body\n\t\tif ( document.body === currentFocusedElement ) { return; }\n\n\t\trequestAnimationFrame( function() {\n\t\t\tvar elementToFocus;\n\n\t\t\t// Try findind the `select2` focusable element\n\t\t\tif ( currentFocusedElement.closest( _settings.select2FormRowSelector ) ) {\n\t\t\t\tvar formRow = currentFocusedElement.closest( _settings.select2FormRowSelector );\n\t\t\t\telementToFocus = formRow.querySelector( _settings.select2FocusElementSelector );\n\t\t\t}\n\t\t\t// Try findind the the current focused element after updating updated element by ID\n\t\t\telse if ( currentFocusedElement.id ) {\n\t\t\t\telementToFocus = document.getElementById( currentFocusedElement.id );\n\t\t\t}\n\t\t\t// Try findind the updated element by name attribute\n\t\t\telse if ( currentFocusedElement.getAttribute( 'name' ) ) {\n\t\t\t\tvar nameAttr = currentFocusedElement.getAttribute( 'name' );\n\t\t\t\telementToFocus = document.querySelector( '[name=\"'+nameAttr+'\"]' );\n\t\t\t}\n\n\t\t\t// Try setting focus if element is found\n\t\t\tif ( elementToFocus ) {\n\t\t\t\telementToFocus.focus();\n\n\t\t\t\t// Try to set current value to the focused element\n\t\t\t\tif ( undefined !== currentValue && null !== currentValue && currentValue !== elementToFocus.value ) {\n\t\t\t\t\telementToFocus.value = currentValue;\n\t\t\t\t}\n\n\t\t\t\t// Set keyboard track position back to that previously to update\n\t\t\t\tsetTimeout( function(){\n\t\t\t\t\t// Try to set the same track position\n\t\t\t\t\tif( null !== elementToFocus.selectionStart && null !== elementToFocus.selectionEnd ) {\n\t\t\t\t\t\tif ( currentFocusedElement.selectionStart && currentFocusedElement.selectionEnd ) {\n\t\t\t\t\t\t\telementToFocus.selectionStart = currentFocusedElement.selectionStart;\n\t\t\t\t\t\t\telementToFocus.selectionEnd = currentFocusedElement.selectionEnd;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise try set the track position to the end of the field\n\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n\t\t\t\t\t\t// @see https://html.spec.whatwg.org/multipage/input.html#concept-input-apply\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\telementToFocus.selectionStart = elementToFocus.selectionEnd = 999999;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 0 );\n\t\t\t}\n\t\t} );\n\t};\n\n\n\n\n\n\t/**\n\t * Expose public APIs.\n\t */\n\treturn _publicMethods;\n\n});\n"],"names":["root","factory","define","amd","exports","module","FCUtils","global","this","window","_publicMethods","_settings","keyboardKeys","ESC","ENTER","SPACE","TAB","CAPS","SHIFT","FUNCTION","CONTROL","COMMAND_OR_WINDOWS","ALT","ARROW_LEFT","ARROW_RIGHT","ARROW_UP","ARROW_DOWN","animationEndEvent","whichAnimationEnd","extendObject","extended","deep","i","Object","prototype","toString","call","arguments","length","prop","obj","hasOwnProperty","debounce","func","wait","immediate","timeout","context","args","callNow","clearTimeout","setTimeout","apply","maybeRefocusElement","currentFocusedElement","currentValue","document","body","requestAnimationFrame","elementToFocus","nameAttr","closest","querySelector","id","getElementById","getAttribute","focus","undefined","value","selectionStart","selectionEnd"],"mappings":"AAGA,CAAA,SAAWA,EAAMC,GACO,YAAlB,OAAOC,QAAyBA,OAAOC,IAC3CD,OAAO,GAAID,EAAY,CAAC,EACM,UAAnB,OAAOG,QAClBC,OAAOD,QAAUH,EAAY,EAE7BD,EAAKM,QAAUL,EAAY,CAE5B,EAAoB,aAAlB,OAAOM,OAAyBA,OAASC,KAAKC,QAAUD,KAAKD,OAAQ,SAAUP,GAEjF,aAEA,IAAIU,EAAiB,GACjBC,EACoC,6BADpCA,EAEoC,yCAgMxC,OAlLAD,EAA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