-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Use middleware to inject the loading overlay, split JS into …
…specific modules
- Loading branch information
1 parent
020c11e
commit 0dcee19
Showing
19 changed files
with
419 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\In2publishCore\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Psr\Http\Server\MiddlewareInterface; | ||
use Psr\Http\Server\RequestHandlerInterface; | ||
use TYPO3\CMS\Core\Http\StreamFactory; | ||
use TYPO3\CMS\Core\Page\PageRenderer; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
use function str_starts_with; | ||
use function strpos; | ||
use function strtolower; | ||
use function substr; | ||
|
||
class InjectLoadingOverlayMiddleware implements MiddlewareInterface | ||
{ | ||
protected const CODE = <<<HTML | ||
<div class="in2publish-loading-overlay in2publish-loading-overlay--hidden"> | ||
<div class="in2publish-loading-overlay--spinner"> | ||
<div class="rect1"></div> | ||
<div class="rect2"></div> | ||
<div class="rect3"></div> | ||
<div class="rect4"></div> | ||
<div class="rect5"></div> | ||
</div> | ||
</div> | ||
HTML; | ||
protected const SUPPORTED_PATHS = [ | ||
'/typo3/module/web/', | ||
'/typo3/module/file/in2publish', | ||
'/typo3/module/site/in2publish', | ||
'/typo3/module/tools/in2publish', | ||
'/typo3/module/in2publish', | ||
]; | ||
|
||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||
{ | ||
if (!$this->isInSupportedPath($request)) { | ||
return $handler->handle($request); | ||
} | ||
|
||
/** @var PageRenderer $pageRenderer */ | ||
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); | ||
$pageRenderer->addCssFile( | ||
'EXT:in2publish_core/Resources/Public/Css/LoadingOverlay.css', | ||
'stylesheet', | ||
'all', | ||
'', | ||
false, | ||
); | ||
$pageRenderer->loadRequireJsModule('TYPO3/CMS/In2publishCore/LoadingOverlay'); | ||
$pageRenderer->addInlineLanguageLabelFile('EXT:in2publish_core/Resources/Private/Language/locallang_js.xlf'); | ||
|
||
$response = $handler->handle($request); | ||
|
||
if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { | ||
$body = $response->getBody(); | ||
if ($body->isSeekable()) { | ||
$body->rewind(); | ||
} | ||
$contents = $body->getContents(); | ||
|
||
$offset = strpos($contents, '<body>') + 6; | ||
$contents = substr($contents, 0, $offset) . self::CODE . substr($contents, $offset); | ||
|
||
$streamFactory = GeneralUtility::makeInstance(StreamFactory::class); | ||
$newBody = $streamFactory->createStream($contents); | ||
$response = $response->withBody($newBody); | ||
} | ||
|
||
return $response; | ||
} | ||
|
||
protected function isInSupportedPath(ServerRequestInterface $request): bool | ||
{ | ||
$requestPath = strtolower($request->getUri()->getPath()); | ||
foreach (self::SUPPORTED_PATHS as $path) { | ||
if (str_starts_with($requestPath, $path)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
Resources/Private/Partials/Record/Publishing/PublishButton.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 5 additions & 2 deletions
7
Resources/Private/Partials/Record/Publishing/PublishButtonWithWarning.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@import "compass"; | ||
@import "Settings"; | ||
|
||
.in2publish-loading-overlay { | ||
background-color: $scorpion; | ||
height: 100%; | ||
position: fixed; | ||
z-index: 100000; | ||
text-align: center; | ||
opacity: 0.3; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
filter: blur(0); | ||
} | ||
|
||
.in2publish-loading-overlay--hidden { | ||
display: none; | ||
} | ||
|
||
.in2publish-loading-overlay--spinner { | ||
position: relative; | ||
top: 30%; | ||
margin: 100px auto; | ||
width: 50px; | ||
height: 30px; | ||
text-align: center; | ||
font-size: 10px; | ||
|
||
> div { | ||
background-color: $white; | ||
height: 100%; | ||
width: 6px; | ||
display: inline-block; | ||
|
||
-webkit-animation: stretchdelay 1.2s infinite ease-in-out; | ||
animation: stretchdelay 1.2s infinite ease-in-out; | ||
} | ||
|
||
.rect2 { | ||
-webkit-animation-delay: -1.1s; | ||
animation-delay: -1.1s; | ||
} | ||
|
||
.rect3 { | ||
-webkit-animation-delay: -1.0s; | ||
animation-delay: -1.0s; | ||
} | ||
|
||
.rect4 { | ||
-webkit-animation-delay: -0.9s; | ||
animation-delay: -0.9s; | ||
} | ||
|
||
.rect5 { | ||
-webkit-animation-delay: -0.8s; | ||
animation-delay: -0.8s; | ||
} | ||
} | ||
|
||
body:has(.in2publish-loading-overlay--active) > *:not(.in2publish-loading-overlay) { | ||
filter: blur(3px); | ||
} |
Oops, something went wrong.