Skip to content

Commit

Permalink
Fix styling and move towards standard TemplateResponse
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed May 26, 2021
1 parent 296aa56 commit 0f240f4
Show file tree
Hide file tree
Showing 10 changed files with 2,086 additions and 1,826 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = {
globals: {
appName: true,
PDFViewerApplicationOptions: true,
PDFViewerApplication: true,
pdfjsLib: true,
},
extends: [
'@nextcloud',
]
],
}
15 changes: 0 additions & 15 deletions css/style.css

This file was deleted.

37 changes: 37 additions & 0 deletions css/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Prevent printing from the browser when the download of a share is hidden
@media print {
.pdfViewer.disabledTextSelection {
visibility: hidden;
display: none;
}
}

// Prevent text selection when the download of a share is hidden
.pdfViewer.disabledTextSelection .textLayer {
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}

// Override text cursor in descendants
.pdfViewer.disabledTextSelection .textLayer * {
cursor: default;
}

// Hide unwanted toolbar actions
#secondaryOpenFile,
#openFile,
#sidebarResizer {
display: none !important;
}

// Override default styling
#content {
height: 100%;
width: 100%;
#sidebarContent *,
#viewer * {
box-sizing: content-box;
}
}
20 changes: 0 additions & 20 deletions css/viewer.css

This file was deleted.

39 changes: 31 additions & 8 deletions lib/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,62 @@
use OCA\Files_PDFViewer\AppInfo\Application;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\Util;

class DisplayController extends Controller {

/** @var IURLGenerator */
private $urlGenerator;

/** @var IInitialStateService */
private $initialStateService;

/**
* @param IRequest $request
* @param IURLGenerator $urlGenerator
*/
public function __construct(IRequest $request,
IURLGenerator $urlGenerator) {
IURLGenerator $urlGenerator,
IInitialStateService $initialStateService) {
parent::__construct(Application::APP_ID, $request);

$this->urlGenerator = $urlGenerator;
$this->initialStateService = $initialStateService;
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @param bool $minmode
* @return TemplateResponse
* @return StandaloneTemplateResponse
*/
public function showPdfViewer(bool $minmode = false): TemplateResponse {
$params = [
'urlGenerator' => $this->urlGenerator,
'minmode' => $minmode
];
public function showPdfViewer(bool $minmode = false): StandaloneTemplateResponse {
if ($minmode) {
Util::addStyle(Application::APP_ID, 'minmode');
}

Util::addScript(Application::APP_ID, 'files_pdfviewer-workersrc');
Util::addScript(Application::APP_ID, 'pdfjs/build/pdf');
Util::addScript(Application::APP_ID, 'pdfjs/web/viewer');

Util::addStyle(Application::APP_ID, 'style');
Util::addStyle(Application::APP_ID, '../js/pdfjs/web/viewer');

$workerSrc = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.worker.js');
$cmapUrl = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/cmaps/');
$localeUrl = $this->urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/locale/locale.properties');

$this->initialStateService->provideInitialState(Application::APP_ID, 'workerSrc', $workerSrc);
$this->initialStateService->provideInitialState(Application::APP_ID, 'cmapUrl', $cmapUrl);
Util::addHeader('link', ['rel' => 'resource', 'type' => 'application/l10n', 'href' => $localeUrl]);

$response = new TemplateResponse(Application::APP_ID, 'viewer', $params, 'blank');
$response = new StandaloneTemplateResponse(Application::APP_ID, 'viewer', [], TemplateResponse::RENDER_AS_BASE);

$policy = new ContentSecurityPolicy();
$policy->addAllowedChildSrcDomain('\'self\'');
Expand Down
Loading

0 comments on commit 0f240f4

Please sign in to comment.