PageSourceSearch

https://cloud.medianeira.pr.gov.br/apps/files_pdfviewer/js/previewplugin.js?v=333d7a1cf5d658b40f68f1bc8a84dac2

js medianeira.pr.gov.br collected 2026-10-02 18:35:28 UTC 5,855 bytes, 210 lines download raw bytes

1/*
2 * Copyright (c) 2013-2014 Lukas Reschke <[email protected]>
3 *
4 * This file is licensed under the Affero General Public License version 3
5 * or later.
6 *
7 * See the COPYING-README file.
8 *
9 */
10(function (OCA) {
11
12	OCA.FilesPdfViewer = OCA.FilesPdfViewer || {};
13
14	/**
15	 * @namespace OCA.FilesPdfViewer.PreviewPlugin
16	 */
17	OCA.FilesPdfViewer.PreviewPlugin = {
18
19		/**
20		 * @param fileList
21		 */
22		attach: function (fileList) {
23			/*
24			Since PDFjs dropped support for IE11 and old EDGE(not chromium based) up to version v2.7.570
25			(https://github.com/mozilla/pdf.js/releases/tag/v2.7.570)
26			We don't attach file actions on an unsupported browser,
27			this falls back to download.
28			*/
29			if(!this.isSupportedBrowser()){
30				console.warn('files_pdfviewer can not be attached due to browser incompatibility');
31				return;
32			}
33
34			this._extendFileActions(fileList.fileActions);
35		},
36
37		hide: function () {
38			$('#pdframe').remove();
39			if ($('#isPublic').val() && $('#filesApp').val()) {
40				$('#controls').removeClass('hidden');
41				$('#content').removeClass('full-height');
42				$('footer').removeClass('hidden');
43			}
44
45			FileList.setViewerMode(false);
46			// replace the controls with our own
47			$('#app-content #controls').removeClass('hidden');
48		},
49
50		/**
51		 * @param fileName
52		 * @param dir
53		 */
54		show: function (fileName, dir) {
55			var self = this;
56			var downloadUrl = this._getDownloadUrl(fileName, dir);
57			var sharingToken = $("#sharingToken").val();
58			var uri = 'apps/files_pdfviewer/candownload?path={path}';
59
60			var params = {
61				path : dir+"/"+fileName,
62			};
63
64			if(sharingToken){
65				params.sharingToken = sharingToken;
66				uri += '&sharingToken={sharingToken}';
67			}
68
69			$.get(OC.generateUrl(uri, params)).then(function (response) {
70				if(!response.canDownload){
71					OC.Notification.show(t('files_pdfviewer', 'This shared file does not have download permission and is possibly protected by secure view, please contact the owner of the file for granting permission or use a different viewer.'), {timeout : 7, type: 'error'});
72				}else{
73					self.renderPdfViewer(downloadUrl, true);
74				}
75			});
76		},
77
78		/**
79		 * @param downloadUrl
80		 * @param isFileList
81		 */
82		renderPdfViewer: function(downloadUrl, isFileList){
83			var self = this;
84			var $iframe;
85			var isPdfVisible;
86			var viewer = OC.generateUrl('/apps/files_pdfviewer/?file={file}', {
87				file: downloadUrl
88			});
89			$iframe = $('<iframe id="pdframe" style="width:100%;height:100%;display:block;position:absolute;top:0;z-index:10;" src="' + viewer + '" sandbox="allow-downloads allow-scripts allow-same-origin allow-popups allow-modals allow-top-navigation" />');
90
91			if (isFileList === true) {
92				FileList.setViewerMode(true);
93			}
94
95			if ($('#isPublic').val()) {
96				// force the preview to adjust its height
97				$('#preview').append($iframe).css({
98					height: '100%'
99				});
100				$('body').css({
101					height: '100%'
102				});
103				$('#content').addClass('full-height');
104				$('footer').addClass('hidden');
105				$('#imgframe').addClass('hidden');
106				$('.directLink').addClass('hidden');
107				$('.directDownload').addClass('hidden');
108				$('#controls').addClass('hidden');
109			} else {
110				$('#app-content').append($iframe);
111			}
112
113			$("#pageWidthOption").attr("selected", "selected");
114			// replace the controls with our own
115			$('#app-content #controls').addClass('hidden');
116
117			// if a filelist is present, the PDF viewer can be closed to go back there
118			$('#pdframe').on("load", function () {
119				var iframe = $('#pdframe').contents();
120				if ($('#fileList').length) {
121					isPdfVisible = true;
122					history.pushState({}, '', '#pdfviewer');
123					iframe.find('#secondaryToolbarClose').click(function () {
124						history.back()
125					});
126				} else {
127					iframe.find("#secondaryToolbarClose").addClass('hidden');
128				}
129			});
130
131
132			$(document).keyup(function (e) {
133				if (isPdfVisible && e.keyCode == 27) {
134					isPdfVisible = false;
135					history.back();
136				}
137			});
138
139			setTimeout(function () {
140				$(window).one('popstate', function (e) {
141					self.hide();
142				});
143			}, 0);
144		},
145
146
147		/**
148		 * @param fileName
149		 * @param dir
150		 * @return string
151		 * @private
152		 */
153		_getDownloadUrl: function(fileName, dir){
154			var downloadUrl
155			if ($('#isPublic').val()) {
156				var sharingToken = $('#sharingToken').val();
157				downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
158					token: sharingToken,
159					files: fileName,
160					path: dir
161				});
162			} else {
163				downloadUrl = Files.getDownloadUrl(fileName, dir);
164			}
165
166			return downloadUrl;
167		},
168
169		/**
170		 * @param fileActions
171		 * @private
172		 */
173		_extendFileActions: function (fileActions) {
174			var self = this;
175			fileActions.registerAction({
176				name: 'FilesPdfViewer',
177				displayName: t('files_pdfviewer', 'Open in PDF Viewer'),
178				mime: 'application/pdf',
179				iconClass: 'icon-toggle',
180				permissions: OC.PERMISSION_READ,
181				actionHandler: function (fileName, context) {
182					self.show(fileName, context.dir);
183				}
184			});
185			fileActions.setDefault('application/pdf', 'FilesPdfViewer');
186		},
187
188		isSupportedBrowser: function () {
189			var userAgent = navigator.userAgent;
190			var isInternetExplorer = userAgent.indexOf("MSIE ") > -1 || userAgent.indexOf("Trident/") > -1;
191			var isOldEdge = userAgent.indexOf("edge") > -1;
192			return !isInternetExplorer && !isOldEdge ;
193		}
194	};
195
196})(OCA);
197
198OC.Plugins.register('OCA.Files.FileList', OCA.FilesPdfViewer.PreviewPlugin);
199
200// FIXME: Hack for single public file view since it is not attached to the fileslist
201$(document).ready(function () {
202	if ($('#isPublic').val() && $('#mimetype').val() === 'application/pdf') {
203		var sharingToken = $('#sharingToken').val();
204		var downloadUrl = OC.generateUrl('/s/{token}/download', {
205			token: sharingToken
206		});
207		var viewer = OCA.FilesPdfViewer.PreviewPlugin;
208		viewer.renderPdfViewer(downloadUrl, false);
209	}
210});

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.