Commit fdc2b94e authored by Andy Hausmann's avatar Andy Hausmann

Revised the view helper calls and optimized them. Added option to move JS to the page footer.

parent 1774b11d
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Andy Hausmann <hi@andy-hausmann.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
*
* A view helper for adding CSS and JS files to teh frontend.
*
* This helper needs to be called once per file.
* It is not possible to add multiple files via array or such, yet.
*
* = Examples =
*
* <code title="Single argument">
* <fs:AddCssJs file="path/to/file.ext" />
* </code>
* <output>
* </output>
*
* @package flexslider
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_Flexslider_ViewHelpers_AddCssJsViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
/**
* Adds JS and CSS to the frontend
*
* @param string $file
* @param bool $moveToFooter
* @return void Flag to include file into footer - doesn't work for CSS files
*/
public function render($file = NULL, $moveToFooter = FALSE)
{
if ($file) {
// Get file extension (after last occurance of a dot)
$mediaTypeSplit = strrchr($file, '.');
Tx_Flexslider_Utility_Div::addCssJsFile(
$file,
($mediaTypeSplit == '.js') ? 'flexSliderJs' : 'flexSliderCss',
$moveToFooter
);
}
}
}
?>
\ No newline at end of file
<?php
class Tx_Flexslider_ViewHelpers_AddFileViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
/**
* Adds JS
*
* @param string $file
* @return void
*/
public function render($file = NULL) {
$mediaTypeSplit = strrchr($file, '.');
$fileRef = $GLOBALS['TSFE']->tmpl->getFileName($file);
if ($fileRef) {
if ($mediaTypeSplit == '.js') {
$GLOBALS['TSFE']->additionalHeaderData['flexSliderJs'] = '<script src="' . $fileRef . '" type="text/javascript"></script>';
}
elseif ($mediaTypeSplit == '.css') {
$GLOBALS['TSFE']->additionalHeaderData['flexSliderCss'] =
'<link rel="stylesheet" type="text/css" media="all" href="' . $fileRef . '" />';
}
}
}
}
?>
\ No newline at end of file
<?php <?php
class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper { /***************************************************************
* Copyright notice
*
* (c) 2012 Andy Hausmann <hi@andy-hausmann.de>
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
*
* A view helper for adding jQuery to the frontend.
*
* = Examples =
*
* <code title="Single argument">
* <fs:AddJQuery altJQueryFile="path/to/alternativeJQueryFile.js" />
* </code>
* <output>
* </output>
*
* @package flexslider
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper
{
/** /**
* Adds T3Jquery as Lib * Adds T3Jquery as Lib
...@@ -11,7 +51,6 @@ class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHe ...@@ -11,7 +51,6 @@ class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHe
* @param string $altJQueryFile * @param string $altJQueryFile
* @return void * @return void
*/ */
public function render($altJQueryFile = NULL) { public function render($altJQueryFile = NULL) {
// checks if t3jquery is loaded // checks if t3jquery is loaded
if (t3lib_extMgm::isLoaded('t3jquery')) { if (t3lib_extMgm::isLoaded('t3jquery')) {
...@@ -23,9 +62,16 @@ class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHe ...@@ -23,9 +62,16 @@ class Tx_Flexslider_ViewHelpers_AddJQueryViewHelper extends Tx_Fluid_Core_ViewHe
} else { } else {
if ($altJQueryFile) { if ($altJQueryFile) {
$fileRef = $GLOBALS['TSFE']->tmpl->getFileName($altJQueryFile); Tx_Flexslider_Utility_Div::addCssJsFile(
$GLOBALS['TSFE']->additionalHeaderData['flexSliderJQuery'] = $altJQueryFile,
'<script src="' . $fileRef . '" type="text/javascript"></script>'; 'flexSliderJQuery'
);
} else {
Tx_Flexslider_Utility_Div::renderFlashMessage(
'jQuery not loaded',
'jQuery could not be loaded. Please check the path to the alternative jQuery library or simply use the Extension t3jquery.',
t3lib_FlashMessage::ERROR
);
} }
} }
} }
......
...@@ -19,6 +19,8 @@ plugin.tx_flexslider { ...@@ -19,6 +19,8 @@ plugin.tx_flexslider {
jQuery = EXT:flexslider/Resources/Public/Js/jquery-min.js jQuery = EXT:flexslider/Resources/Public/Js/jquery-min.js
# String: File reference to flexslider library # String: File reference to flexslider library
flexslider = EXT:flexslider/Resources/Public/Js/jquery.flexslider-min.js flexslider = EXT:flexslider/Resources/Public/Js/jquery.flexslider-min.js
# Bool: Flag to define whether the script shoul be moved to the footer or not
moveToFooter = 0
} }
} }
} }
\ No newline at end of file
...@@ -12,6 +12,7 @@ plugin.tx_flexslider { ...@@ -12,6 +12,7 @@ plugin.tx_flexslider {
lib { lib {
jQuery = {$plugin.tx_flexslider.settings.lib.jQuery} jQuery = {$plugin.tx_flexslider.settings.lib.jQuery}
flexslider = {$plugin.tx_flexslider.settings.lib.flexslider} flexslider = {$plugin.tx_flexslider.settings.lib.flexslider}
moveToFooter = {$plugin.tx_flexslider.settings.lib.moveToFooter}
} }
# String: Select your animation type, "fade" or "slide" # String: Select your animation type, "fade" or "slide"
animation = fade animation = fade
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<f:flashMessages /> <f:flashMessages />
<fs:AddJQuery altJQueryFile="{settings.lib.jQuery}" /> <fs:AddJQuery altJQueryFile="{settings.lib.jQuery}" />
<fs:AddFile file="{settings.lib.flexslider}" /> <fs:AddCssJs file="{settings.lib.flexslider}" moveToFooter="{settings.lib.moveToFooter}" />
<fs:AddFile file="{settings.css}" /> <fs:AddCssJs file="{settings.css}" />
<script type="text/javascript"> <script type="text/javascript">
<![CDATA[ <![CDATA[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment