{"version":3,"sources":["webpack:///./app/javascript/packs/initializers/initializeCommentPreview.js","webpack:///./app/javascript/utilities/localDateTime.js","webpack:///./app/javascript/packs/initializers/initializeCommentDate.js","webpack:///./app/javascript/packs/baseInitializers.js"],"names":["getAndShowPreview","preview","editor","payload","JSON","stringify","comment","body_markdown","value","getCsrfToken","then","sendFetch","response","json","body","script","innerHTML","processed_html","includes","document","createElement","src","async","appendChild","activateRunkitTags","err","console","log","handleCommentPreview","event","preventDefault","form","target","getElementsByClassName","trigger","classList","contains","toggle","editorHeight","offsetHeight","style","minHeight","initializeCommentPreview","previewButton","addEventListener","timestampToLocalDateTime","timestamp","locale","options","time","Date","formattedTime","Intl","DateTimeFormat","format","year","replace","e","timestampToLocalDateTimeLong","navigator","language","weekday","month","day","hour","minute","second","initializeCommentDate","commentsDates","querySelectorAll","elements","timestampAttribute","i","length","element","getAttribute","localDateTime","setAttribute","addLocalizedDateTimeToElementsTitles","globalThis","timestampToLocalDateTimeShort","currentYear","getFullYear","timeOptions"],"mappings":"iGAEA,SAASA,EAAkBC,EAASC,GAmBlC,IAAMC,EAAUC,KAAKC,UAAU,CAC7BC,QAAS,CACPC,cAAeL,EAAOM,SAG1BC,eACGC,KAAKC,UAAU,kBAAmBR,IAClCO,MAAK,SAACE,GACL,OAAOA,EAASC,MAClB,IACCH,MAlBH,SAAmBI,GAVnB,IACQC,EAUNd,EAAQe,UAAYF,EAAKG,eACrBH,EAAKG,eAAeC,SAAS,uBAX3BH,EAASI,SAASC,cAAc,WAC/BC,IAAM,0CACbN,EAAOO,OAAQ,EACfH,SAASL,KAAKS,YAAYR,IAW1BS,oBACF,IAYkB,OACT,SAACC,GACNC,QAAQC,IAAI,UACZD,QAAQC,IAAIF,EACd,GACJ,CAEA,SAASG,EAAqBC,GAC5BA,EAAMC,iBACN,IAAQC,EAASF,EAAMG,OAAfD,KACF7B,EAAS6B,EAAKE,uBAAuB,oBAAoB,GACzDhC,EAAU8B,EAAKE,uBAAuB,yBAAyB,GA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AfW,aACTA,WAAWrB,6BAA+BA,EAC1CqB,WAAWC,8BAzBb,SAAuClC,GAIrC,GAAIA,EAAW,CACb,IAAMmC,GAAc,IAAI/B,MAAOgC,cAGzBC,EAAc,CAClBpB,IAAK,UACLD,MAAO,SAOT,OAXkB,IAAIZ,KAAKJ,GAAWoC,gBAOpBD,IAChBE,EAAY5B,KAAO,WAGdV,EAAyBC,EAAWa,UAAUC,SAAUuB,EACjE,CAEA,MAAO,EACT,E,mCErGA,6BAGAhB,kCACAzB,oC","file":"js/baseInitializers-3c0110af063b08187acd.chunk.js","sourcesContent":["/* global activateRunkitTags */\n\nfunction getAndShowPreview(preview, editor) {\n function attachTwitterTimelineScript() {\n const script = document.createElement('script');\n script.src = 'https://platform.twitter.com/widgets.js';\n script.async = true;\n document.body.appendChild(script);\n return () => {\n document.body.removeChild(script);\n };\n }\n\n function successCb(body) {\n preview.innerHTML = body.processed_html; // eslint-disable-line no-param-reassign\n if (body.processed_html.includes('twitter-timeline')) {\n attachTwitterTimelineScript();\n }\n activateRunkitTags();\n }\n\n const payload = JSON.stringify({\n comment: {\n body_markdown: editor.value,\n },\n });\n getCsrfToken()\n .then(sendFetch('comment-preview', payload))\n .then((response) => {\n return response.json();\n })\n .then(successCb)\n .catch((err) => {\n console.log('error!'); // eslint-disable-line\n console.log(err); // eslint-disable-line no-console\n });\n}\n\nfunction handleCommentPreview(event) {\n event.preventDefault();\n const { form } = event.target;\n const editor = form.getElementsByClassName('comment-textarea')[0];\n const preview = form.getElementsByClassName('comment-form__preview')[0];\n const trigger = form.getElementsByClassName('preview-toggle')[0];\n\n if (editor.value !== '') {\n if (form.classList.contains('preview-open')) {\n form.classList.toggle('preview-open');\n trigger.innerHTML = 'Preview';\n } else {\n getAndShowPreview(preview, editor);\n const editorHeight = editor.offsetHeight + 43; // not ideal but prevents jumping screen\n preview.style.minHeight = `${editorHeight}px`;\n trigger.innerHTML = 'Continue editing';\n form.classList.toggle('preview-open');\n }\n }\n}\n\nexport function initializeCommentPreview() {\n const previewButton = document.getElementsByClassName('preview-toggle')[0];\n\n if (!previewButton) {\n return;\n }\n\n previewButton.addEventListener('click', handleCommentPreview);\n}\n","/* Local date/time utilities */\n\n/*\n Convert string timestamp to local time, using the given locale.\n\n timestamp should be something like '2019-05-03T16:02:50.908Z'\n locale can be `navigator.language` or a custom locale. defaults to 'default'\n options are `Intl.DateTimeFormat` options\n\n see \n for more information.\n*/\nexport function timestampToLocalDateTime(timestamp, locale, options) {\n if (!timestamp) {\n return '';\n }\n\n try {\n const time = new Date(timestamp);\n const formattedTime = new Intl.DateTimeFormat(\n locale || 'default',\n options,\n ).format(time);\n return options.year === '2-digit'\n ? formattedTime.replace(', ', \" '\")\n : formattedTime;\n } catch (e) {\n return '';\n }\n}\n\nexport function addLocalizedDateTimeToElementsTitles(elements, timestampAttribute) {\n for (let i = 0; i < elements.length; i += 1) {\n const element = elements[i];\n\n // get UTC timestamp set by the server\n const timestamp = element.getAttribute(timestampAttribute || 'datetime');\n\n if (timestamp) {\n // add a full datetime to the element title, visible on hover.\n // `navigator.language` is used to allow the date to be localized\n // according to the browser's locale\n // see \n const localDateTime = timestampToLocalDateTimeLong(timestamp);\n element.setAttribute('title', localDateTime);\n }\n }\n}\n\nexport function localizeTimeElements(elements, timeOptions) {\n for (let i = 0; i < elements.length; i += 1) {\n const element = elements[i];\n\n const timestamp = element.getAttribute('datetime');\n if (timestamp) {\n const localDateTime = timestampToLocalDateTime(\n timestamp,\n navigator.language,\n timeOptions,\n );\n\n element.textContent = localDateTime;\n }\n }\n}\n\nfunction timestampToLocalDateTimeLong(timestamp) {\n // example: \"Wednesday, April 3, 2019, 2:55:14 PM\"\n\n return timestampToLocalDateTime(timestamp, navigator.language, {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n });\n}\n\nfunction timestampToLocalDateTimeShort(timestamp) {\n // example: \"10 Dec 2018\" if it is not the current year\n // example: \"6 Sep\" if it is the current year\n\n if (timestamp) {\n const currentYear = new Date().getFullYear();\n const givenYear = new Date(timestamp).getFullYear();\n\n const timeOptions = {\n day: 'numeric',\n month: 'short',\n };\n\n if (givenYear !== currentYear) {\n timeOptions.year = 'numeric';\n }\n\n return timestampToLocalDateTime(timestamp, navigator.language, timeOptions);\n }\n\n return '';\n}\n\nif (typeof globalThis !== 'undefined') {\n globalThis.timestampToLocalDateTimeLong = timestampToLocalDateTimeLong; // eslint-disable-line no-undef\n globalThis.timestampToLocalDateTimeShort = timestampToLocalDateTimeShort; // eslint-disable-line no-undef\n}\n","import { addLocalizedDateTimeToElementsTitles } from \"../../utilities/localDateTime\";\n\nexport function initializeCommentDate() {\n const commentsDates = document.querySelectorAll('.comment-date time');\n\n if (commentsDates) {\n addLocalizedDateTimeToElementsTitles(commentsDates, 'datetime');\n }\n}\n","import { initializeCommentDate } from './initializers/initializeCommentDate';\nimport { initializeCommentPreview } from './initializers/initializeCommentPreview';\n\ninitializeCommentDate();\ninitializeCommentPreview();\n"],"sourceRoot":""}