Commit 731d21f7 authored by Andy Hausmann's avatar Andy Hausmann

Improved handling of Inline JS by adding a new ViewHelper.

parent d7f02315
......@@ -4,6 +4,7 @@
* Copyright notice
*
* (c) 2012-2013 Andy Hausmann <andy@sota-studio.de>
* (c) 2012-2013 Xaver Maierhofer <xaver.maierhofer@xwissen.info>
*
* All rights reserved
*
......@@ -28,6 +29,7 @@
* Helper Class which makes various tools and helper available
*
* @author Andy Hausmann <andy@sota-studio.de>
* @author Xaver Maierhofer <xaver.maierhofer@xwissen.info>
* @package flexslider
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
......@@ -115,6 +117,24 @@ class Tx_Flexslider_Utility_Div
}
}
/**
* Checks a passed CSS or JS file and adds it to the Frontend.
*
* @param string $script JS Block
* @param string $addUnique Unique key to avoid multiple inclusions
* @param bool $moveToFooter Flag to include file into footer - doesn't work for CSS files
*/
public static function addJsInline($code, $name, $moveToFooter = false)
{
if ($code) {
//$code = '<script type="text/javascript">'.$code.'</script>';
($moveToFooter)
? $GLOBALS['TSFE']->getPageRenderer()->addJsFooterInlineCode($name, $code)
: $GLOBALS['TSFE']->getPageRenderer()->addJsInlineCode($name, $code);
}
}
/**
* Adds/renders a Flash message.
*
......
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012-2013 Andy Hausmann <andy@sota-studio.de>
* (c) 2012-2013 Xaver Maierhofer <xaver.maierhofer@xwissen.info>
*
* 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!
***************************************************************/
/**
*
* Renders Inline JS via PageRenderer and enables Plugins to throw it into external files,
* close to the ending body tag or just to special stuff with it, like concatenation, compression and such.
*
* = Examples =
*
* <code title="Single argument">
* <fs:AddJsInline code="$();" name="unique-name" moveToFooter="0" />
* </code>
* <output>
* </output>
*
* @author Andy Hausmann <andy@sota-studio.de>
* @author Xaver Maierhofer <xaver.maierhofer@xwissen.info>
* @package flexslider
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class Tx_Flexslider_ViewHelpers_AddJsInlineViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
/**
* Adds JS and CSS to the frontend
*
* @param null $code The JS code
* @param bool $moveToFooter Move the the ending body tag?
* @param null $uniqueLabel Unique label in order to avoid multiple code blocks of the same code.
* @return void
*/
public function render($code = null, $name = '', $moveToFooter = false)
{
if ($code) {
Tx_Flexslider_Utility_Div::addJsInline(
$code,
$name,
$moveToFooter
);
}
}
}
?>
\ No newline at end of file
<script type="text/javascript">
<![CDATA[ $(window).load(function() { ]]>
$('#fs-{data.uid}.flexslider').flexslider(
<![CDATA[ { ]]>
animation: "{settings.animation}",
slideDirection: "{settings.slideDirection}",
slideshow: <f:if condition="{settings.slideshow} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
slideshowSpeed: <f:if condition="{settings.slideshowSpeed} > 0"><f:then>{settings.slideshowSpeed}</f:then><f:else>7000</f:else></f:if>,
animationDuration: <f:if condition="{settings.animationDuration} > 0"><f:then>{settings.animationDuration}</f:then><f:else>600</f:else></f:if>,
controlNav: <f:if condition="{settings.controlNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
directionNav: <f:if condition="{settings.directionNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
keyboardNav: <f:if condition="{settings.keyboardNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
mousewheel: <f:if condition="{settings.mousewheel} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
prevText: "<f:translate key="prevText">Prev</f:translate>",
nextText: "<f:translate key="nextText">Next</f:translate>",
pausePlay: <f:if condition="{settings.pausePlay} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
pauseText: "<f:translate key="pauseText">Pause</f:translate>",
playText: "<f:translate key="playText">Play</f:translate>",
randomize: <f:if condition="{settings.randomize} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
animationLoop: <f:if condition="{settings.animationLoop} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
pauseOnHover: <f:if condition="{settings.pauseOnHover} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>
<![CDATA[
});
});
]]>
<f:render partial='JavaScriptRaw' arguments='{settings: settings, data: data}'/>
</script>
\ No newline at end of file
<![CDATA[ $(window).load(function() { ]]>
$('#fs-{data.uid}.flexslider').flexslider(
<![CDATA[{]]>
animation: "{settings.animation}",
slideDirection: "{settings.slideDirection}",
slideshow: <f:if condition="{settings.slideshow} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
slideshowSpeed: <f:if condition="{settings.slideshowSpeed} > 0"><f:then>{settings.slideshowSpeed}</f:then><f:else>7000</f:else></f:if>,
animationDuration: <f:if condition="{settings.animationDuration} > 0"><f:then>{settings.animationDuration}</f:then><f:else>600</f:else></f:if>,
controlNav: <f:if condition="{settings.controlNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
directionNav: <f:if condition="{settings.directionNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
keyboardNav: <f:if condition="{settings.keyboardNav} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
mousewheel: <f:if condition="{settings.mousewheel} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
prevText: "<f:translate key="prevText">Prev</f:translate>",
nextText: "<f:translate key="nextText">Next</f:translate>",
pausePlay: <f:if condition="{settings.pausePlay} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
pauseText: "<f:translate key="pauseText">Pause</f:translate>",
playText: "<f:translate key="playText">Play</f:translate>",
randomize: <f:if condition="{settings.randomize} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
animationLoop: <f:if condition="{settings.animationLoop} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>,
pauseOnHover: <f:if condition="{settings.pauseOnHover} > 0"><f:then>true</f:then><f:else>false</f:else></f:if>
<![CDATA[
});
});
]]>
\ No newline at end of file
......@@ -9,7 +9,7 @@
<f:if condition="<f:count subject='{flexSliders}' /> > 0">
<f:render partial="ResourceFiles" arguments="{settings: settings}"/>
<f:render partial="JavaScript" arguments="{settings: settings, data: data}"/>
<f:render partial="JavaScript" arguments="{settings: settings, data: data}"/>
<div class="flexslider" id="fs-{data.uid}">
<ul class="slides">
......
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