From 897a6f623f955b78d4d21d9ed1030c2d8233e1d4 Mon Sep 17 00:00:00 2001 From: Cedric Ziel Date: Tue, 3 Jan 2017 16:04:36 +0100 Subject: [PATCH] Remove dependency on t3jquery and handle assets The jQuery library now needs to be provided by the site rather than being automatically included by t3jquery. Stylesheet assets can now be included through fluid viewhelpers (similar to vhs assets): ```xml {namespace s=Subugoe\Find\ViewHelpers} ``` Same for script assets: ```xml ``` and ```xml var foo = 'bar'; ``` Existing templates have been migrated. --- Classes/ViewHelpers/Page/ScriptViewHelper.php | 106 ++++++++++++++++++ Documentation/Index.rst | 10 +- Resources/Private/Layouts/Default.html | 2 +- .../Partials/Facets/Facet/Histogram.html | 10 +- .../Facets/Facet/List/Autocomplete.html | 10 +- .../Private/Partials/Facets/Facet/Map.html | 14 ++- Resources/Private/Partials/Page/CSS.html | 4 +- .../Private/Partials/Page/JavaScript.html | 8 +- ext_emconf.php | 2 +- t3jquery.txt | 2 - 10 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 Classes/ViewHelpers/Page/ScriptViewHelper.php delete mode 100644 t3jquery.txt diff --git a/Classes/ViewHelpers/Page/ScriptViewHelper.php b/Classes/ViewHelpers/Page/ScriptViewHelper.php new file mode 100644 index 00000000..e5d7a460 --- /dev/null +++ b/Classes/ViewHelpers/Page/ScriptViewHelper.php @@ -0,0 +1,106 @@ + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +use TYPO3\CMS\Core\Page\PageRenderer; +use TYPO3\CMS\Core\TypoScript\TemplateService; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface; +use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; +use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface; + +/** + * View Helper to dynamically add script resources to the output. + * + * Usage examples are available in Private/Partials/Test.html. + */ +class ScriptViewHelper extends AbstractViewHelper implements CompilableInterface +{ + /** + * @return PageRenderer + */ + protected static function getPageRenderer() + { + return GeneralUtility::makeInstance(PageRenderer::class); + } + + /** + * @return TemplateService + */ + protected static function getTypoScriptTemplateService() + { + return $GLOBALS['TSFE']->tmpl; + } + + /** + * @return void + */ + public function initializeArguments() + { + $this->registerArgument('file', 'string', 'File to append as script'); + $this->registerArgument('name', 'string', 'Name to use', true); + } + + /** + * @return string + */ + public function render() + { + return self::renderStatic( + [ + 'file' => $this->arguments['file'], + 'name' => $this->arguments['name'], + ], + $this->buildRenderChildrenClosure(), + $this->renderingContext + ); + } + + /** + * @param array $arguments + * @param \Closure $renderChildrenClosure + * @param RenderingContextInterface $renderingContext + * + * @return string + */ + public static function renderStatic( + array $arguments, + \Closure $renderChildrenClosure, + RenderingContextInterface $renderingContext + ) { + $scriptPath = static::getTypoScriptTemplateService()->getFileName($arguments['file']); + $name = $arguments['name']; + + $pageRenderer = self::getPageRenderer(); + if ($scriptPath) { + $pageRenderer->addJsFooterLibrary($name, $scriptPath); + + return ''; + } + + $content = $renderChildrenClosure(); + $pageRenderer->addJsFooterInlineCode($name, $content); + + return ''; + } +} diff --git a/Documentation/Index.rst b/Documentation/Index.rst index d2fc661d..4af30ef9 100644 --- a/Documentation/Index.rst +++ b/Documentation/Index.rst @@ -606,6 +606,14 @@ Settings include the ``JSPaths`` and ``CSSPaths`` arrays which can be used to co JSPaths.20 = EXT:find/Projects/test/Resources/test.js } +jQuery has to be included manually on your TypoScript ``PAGE``-object of choice. Example:: + + page.includeJSFooterlibs.jquery = https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js + page.includeJSFooterlibs.jquery.external = 1 + page.includeJSFooterlibs.jquery.integrity = sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8= + page.includeJSFooterlibs.jqueryUi = https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js + page.includeJSFooterlibs.jqueryUi.external = 1 + page.includeJSFooterlibs.jqueryUi.integrity = sha256-T0Vest3yCU7pafRw9r+settMBX6JkKN06dqBnpQ8d30= Localisation :::::::::::: @@ -712,8 +720,6 @@ Prerequisites * TYPO3 6.2 or higher * PHP 5.5 or higher -* t3jquery Extension - Contact ------- diff --git a/Resources/Private/Layouts/Default.html b/Resources/Private/Layouts/Default.html index d5e670ab..bba0aa16 100644 --- a/Resources/Private/Layouts/Default.html +++ b/Resources/Private/Layouts/Default.html @@ -1,4 +1,4 @@
-
\ No newline at end of file + diff --git a/Resources/Private/Partials/Facets/Facet/Histogram.html b/Resources/Private/Partials/Facets/Facet/Histogram.html index 1d091ff9..ebde5d65 100644 --- a/Resources/Private/Partials/Facets/Facet/Histogram.html +++ b/Resources/Private/Partials/Facets/Facet/Histogram.html @@ -1,13 +1,15 @@ {namespace s=Subugoe\Find\ViewHelpers} -{namespace t3jquery=Tx_T3jquery_ViewHelpers} + Uses facet data to draw a histogram of the distribution of the (numeric) facet terms. Includes the required JavaScript libraries (jQuery.flot) and hooks up the script functions to enable interaction. Adds a link to deselect the date range used for faceting if there is a selection. - - + + + +
@@ -58,4 +60,4 @@
- \ No newline at end of file + diff --git a/Resources/Private/Partials/Facets/Facet/List/Autocomplete.html b/Resources/Private/Partials/Facets/Facet/List/Autocomplete.html index daf2a36d..422fbb42 100644 --- a/Resources/Private/Partials/Facets/Facet/List/Autocomplete.html +++ b/Resources/Private/Partials/Facets/Facet/List/Autocomplete.html @@ -1,12 +1,14 @@ {namespace s=Subugoe\Find\ViewHelpers} -{namespace t3jquery=Tx_T3jquery_ViewHelpers} + Uses the facet items to create a popup menu with an autocomplete field (using jQuery.chosen) to let the user easily find a specific item in the facet and use it as a filter. - - + + + +
-
\ No newline at end of file + diff --git a/Resources/Private/Partials/Facets/Facet/Map.html b/Resources/Private/Partials/Facets/Facet/Map.html index 547abc14..325e2d7f 100644 --- a/Resources/Private/Partials/Facets/Facet/Map.html +++ b/Resources/Private/Partials/Facets/Facet/Map.html @@ -1,5 +1,5 @@ {namespace s=Subugoe\Find\ViewHelpers} -{namespace t3jquery=Tx_T3jquery_ViewHelpers} + Creates a map facet. @@ -25,7 +25,7 @@ of facet values that are fetched the more granular the displayed results will be. Sample TypoScript configuration: - + plugin.tx_find.settings.facet { 10 { id = map @@ -36,7 +36,10 @@ } } - + + + + tx_find_facetMap.init ({ container: jQuery('.facet-id-{facetInfo.id} .mapContainer')[0], queryURLTemplate: {s:format.json(data:"{f:uri.action( @@ -53,7 +56,8 @@ facetData: {s:format.json(data:facetData.values)}, facetFetchMaximum: {facetInfo.fetchMaximum} }); - +
+
-
\ No newline at end of file + diff --git a/Resources/Private/Partials/Page/CSS.html b/Resources/Private/Partials/Page/CSS.html index d9f71c3b..410e6397 100644 --- a/Resources/Private/Partials/Page/CSS.html +++ b/Resources/Private/Partials/Page/CSS.html @@ -1,7 +1,9 @@ {namespace s=Subugoe\Find\ViewHelpers} + Adds the CSS files configured in the CSSPaths settings to the page’s head. + - \ No newline at end of file + diff --git a/Resources/Private/Partials/Page/JavaScript.html b/Resources/Private/Partials/Page/JavaScript.html index d7f1b853..67fdb789 100644 --- a/Resources/Private/Partials/Page/JavaScript.html +++ b/Resources/Private/Partials/Page/JavaScript.html @@ -1,7 +1,9 @@ -{namespace t3jquery=Tx_T3jquery_ViewHelpers} +{namespace s=Subugoe\Find\ViewHelpers} + Adds the JavaScript files configured in the CSSPaths settings to the page’s head. + - - \ No newline at end of file + + diff --git a/ext_emconf.php b/ext_emconf.php index f24f2ae1..9083e10d 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -28,7 +28,7 @@ 'author' => 'Sven-S. Porst, Ingo Pfennigstorf', 'author_email' => 'pfennigstorf@sub.uni-goettingen.de', 'author_company' => 'SUB Göttingen', - 'dependencies' => 't3jquery', + 'dependencies' => '', 'conflicts' => '', 'constraints' => [ 'depends' => [ diff --git a/t3jquery.txt b/t3jquery.txt deleted file mode 100644 index 76706a9d..00000000 --- a/t3jquery.txt +++ /dev/null @@ -1,2 +0,0 @@ -script=Resources/Public/JavaScript/find.js -components=jQuery,Autocomplete,Menu,Position \ No newline at end of file