{"version":3,"sources":["webpack:///./widgets/export-citations/js/export-citations.js"],"names":["exportCitation","UX","configureCiteprocOptions","citeproc","opt","development_extensions","wrap_url_and_doi","field_hack","mode","processCslResponseData","downloadContainer","$target","find","downloadData","length","html","test","text","downloadMultiText","isCSV","selectCiteStyle","each","$this","$","this","handleExportCitation","$el","largeQuery","selectedFormat","targetCustomCSLFIle","citationType","action_server","isLargeCitation","query","limit","batchSize","empty","$wrapper","closest","disableButtonsAndDropdown","addClass","parent","css","attr","showLoadingMessage","loadingText","loadingAdditionalInfo","params","setParams","performServerSideAjax","setFormValues","val","dois","url","ajax","data","async","type","success","response","processResponse","result","itemIDs","items","forEach","item","key","push","includesDbPubItem","show","hide","responseFormat","citeprocSys","retrieveLocale","lang","locale","retrieveItem","index","indexOf","CSL","Engine","style","updateItems","makeBibliography","content","setContent","downloadCiteProc","unProcessedChunks","formatObject","resultsArray","global","xhr","last_index","XMLHttpRequest","loopIndex","onprogress","e","responseText","includes","$export__warning","document","querySelector","classList","add","innerText","curr_index","slideDown","chunk","substring","completeJsons","split","_loop","innerItems","parsedJson","JSON","parse","i","getDataChunkBlob","universalBOM","is","additionalDownloadDataFormat","contentType","Uint8Array","dataArray","TextEncoder","encode","combinedArray","set","blob","Blob","console","error","endsWith","complete","downloadLargeCiteProc","bolbArray","_toConsumableArray","downloadAnchorTag","createElement","href","URL","createObjectURL","download","fileName","suffix","body","appendChild","click","removeChild","collectDois","doisArray","multiDois","doiArticle","hasClass","$multiToggle","doiValue","doiVal","binderVal","$trigger","targetFile","format","binderCode","isLarge","removeClass","removeAttr","warning","getWarningMessage","concat","encodeURIComponent","control","on","resetPopup","toString","loadCiteProc","$toggle","preventDefault"],"mappings":"uHAGMA,G,cAAiBC,GAAGD,gBAAkB,IAG5C,SAASE,yBAAyBC,GAC9BA,EAASC,IAAIC,uBAAuBC,kBAAmB,EACvDH,EAASC,IAAIC,uBAAuBE,YAAa,EACjDJ,EAASC,IAAII,KAAO,OA6CxB,SAASC,yBAC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EAAId,KAAK,oBAAoBuC,MAC7DvB,EAAiBL,EAAE,gBAAkBvB,EAAeoB,gBAAkB,KAAKmC,KAAK,UAC5E1B,EAAsB,UAAY7B,EAAeoB,gBACtDU,EAAeJ,EAAId,KAAK,2CAA2CuC,MACnE1B,qBACIC,EACAC,EACAC,EACAC,EACAC,EApBc,iCAsBdE,EACAC,EACAC,EACAC","file":"js/exportCitation-fb869072e9a66ab7e246.js","sourcesContent":["import 'ui-core/widgets/export-citations/js/export-citations';\nimport 'ui-core/plugins/citeProc/js/citeproc.min';\n\nconst exportCitation = UX.exportCitation || {};\n\n//Shared Citeproc Options\nfunction configureCiteprocOptions(citeproc) {\n citeproc.opt.development_extensions.wrap_url_and_doi = false;\n citeproc.opt.development_extensions.field_hack = false;\n citeproc.opt.mode = 'text';\n}\n\n// handles normal requests (not large citations)\nfunction processResponse(response, selectCiteStyle) {\n const itemIDs = [];\n let citeproc;\n let result;\n\n exportCitation.response = response;\n\n exportCitation.response.items.forEach(function (item) {\n for (let key in item) {\n itemIDs.push(key);\n }\n\n if (response.includesDbPubItem === true) {\n $('.formats').show();\n } else {\n $('.formats').hide();\n }\n });\n\n exportCitation.responseFormat[selectCiteStyle] = exportCitation.response;\n\n let citeprocSys = {\n retrieveLocale: function (lang) {\n return exportCitation.response.locale;\n },\n retrieveItem: function (key) {\n let index = itemIDs.indexOf(key);\n return exportCitation.response.items[index][key];\n },\n };\n\n citeproc = new UX.CSL.Engine(citeprocSys, exportCitation.response.style);\n configureCiteprocOptions(citeproc);\n\n citeproc.updateItems(itemIDs);\n result = citeproc.makeBibliography();\n exportCitation.responseFormat[selectCiteStyle].content = result[1];\n exportCitation.setContent(exportCitation.responseFormat[selectCiteStyle].content, false);\n exportCitation.downloadCiteProc();\n}\n\nfunction processCslResponseData() {\n let downloadContainer = exportCitation.$target.find('.csl-response'),\n downloadData = '';\n\n if (exportCitation.$target.find('.csl-right-inline').length) {\n downloadContainer = exportCitation.$target.find('.csl-right-inline');\n downloadData = downloadContainer.html();\n\n if (/<\\/?[a-z][\\s\\S]*>/i.test(downloadContainer.html())) {\n downloadData = downloadContainer.text();\n }\n } else if (exportCitation.$target.find('.csl-entry').length) {\n downloadContainer = exportCitation.$target.find('.csl-entry');\n downloadData = downloadContainer.html();\n if (/<\\/?[a-z][\\s\\S]*>/i.test(downloadContainer.html())) {\n downloadData = downloadContainer.text();\n }\n }\n\n if (downloadContainer.length > 1) {\n let downloadMultiText = '';\n let isCSV = exportCitation.selectCiteStyle === 'csv';\n\n downloadContainer.each(function () {\n let $this = $(this);\n\n if (isCSV) {\n if (/<\\/?[a-z][\\s\\S]*>/i.test($this.html())) {\n downloadMultiText += $this.text() + '\\n';\n } else {\n downloadMultiText += $this.html() + '\\n';\n }\n } else {\n if (/<\\/?[a-z][\\s\\S]*>/i.test($this.html())) {\n downloadMultiText += $this.text() + '\\n\\n';\n } else {\n downloadMultiText += $this.html() + '\\n\\n';\n }\n }\n });\n downloadData = downloadMultiText;\n }\n\n return downloadData;\n}\n\nfunction setFormValues($el, selectedFormat) {\n exportCitation.$wrapper.find('[name=\"dois\"]').val(exportCitation.dois);\n exportCitation.$wrapper.find('[name=\"format\"]').val(selectedFormat);\n}\n\nfunction getDataChunkBlob(index) {\n let downloadContainer = exportCitation.$target,\n downloadData = '',\n universalBOM = '';\n\n if (downloadContainer.is('.csl-response')) {\n downloadData = processCslResponseData();\n }\n\n downloadData = exportCitation.additionalDownloadDataFormat(downloadData);\n\n if (exportCitation.responseFormat[exportCitation.selectCiteStyle].contentType === 'text/csv' && index === 0) {\n universalBOM = new Uint8Array([0xef, 0xbb, 0xbf]);\n } else {\n universalBOM = '';\n }\n\n // Convert downloadData to a Uint8Array\n const dataArray = new TextEncoder().encode(downloadData);\n\n // Combine BOM and downloadData arrays\n const combinedArray = new Uint8Array(universalBOM.length + dataArray.length);\n combinedArray.set(universalBOM, 0);\n combinedArray.set(dataArray, universalBOM.length);\n\n // Create a Blob containing the data\n const blob = new Blob([combinedArray], {\n type: exportCitation.responseFormat[exportCitation.selectCiteStyle].contentType,\n });\n\n exportCitation.$target.empty();\n return blob;\n}\n\nfunction downloadLargeCiteProc(bolbArray) {\n // Create a Blob containing the data\n const blob = new Blob([...bolbArray], {\n type: exportCitation.responseFormat[exportCitation.selectCiteStyle].contentType,\n });\n\n // Create a link element\n const downloadAnchorTag = document.createElement('a');\n downloadAnchorTag.href = URL.createObjectURL(blob);\n downloadAnchorTag.download =\n exportCitation.responseFormat[exportCitation.selectCiteStyle].fileName +\n '.' +\n exportCitation.responseFormat[exportCitation.selectCiteStyle].suffix;\n\n // Append the link to the document (you can remove it after the download)\n document.body.appendChild(downloadAnchorTag);\n\n // Trigger the download\n downloadAnchorTag.click();\n\n // Remove the link from the document\n document.body.removeChild(downloadAnchorTag);\n}\n\nfunction showLoadingMessage($el) {\n const loadingText = 'Loading ' + exportCitation.loadingAdditionalInfo + '... ';\n exportCitation.$target.html('' + loadingText + '');\n}\n\nfunction disableButtonsAndDropdown($el) {\n exportCitation.$wrapper.find('.copy__btn, .download__btn').addClass('disabled').parent('li').css('cursor', '');\n exportCitation.$wrapper.find('#citation-format').attr('disabled', 'disabled');\n}\n\nfunction handleExportCitation(\n $el,\n largeQuery,\n selectedFormat,\n targetCustomCSLFIle,\n citationType,\n action_server,\n isLargeCitation,\n query,\n limit,\n batchSize\n) {\n $('#export-warning').empty();\n exportCitation.$wrapper = $el.closest('.csl-wrapper');\n exportCitation.$target = exportCitation.$wrapper.find('.csl-response');\n\n if (exportCitation.selectCiteStyle) {\n disableButtonsAndDropdown($el);\n showLoadingMessage($el);\n const params = exportCitation.setParams(\n targetCustomCSLFIle,\n selectedFormat,\n citationType,\n isLargeCitation,\n query,\n limit,\n batchSize,\n largeQuery\n );\n exportCitation.performServerSideAjax(action_server, params, exportCitation.selectCiteStyle);\n setFormValues($el, selectedFormat);\n }\n}\n\n//TODO: code clean up in LIT-550330\nexportCitation.performServerSideAjax = function (url, params, selectCiteStyle) {\n if (!params.isLargeCitation) {\n return $.ajax({\n // url: '/specs/products/cabi/widgets/export-citations/js/dummy-csl-metaData.json', // local testing\n url,\n data: params,\n async: true,\n type: 'GET',\n success: function (response) {\n processResponse(response, selectCiteStyle);\n },\n });\n } else {\n let unProcessedChunks = '';\n const formatObject = [];\n let resultsArray = [];\n\n $.ajax({\n // url: '/specs/products/cabi/widgets/export-citations/js/dummy-csl-metaData.json', // local testing\n url,\n data: params,\n type: 'GET',\n async: true,\n global: false,\n xhr: function () {\n var last_index = 0;\n var xhr = new XMLHttpRequest();\n var loopIndex = 0;\n\n xhr.onprogress = function (e) {\n const responseData = xhr.responseText.includes(`\"status\": \"failed\"`);\n if (!responseData) {\n var curr_index = xhr.responseText.length;\n $('.export__info').slideDown();\n\n if (last_index === curr_index) return;\n\n var chunk = xhr.responseText.substring(last_index, curr_index);\n last_index = curr_index;\n\n unProcessedChunks += chunk;\n\n if (unProcessedChunks.includes('endOfJson')) {\n let completeJsons = unProcessedChunks.split('endOfJson');\n\n if (formatObject.length !== 0) {\n for (let i = 0; i < completeJsons.length - 1; i++) {\n try {\n const itemIDs = [];\n let innerItems = [];\n let citeproc;\n let result;\n\n let parsedJson = JSON.parse(completeJsons[i]);\n\n parsedJson.items.forEach(function (item) {\n for (let key in item) {\n itemIDs.push(key);\n }\n });\n\n exportCitation.responseFormat[selectCiteStyle] = formatObject[0];\n\n let citeprocSys = {\n retrieveLocale: function (lang) {\n return formatObject[0].locale;\n },\n retrieveItem: function (key) {\n parsedJson.items.forEach(function (item) {\n innerItems.push(item);\n });\n let index = itemIDs.indexOf(key);\n return innerItems[index][key];\n },\n };\n\n citeproc = new UX.CSL.Engine(\n citeprocSys,\n exportCitation.responseFormat[selectCiteStyle].style\n );\n configureCiteprocOptions(citeproc);\n citeproc.updateItems(itemIDs);\n result = citeproc.makeBibliography();\n exportCitation.responseFormat[selectCiteStyle].content = result[1];\n exportCitation.setContent(\n exportCitation.responseFormat[selectCiteStyle].content,\n true\n );\n\n // Store each chunk after processing the data as blob\n resultsArray.push(getDataChunkBlob(loopIndex));\n loopIndex++;\n } catch (e) {\n console.error('Parsing error:', e);\n }\n }\n }\n\n if (formatObject.length === 0) {\n formatObject.push(JSON.parse(completeJsons[0]));\n }\n\n unProcessedChunks = !unProcessedChunks.endsWith('endOfJson')\n ? completeJsons[completeJsons.length - 1]\n : '';\n }\n } else {\n const $export__warning = document.querySelector('#export-warning');\n $export__warning.classList.add('unavailable');\n $export__warning.innerText = 'Bulk citation is not available, Please try again in one hour';\n }\n };\n\n return xhr;\n },\n complete: function () {\n if (resultsArray.length) {\n downloadLargeCiteProc(resultsArray);\n } else {\n const $export__warning = document.querySelector('#export-warning');\n $export__warning.classList.add('unavailable');\n $export__warning.innerText = 'Bulk citation is not available, Please try again in one hour';\n }\n },\n });\n }\n};\n\nexportCitation.collectDois = function ($el) {\n const doisArray = [];\n let multiDois = false;\n const doiArticle = $('header [data-single-doi]');\n if ($el.hasClass('export-citation') && !doiArticle.length) {\n multiDois = true;\n }\n\n if (multiDois) {\n exportCitation.$multiToggle = $('.issue-Item__checkbox:checked');\n exportCitation.$multiToggle.each(function () {\n const $this = $(this);\n const doiValue = $this.attr('name') === 'doi' ? $this.val() : $this.attr('name');\n doisArray.push(doiValue);\n });\n } else {\n const doiVal = $el.find('[name=\"doiVal\"]');\n const binderVal = $el.find('[name=\"binderCode\"]');\n if (doiVal.length) {\n doiVal.each(function () {\n doisArray.push($(this).val());\n });\n } else if (binderVal.length) {\n binderVal.each(function () {\n doisArray.push($(this).val());\n });\n } else if (doiArticle.length) {\n doisArray.push(doiArticle.data('single-doi'));\n }\n }\n\n return doisArray;\n};\n\nexportCitation.setParams = function (\n targetCustomCSLFIle,\n selectedFormat,\n type,\n isLargeCitation,\n query,\n limit,\n batchSize,\n largeQuery\n) {\n if (\n (exportCitation.$trigger.find('[name=\"doiVal\"]').length || exportCitation.$trigger.is('.export-citation')) &&\n !isLargeCitation\n ) {\n return {\n dois: exportCitation.dois,\n targetFile: targetCustomCSLFIle,\n format: selectedFormat,\n citationType: type,\n largeQuery: largeQuery,\n };\n } else if (isLargeCitation) {\n return {\n dois: exportCitation.dois,\n targetFile: targetCustomCSLFIle,\n format: selectedFormat,\n citationType: type,\n query,\n isLargeCitation,\n limit,\n batchSize,\n largeQuery: largeQuery,\n };\n } else if (exportCitation.$trigger.find('[name=\"binderCode\"]').length) {\n return {\n binderCode: exportCitation.dois,\n targetFile: targetCustomCSLFIle,\n format: selectedFormat,\n citationType: type,\n };\n }\n};\n\nexportCitation.setContent = function (content, isLarge) {\n exportCitation.$target.html(content);\n exportCitation.$wrapper.find('[name=\"content\"]').val(exportCitation.$target.text());\n if (!isLarge) {\n exportCitation.$wrapper\n .find('.copy__btn, .download__btn')\n .removeClass('disabled')\n .parent('li')\n .css('cursor', 'pointer');\n }\n\n exportCitation.$wrapper.find('#citation-format').removeAttr('disabled');\n if (exportCitation.responseFormat[exportCitation.selectCiteStyle].warning) {\n exportCitation.$wrapper\n .find('#export-warning')\n .html(\n exportCitation.getWarningMessage(exportCitation.responseFormat[exportCitation.selectCiteStyle].warning)\n );\n }\n};\n\nexportCitation.downloadCiteProc = function () {\n let $el = $('.download__btn:not(.allResults)'),\n downloadContainer = exportCitation.$target,\n downloadData = '',\n universalBOM = '';\n\n if (downloadContainer.is('.csl-response')) {\n downloadData = processCslResponseData();\n }\n downloadData = exportCitation.additionalDownloadDataFormat(downloadData);\n\n if (exportCitation.responseFormat[exportCitation.selectCiteStyle].contentType === 'text/csv') {\n universalBOM = '%EF%BB%BF';\n }\n\n $el.attr(\n 'href',\n 'data:' +\n exportCitation.responseFormat[exportCitation.selectCiteStyle].contentType +\n `;charset=utf-8,${universalBOM}` +\n encodeURIComponent(downloadData)\n );\n $el.attr(\n 'download',\n exportCitation.responseFormat[exportCitation.selectCiteStyle].fileName +\n '.' +\n exportCitation.responseFormat[exportCitation.selectCiteStyle].suffix\n );\n};\n\nexportCitation.control = function () {\n $(document).on('click', '[data-target=\"#exportCitation\"]', function () {\n exportCitation.$trigger = $(this);\n exportCitation.resetPopup(exportCitation.$trigger);\n exportCitation.dois = exportCitation.collectDois(exportCitation.$trigger).toString();\n exportCitation.loadCiteProc(exportCitation.$toggle.closest('.copy__text-wrapper'), $(this));\n });\n\n $(document).on('change', '#citation-format, .export-citation__formats input', function () {\n exportCitation.loadCiteProc($(this).closest('.copy__text-wrapper'), $(this));\n });\n\n $(document).on('click', '.download__btn.allResults:not(.disabled)', function (e) {\n e.preventDefault();\n exportCitation.loadCiteProc($(this).closest('.copy__text-wrapper'), $(this));\n });\n\n $(document).on('click', '.allResults.disabled', function (e) {\n e.preventDefault();\n });\n\n $(document).on('click', '#exportCitation .close', function () {\n $('#citationOnly').click();\n });\n\n $(document).on('click', '.export-citation__formats-all input[type=\"radio\"]', function () {\n $('.export__warning').hide();\n $(this).closest('.input-group').find('.export__warning').show();\n });\n};\n\nexportCitation.loadCiteProc = function ($el, $this) {\n const action_server = '/action/exportCiteProcCitation';\n let selectedFormat,\n targetCustomCSLFIle,\n citationType,\n largeQuery = '',\n isLargeCitation = false,\n query = '',\n limit = '',\n batchSize = '';\n\n if (!$this.hasClass('allResults')) {\n exportCitation.selectCiteStyle = $el.find('#citation-format').val();\n (selectedFormat = $('option[value=' + exportCitation.selectCiteStyle + ']').data('format')),\n (targetCustomCSLFIle = 'custom-' + exportCitation.selectCiteStyle);\n citationType = $el.find('.export-citation__formats input:checked').val();\n handleExportCitation(\n $el,\n largeQuery,\n selectedFormat,\n targetCustomCSLFIle,\n citationType,\n action_server,\n isLargeCitation,\n query,\n limit,\n batchSize\n );\n } else {\n isLargeCitation = true;\n query = $this.attr('href');\n limit = $this.attr('data-limit');\n batchSize = $this.attr('data-batch');\n largeQuery = $this.attr('data-largeQuery');\n\n exportCitation.selectCiteStyle = $el.find('#all-citation-format').val();\n selectedFormat = $el\n .find('#all-citation-format option[value=' + exportCitation.selectCiteStyle + ']')\n .data('format');\n targetCustomCSLFIle = 'custom-' + exportCitation.selectCiteStyle;\n citationType = $el.find('.export-citation__formats-all input:checked').val();\n handleExportCitation(\n $el,\n largeQuery,\n selectedFormat,\n targetCustomCSLFIle,\n citationType,\n action_server,\n isLargeCitation,\n query,\n limit,\n batchSize\n );\n }\n};\n"],"sourceRoot":""}