{"version":3,"sources":["webpack:////tmp/build_ae20a34b/app/assets/es6/entries/rtdv_icmib.js"],"names":["RealTimeDataValidator","_classCallCheck","this","questionIdHasManyMetadata","questionId","metadata","inputDomElement","firstChar","numberOfCharactersTyped","maxPasteLength","autoCompleteDetected","numberOfKeyUpCountAll","numberOfKeyDownCountAll","pastedEntireResponse","speechDetected","startTime","timeDiff","endTime","startTimeChar","timeDiffFirstChar","outputString","concat","randomCharacter","value","length","characters","charAt","Math","floor","random","_this","metadataArray","document","querySelectorAll","forEach","container","getAttribute","split","inputField","meta","Object","create","push","_this2","hasManyMetaDatas","questionIds","map","_toConsumableArray","Set","filter","outputValue","_this3","formElement","querySelector","addEventListener","_event","populateQuestionIdHasManyMetadata","hiddenInput","createElement","setAttribute","JSON","stringify","appendChild","event","Date","inputType","data","_this4","preloadMetaData","addEventListeners","handleMetadataOnFormSubmit","rtdv","setTimeout","init"],"mappings":"i+BAmBMA,aACJ,SAAAA,iGAAcC,CAAAC,KAAAF,GACZE,KAAKC,0BAA4B,CAC/BC,WAAY,GACZC,SAAU,IAEZH,KAAKG,SAAW,CACdD,WAAY,GACZE,gBAAiB,KACjBC,WAAW,EACXC,wBAAyB,EACzBC,eAAgB,EAChBC,qBAAsB,EACtBC,sBAAuB,EACvBC,wBAAyB,EACzBC,qBAAsB,EACtBC,eAAgB,EAChBC,UAAW,KACXC,SAAU,EACVC,QAAS,KACTC,cAAe,KACfC,kBAAmB,EACnBC,aAAc,WACZ,MAAO,GAAAC,OAAGnB,KAAKoB,mBAARD,OAA4BnB,KAAKU,yBAAjC,GAAAS,OACGnB,KAAKoB,mBADRD,OAC4BnB,KAAKS,uBADjC,GAAAU,OAEGnB,KAAKoB,mBAFRD,OAE4BnB,KAAKc,UAFjC,GAAAK,OAGGnB,KAAKoB,mBAHRD,OAG4BnB,KAAKiB,mBAHjC,GAAAE,OAIGnB,KAAKoB,mBAJRD,OAI4BnB,KAAKO,gBAJjC,GAAAY,OAKGnB,KAAKoB,mBALRD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K1C,8BAMzC,WAAO,IAAA2C,EAAAjE,KACC6B,EAAgB7B,KAAKkE,kBAC3BrC,EAAcG,QAAQ,SAAAK,GAAI,OAAI4B,EAAKE,kBAAkB9B,KACrDrC,KAAKoE,2BAA2BvC,wCAIpCC,SAASsB,iBAAiB,mBAAoB,WAC5C,IAAMiB,EAAO,IAAIvE,EACjBwE,WAAW,WACTD,EAAKE,QAEL","file":"92-rtdv_icmib-48e63b5a2eff4643c751.js","sourcesContent":["\n// This script is designed to be used with the ICMIB survey. It will capture\n// real-time data from the user as they type into the open text fields. The\n// data will be stored in hidden input fields and submitted with the form.\n// The data will be stored in the following format:\n// {\n// \"questionId\": [\n// {\n// \"outputValue\": \"A1B2C3D4E5F6G7H8I9J10\",\n// \"value\": \"User input value\"\n// },\n// {\n// \"outputValue\": \"A1B2C3D4E5F6G7H8I9J10\",\n// \"value\": \"User input value\"\n// },\n// ...\n// ]\n// }\n\nclass RealTimeDataValidator {\n constructor() {\n this.questionIdHasManyMetadata = {\n questionId: \"\",\n metadata: []\n };\n this.metadata = {\n questionId: \"\",\n inputDomElement: null,\n firstChar: true,\n numberOfCharactersTyped: 0,\n maxPasteLength: 0,\n autoCompleteDetected: 0,\n numberOfKeyUpCountAll: 0,\n numberOfKeyDownCountAll: 0,\n pastedEntireResponse: 0,\n speechDetected: 0,\n startTime: null,\n timeDiff: 0,\n endTime: null,\n startTimeChar: null,\n timeDiffFirstChar: 0,\n outputString: function () {\n return `${this.randomCharacter()}${this.numberOfKeyDownCountAll}` +\n `${this.randomCharacter()}${this.numberOfKeyUpCountAll}` +\n `${this.randomCharacter()}${this.timeDiff}` +\n `${this.randomCharacter()}${this.timeDiffFirstChar}` +\n `${this.randomCharacter()}${this.maxPasteLength}` +\n `${this.randomCharacter()}${this.autoCompleteDetected}` +\n `${this.randomCharacter()}${this.speechDetected}` +\n `${this.randomCharacter()}${this.pastedEntireResponse}` +\n `${this.randomCharacter()}${this.inputDomElement.value.length}`;\n },\n randomCharacter: function () {\n const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n return characters.charAt(Math.floor(Math.random() * characters.length));\n }\n };\n }\n\n preloadMetaData() {\n const metadataArray = [];\n\n document.querySelectorAll('.Survey\\\\:\\\\:Open').forEach(container => {\n // the id looks like question_67a69032413b1900092572fd\n const questionId = container.getAttribute('id').split('_')[1];\n\n container.querySelectorAll('textarea[name^=\"questions[open\"]').forEach(inputField => {\n const meta = Object.create(this.metadata);\n meta.questionId = questionId;\n meta.inputDomElement = inputField;\n metadataArray.push(meta);\n });\n });\n return metadataArray;\n }\n\n populateQuestionIdHasManyMetadata(metadataArray) {\n const hasManyMetaDatas = [];\n // get the unique question ids from the metadataArray\n const questionIds = metadataArray.map(meta => meta.questionId);\n // remove duplicates\n const uniqueQuestionIds = [...new Set(questionIds)];\n // now iterate over the unique question ids\n uniqueQuestionIds.forEach(questionId => {\n // create a new questionIdHasManyMetadata object\n const questionIdHasManyMetadata = Object.create(this.questionIdHasManyMetadata);\n questionIdHasManyMetadata.questionId = questionId;\n\n const metadataForQuestion = metadataArray.filter(meta => meta.questionId === questionId);\n // now iterate over the metadata for this question\n metadataForQuestion.forEach(meta => {\n const inputLength = meta.inputDomElement.value.length;\n if (inputLength === meta.maxPasteLength) {\n meta.pastedEntireResponse = 1;\n }\n questionIdHasManyMetadata.metadata.push({outputValue: meta.outputString(), value: meta.inputDomElement.value});\n });\n hasManyMetaDatas.push(questionIdHasManyMetadata);\n });\n\n return hasManyMetaDatas;\n }\n\n handleMetadataOnFormSubmit(metadataArray) {\n // should only be one form per page\n //\n const formElement = document.querySelector('form');\n if (!formElement) {\n return;\n }\n\n formElement.addEventListener('submit', (_event) => {\n const allMetadata = this.populateQuestionIdHasManyMetadata(metadataArray);\n\n allMetadata.forEach(meta => {\n const hiddenInput = document.createElement('input');\n hiddenInput.setAttribute('type', 'hidden');\n hiddenInput.setAttribute('name', `metadata[${meta.questionId}]`);\n hiddenInput.setAttribute('value', JSON.stringify(meta.metadata));\n formElement.appendChild(hiddenInput);\n });\n });\n }\n\n addEventListeners(meta) {\n meta.inputDomElement.addEventListener('keyup', function (event) {\n meta.numberOfKeyUpCountAll++;\n });\n\n meta.inputDomElement.addEventListener('keydown', function (event) {\n if (meta.firstChar) {\n meta.firstChar = false;\n meta.startTimeChar = new Date();\n }\n meta.numberOfKeyDownCountAll++;\n });\n\n meta.inputDomElement.addEventListener('focus', function (event) {\n if (meta.startTime === null) {\n meta.startTime = new Date();\n }\n });\n\n meta.inputDomElement.addEventListener('blur', function (event) {\n meta.endTime = new Date();\n meta.timeDiff = meta.endTime - meta.startTime;\n meta.timeDiffFirstChar = meta.endTime - meta.startTimeChar;\n });\n\n meta.inputDomElement.addEventListener('input', function (event) {\n //Flagging assistive technology\n if (\n event.inputType === \"insertText\" &&\n event.data.split(\" \").length - 1 > 1\n ) {\n meta.autoCompleteDetected = 1;\n } else if (\n event.inputType === \"insertReplacementText\" ||\n (event.data && event.data.length > 1 && event.inputType === \"insertText\")\n ) {\n autoCompleteDetected = 1;\n }\n //Flagging speech to text\n if (event.inputType === \"insertCompositionText\") {\n if ( event.data.split(\" \").length > 1 ) {\n meta.speechDetected = 1;\n };\n };\n //Adjust paste length on paste\n if (event.inputType === \"insertFromPaste\") {\n if (event.data.length > meta.maxPasteLength) {\n meta.maxPasteLength = event.data.length;\n };\n };\n });\n }\n\n init() {\n const metadataArray = this.preloadMetaData();\n metadataArray.forEach(meta => this.addEventListeners(meta));\n this.handleMetadataOnFormSubmit(metadataArray);\n }\n}\n\ndocument.addEventListener('DOMContentLoaded', function () {\n const rtdv = new RealTimeDataValidator();\n setTimeout(() => {\n rtdv.init();\n }\n , 100);\n});\n"],"sourceRoot":""}