PageSourceSearch

https://www.zvazslovenskeholyzovania.sk/wp-content/plugins/pdfjs-v…/pdfjs-media-button.js?ver=3.1.1

js zvazslovenskeholyzovania.sk collected 2026-10-02 17:23:34 UTC 2,994 bytes, 109 lines download raw bytes

1jQuery( function( $ ) {
2	$( '.js-insert-pdfjs' ).click( PDFjs_openMediaWindow );
3
4	if ( typeof acf !== 'undefined' ) {
5		acf.addAction( 'load', function() {
6			$( '.js-insert-pdfjs' ).on( 'click', function() {
7				PDFjs_openMediaWindow();
8			} );
9		} );
10	}
11
12	function PDFjs_openMediaWindow() {
13		const frame = wp.media( {
14			title: wp.i18n.__( 'Insert a PDF', 'pdfjs-viewer-shortcode' ),
15			library: { type: 'application/pdf' },
16			multiple: false,
17			button: { text: wp.i18n.__( 'Insert', 'pdfjs-viewer-shortcode' ) },
18		} );
19
20		frame.on( 'select', function() {
21			let selectionID = frame
22				.state()
23				.get( 'selection' )
24				.first()
25				.toJSON().id;
26			let selectionURL = frame
27				.state()
28				.get( 'selection' )
29				.first()
30				.toJSON().url;
31
32			// Sanitize URL: remove potential HTML/JavaScript while preserving valid URL structure
33			// WordPress media URLs use standard HTTP(S) and don't contain script tags or HTML
34			selectionURL = selectionURL.replace(
35				/<script[^>]*>.*?<\/script>/gi,
36				''
37			); // Remove script tags
38			selectionURL = selectionURL.replace( /on\w+\s*=/gi, '' ); // Remove event handlers
39			// Escape double quotes for use in HTML shortcode attribute (URL encoding safe)
40			selectionURL = selectionURL.replace( /"/g, '&quot;' );
41
42			let fullscreenLink = 'fullscreen=false';
43			if (
44				typeof window.pdfjs_options.pdfjs_fullscreen_link !==
45					'undefined' &&
46				window.pdfjs_options.pdfjs_fullscreen_link !== ''
47			) {
48				fullscreenLink = 'fullscreen=true';
49			}
50
51			let downloadLink = 'download=false';
52			if (
53				typeof window.pdfjs_options.pdfjs_download_button !==
54					'undefined' &&
55				window.pdfjs_options.pdfjs_download_button !== ''
56			) {
57				downloadLink = 'download=true';
58			}
59
60			let printLink = 'print=false';
61			if (
62				typeof window.pdfjs_options.pdfjs_print_button !==
63					'undefined' &&
64				window.pdfjs_options.pdfjs_print_button !== ''
65			) {
66				printLink = 'print=true';
67			}
68
69			let viewerWidth = '100%';
70			if (
71				typeof window.pdfjs_options.pdfjs_embed_width !== 'undefined' &&
72				window.pdfjs_options.pdfjs_embed_width !== '0' &&
73				window.pdfjs_options.pdfjs_embed_width !== ''
74			) {
75				viewerWidth = window.pdfjs_options.pdfjs_embed_width + 'px';
76			}
77
78			let viewerHeight = '800px';
79			if (
80				typeof window.pdfjs_options.pdfjs_embed_height !==
81					'undefined' &&
82				window.pdfjs_options.pdfjs_embed_height !== '0' &&
83				window.pdfjs_options.pdfjs_embed_height !== ''
84			) {
85				viewerHeight = window.pdfjs_options.pdfjs_embed_height + 'px';
86			}
87
88			wp.media.editor.insert(
89				'[pdfjs-viewer url="' +
90					selectionURL +
91					'" attachment_id="' +
92					selectionID +
93					'" viewer_width=' +
94					viewerWidth +
95					' viewer_height=' +
96					viewerHeight +
97					' ' +
98					fullscreenLink +
99					' ' +
100					downloadLink +
101					' ' +
102					printLink +
103					']'
104			);
105		} );
106
107		frame.open();
108	}
109} );

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.