1/** 2 * Apply options from anchor tag data-* attributes to the PDF viewer 3 * config, overriding defaults set in the admin settings panel. 4 * @param {Object} config PDF viewer configuration. 5 * @param {DOMStringMap} dataAttributes PDF link anchor tag attributes. 6 */ 7function applyDataAttributesToViewerConfig(config, dataAttributes) { 8 if (dataAttributes?.fit === "horizontal") { 9 config.defaultViewMode = "FIT_WIDTH"; 10 } else if (dataAttributes?.fit === "vertical") { 11 config.defaultViewMode = "FIT_PAGE"; 12 } 13 14 if (dataAttributes?.exitType === "close") { 15 config.exitPDFViewerType = "CLOSE"; 16 } else if (dataAttributes?.exitType === "return") { 17 config.exitPDFViewerType = "RETURN"; 18 } 19 20 if (dataAttributes?.downloadButton === "show") { 21 config.showDownloadPDF = true; 22 } else if (dataAttributes?.downloadButton === "hide") { 23 config.showDownloadPDF = false; 24 } 25 26 if (dataAttributes?.printButton === "show") { 27 config.showPrintPDF = true; 28 } else if (dataAttributes?.printButton === "hide") { 29 config.showPrintPDF = false; 30 } 31 32 if (dataAttributes?.dockControls === "dock") { 33 config.dockPageControls = true; 34 } else if (dataAttributes?.dockControls === "undock") { 35 config.dockPageControls = false; 36 } 37} 38 39/** 40 * Create object used to configure the PDF modal's UI. 41 * @param {Object} link Anchor tag object; may include data attributes. 42 * @returns Configuration object for PDF modal. 43 */ 44function getPDFModalConfiguration(link) { 45 // Get defaults from admin settings 46 const viewerConfig = { 47 embedMode: "LIGHT_BOX", 48 defaultViewMode: adminSettings.initial_page_view, 49 exitPDFViewerType: adminSettings.exit_type, 50 showDownloadPDF: !!adminSettings.enable_download, 51 showPrintPDF: !!adminSettings.enable_print, 52 }; 53 54 // Override defaults with data attributes 55 applyDataAttributesToViewerConfig(viewerConfig, link.dataset); 56 57 return viewerConfig; 58} 59 60/** 61 * If file name is set in a data attribute, get this name. Otherwise, 62 * parse name from PDF's URI. 63 * @param {Object} link Anchor tag object; may include data attributes. 64 * @returns String to be used as PDF file name. 65 */ 66function getFileName(link) { 67 return link.dataset.fileName 68 ? (fileName = link.dataset.fileName) 69 : (fileName = link["data-pdf-url"].split("/").pop()); 70} 71 72/** 73 * Display a PDF modal using the Adobe PDF Embed API. 74 * @param {Object} link Link to PDF (entire anchor tag object). 75 */ 76function viewPDFModal(link) { 77 const adobeDCView = new AdobeDC.View({ 78 clientId: adminSettings.client_id, 79 divId: "adobe-dc-view", 80 reportSuiteId: adminSettings?.adobe_analytics, 81 }); 82 83 adobeDCView.previewFile( 84 { 85 content: { 86 location: { 87 url: link["data-pdf-url"], 88 }, 89 }, 90 metaData: { 91 fileName: getFileName(link), 92 }, 93 }, 94 getPDFModalConfiguration(link) 95 ); 96} 97 98document.addEventListener("adobe_dc_view_sdk.ready", function (event) { 99 if (event.window !== document.parent || event?.origin && event.origin !== 'https://documentcloud.adobe.com/') { 100 return; 101 } 102 103 let anchorCount = 0; 104 105 $('a[href$=".pdf"], a[href$=".PDF"]').each(function () { 106 // Store PDF URI (for Adobe PDF Embed API) 107 this["data-pdf-url"] = this.href; 108 109 // Give anchor unique name, in case of multiple anchors to same pdf 110 anchorCount += 1; 111 const uniquePDFAnchorName = `${anchorCount}_` + $(this).text(); 112 this.name = uniquePDFAnchorName; 113 114 // Create direct link to named anchor (so page scrolls to anchor) 115 this.href = "#" + uniquePDFAnchorName; 116 117 $(this).attr("onclick", "viewPDFModal(this)"); 118 }); 119});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.