nodebb-plugin-pdf-secure 1.2.14 → 1.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-pdf-secure",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "Secure PDF viewer plugin for NodeBB - prevents downloading, enables canvas-only rendering with Premium group support",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -67,6 +67,36 @@
67
67
  }
68
68
  }
69
69
 
70
+ // Fullscreen toggle request from iframe viewer
71
+ if (event.data && event.data.type === 'pdf-secure-fullscreen-toggle') {
72
+ var sourceIframe = document.querySelector('.pdf-secure-iframe');
73
+ // Find the specific iframe that sent the message
74
+ document.querySelectorAll('.pdf-secure-iframe').forEach(function (f) {
75
+ if (f.contentWindow === event.source) sourceIframe = f;
76
+ });
77
+ if (!sourceIframe) return;
78
+
79
+ var fsEl = document.fullscreenElement || document.webkitFullscreenElement;
80
+ if (fsEl) {
81
+ if (document.exitFullscreen) document.exitFullscreen();
82
+ else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
83
+ } else {
84
+ if (sourceIframe.requestFullscreen) sourceIframe.requestFullscreen().catch(function () { });
85
+ else if (sourceIframe.webkitRequestFullscreen) sourceIframe.webkitRequestFullscreen();
86
+ }
87
+ }
88
+
89
+ // Fullscreen state query from iframe
90
+ if (event.data && event.data.type === 'pdf-secure-fullscreen-query') {
91
+ var fsActive = !!(document.fullscreenElement || document.webkitFullscreenElement);
92
+ if (event.source) {
93
+ event.source.postMessage({
94
+ type: 'pdf-secure-fullscreen-state',
95
+ isFullscreen: fsActive
96
+ }, event.origin);
97
+ }
98
+ }
99
+
70
100
  // Viewer asking for cached buffer
71
101
  if (event.data && event.data.type === 'pdf-secure-cache-request') {
72
102
  const { filename } = event.data;
@@ -93,6 +123,21 @@
93
123
  }
94
124
  });
95
125
 
126
+ // Forward fullscreen state changes to all viewer iframes
127
+ function notifyFullscreenChange() {
128
+ var fsActive = !!(document.fullscreenElement || document.webkitFullscreenElement);
129
+ document.querySelectorAll('.pdf-secure-iframe').forEach(function (f) {
130
+ if (f.contentWindow) {
131
+ f.contentWindow.postMessage({
132
+ type: 'pdf-secure-fullscreen-state',
133
+ isFullscreen: fsActive
134
+ }, window.location.origin);
135
+ }
136
+ });
137
+ }
138
+ document.addEventListener('fullscreenchange', notifyFullscreenChange);
139
+ document.addEventListener('webkitfullscreenchange', notifyFullscreenChange);
140
+
96
141
  async function processQueue() {
97
142
  if (isLoading || loadQueue.length === 0) return;
98
143
 
@@ -278,6 +323,7 @@
278
323
  iframe.src = config.relative_path + '/plugins/pdf-secure/viewer?file=' + encodeURIComponent(filename);
279
324
  iframe.setAttribute('frameborder', '0');
280
325
  iframe.setAttribute('allowfullscreen', 'true');
326
+ iframe.setAttribute('allow', 'fullscreen');
281
327
 
282
328
  // Store resolver for postMessage callback
283
329
  currentResolver = function () {
@@ -4461,25 +4461,34 @@
4461
4461
  // ERGONOMIC FEATURES
4462
4462
  // ==========================================
4463
4463
 
4464
- // Fullscreen toggle function (with webkit fallback for iOS Safari)
4464
+ // Fullscreen: track state (parent-managed when in iframe)
4465
+ let isFullscreen = false;
4466
+ const inIframe = window.self !== window.top;
4467
+
4465
4468
  function toggleFullscreen() {
4466
- const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
4467
- if (fsEl) {
4468
- if (document.exitFullscreen) document.exitFullscreen();
4469
- else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
4469
+ if (inIframe) {
4470
+ // In iframe: ask parent to fullscreen the iframe element
4471
+ // Parent manages fullscreen → more stable on tablets
4472
+ window.parent.postMessage({ type: 'pdf-secure-fullscreen-toggle' }, '*');
4470
4473
  } else {
4471
- const el = document.documentElement;
4472
- if (el.requestFullscreen) el.requestFullscreen().catch(() => { });
4473
- else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen();
4474
+ // Standalone: use local fullscreen
4475
+ const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
4476
+ if (fsEl) {
4477
+ if (document.exitFullscreen) document.exitFullscreen();
4478
+ else if (document.webkitExitFullscreen) document.webkitExitFullscreen();
4479
+ } else {
4480
+ const el = document.documentElement;
4481
+ if (el.requestFullscreen) el.requestFullscreen().catch(() => { });
4482
+ else if (el.webkitRequestFullscreen) el.webkitRequestFullscreen();
4483
+ }
4474
4484
  }
4475
4485
  }
4476
4486
 
4477
- // Update fullscreen button icon
4487
+ // Update fullscreen button icon based on state
4478
4488
  function updateFullscreenIcon() {
4479
4489
  const icon = document.getElementById('fullscreenIcon');
4480
4490
  const btn = document.getElementById('fullscreenBtn');
4481
- const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
4482
- if (fsEl) {
4491
+ if (isFullscreen) {
4483
4492
  icon.innerHTML = '<path d="M5 16h3v3h2v-5H5v2zm3-8H5v2h5V5H8v3zm6 11h2v-3h3v-2h-5v5zm2-11V5h-2v5h5V8h-3z"/>';
4484
4493
  btn.classList.add('active');
4485
4494
  } else {
@@ -4488,8 +4497,23 @@
4488
4497
  }
4489
4498
  }
4490
4499
 
4491
- document.addEventListener('fullscreenchange', updateFullscreenIcon);
4492
- document.addEventListener('webkitfullscreenchange', updateFullscreenIcon);
4500
+ // Listen for fullscreen state from parent (iframe mode)
4501
+ window.addEventListener('message', (event) => {
4502
+ if (event.data && event.data.type === 'pdf-secure-fullscreen-state') {
4503
+ isFullscreen = event.data.isFullscreen;
4504
+ updateFullscreenIcon();
4505
+ }
4506
+ });
4507
+
4508
+ // Local fullscreen events (standalone mode)
4509
+ document.addEventListener('fullscreenchange', () => {
4510
+ isFullscreen = !!(document.fullscreenElement || document.webkitFullscreenElement);
4511
+ updateFullscreenIcon();
4512
+ });
4513
+ document.addEventListener('webkitfullscreenchange', () => {
4514
+ isFullscreen = !!(document.fullscreenElement || document.webkitFullscreenElement);
4515
+ updateFullscreenIcon();
4516
+ });
4493
4517
 
4494
4518
  // Fullscreen button click
4495
4519
  document.getElementById('fullscreenBtn').onclick = () => toggleFullscreen();
@@ -4802,9 +4826,8 @@
4802
4826
  document.addEventListener('touchmove', (e) => {
4803
4827
  if (e.touches.length !== 1) return;
4804
4828
 
4805
- // Only prevent when in fullscreen
4806
- const fsEl = document.fullscreenElement || document.webkitFullscreenElement;
4807
- if (!fsEl) return;
4829
+ // Only prevent when in fullscreen (isFullscreen works in both iframe and standalone)
4830
+ if (!isFullscreen) return;
4808
4831
 
4809
4832
  const touchY = e.touches[0].clientY;
4810
4833
  const deltaY = docTouchStartY - touchY;