Skip to content

Commit

Permalink
// first trial of addJsDef for index
Browse files Browse the repository at this point in the history
  • Loading branch information
gRoussac committed Jan 4, 2014
1 parent 086ab5f commit f4afd93
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 69 deletions.
18 changes: 16 additions & 2 deletions classes/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ public static function clearCache()

public static function getJsDef()
{
ksort(Media::$js_def);
return Media::$js_def;
}

Expand All @@ -592,9 +593,9 @@ public static function getInlineScript()
}

/**
* Add a new javascript definition in page
* Add a new javascript definition at bottom of page
*
* @param mixed $js_uri
* @param mixed $js_def
* @return void
*/
public static function addJsDef($js_def)
Expand All @@ -605,6 +606,19 @@ public static function addJsDef($js_def)
elseif ($js_def)
Media::$js_def[] = $js_def;
}

/**
* Add a new javascript definition from a capture at bottom of page
*
* @param mixed $js_def
* @return void
*/
public static function addJsDefL($params, $content, $smarty, &$repeat, $template)
{
if (!$repeat && isset($params) && is_array($params) && Tools::strlen($content))
foreach($params as $param)
Media::$js_def[$param] = $content;
}

public static function deferInlineScripts($output)
{
Expand Down
22 changes: 14 additions & 8 deletions classes/controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,20 @@ protected function smartyOutputContent($content)
$html = $this->context->smarty->fetch($tpl);
else
$html = $this->context->smarty->fetch($content);

$html = Media::deferInlineScripts($html);
$this->context->smarty->assign('js_defs', Media::getJsDef());
echo $html.$this->context->smarty->fetch(_PS_THEME_DIR_.'jsdefs.tpl');

foreach (Media::getInlineScript() as $script)
$javascript .= $script."\n";
echo "\n<script type=\"text/javascript\">\n".$javascript.'</script>';

if ($this->controller_type == 'front')
{
$html = Media::deferInlineScripts($html);
$html = str_replace(array('</body>', '</html>'), '', $html);
$this->context->smarty->assign('js_def', Media::getJsDef());
$javascript = $this->context->smarty->fetch(_PS_THEME_DIR_.'javascript.tpl');
$javascript = substr_replace(trim($javascript), '', -(strlen('</script>')));
foreach (Media::getInlineScript() as $script)
$javascript .= $script."\n";
echo $html.$javascript."</script>\n\t</body>\n</html>";
}
else
echo $html;
}

protected function isCached($template, $cacheId = null, $compileId = null)
Expand Down
3 changes: 2 additions & 1 deletion config/smarty.config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
smartyRegisterFunction($smarty, 'function', 'getWidthSize', array('Image', 'getWidth'));
smartyRegisterFunction($smarty, 'function', 'getHeightSize', array('Image', 'getHeight'));
smartyRegisterFunction($smarty, 'function', 'addJsDef', array('Media', 'addJsDef'));
smartyRegisterFunction($smarty, 'block', 'addJsDefL', array('Media', 'addJsDefL'));

function smartyDieObject($params, &$smarty)
{
Expand Down Expand Up @@ -155,7 +156,7 @@ function smartyPackJSinHTML($tpl_output, &$smarty)

function smartyRegisterFunction($smarty, $type, $function, $params, $lazy = true)
{
if (!in_array($type, array('function', 'modifier')))
if (!in_array($type, array('function', 'modifier', 'block')))
return false;

// lazy is better if the function is not called on every page
Expand Down
2 changes: 2 additions & 0 deletions controllers/front/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function initContent()
{
parent::initContent();

$this->addJS(_THEME_JS_DIR_.'index.js');

$this->context->smarty->assign(array('HOOK_HOME' => Hook::exec('displayHome'),
'HOOK_HOME_TAB' => Hook::exec('displayHomeTab'),
'HOOK_HOME_TAB_CONTENT' => Hook::exec('displayHomeTabContent')
Expand Down
4 changes: 0 additions & 4 deletions modules/socialsharing/socialsharing_header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}

<meta property="og:title" content="">
<meta property="og:type" content="product">

<meta property="og:site_name" content="">
<meta property="og:description" content="">

<meta property="og:email" content="">
<meta property="og:phone_number" content="">
<meta property="og:street-address" content="">
<meta property="og:locality" content="">
<meta property="og:country-name" content="">
<meta property="og:postal-code" content="">

<meta property="og:image" content="{$link->getImageLink($link_rewrite, $cover.id_image, large_default)}" />
2 changes: 1 addition & 1 deletion themes/default-bootstrap/contact-form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
{if (!isset($customerThread.id_order) || $customerThread.id_order > 0)}
<div class="form-group selector1">
<label>{l s='Order reference'}</label>
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged == 1}
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged}
<select name="id_order" class="form-control">
<option value="0">{l s='-- Choose --'}</option>
{foreach from=$orderList item=order}
Expand Down
8 changes: 4 additions & 4 deletions themes/default-bootstrap/footer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
{addJsDef baseUri=$base_uri}
{addJsDef static_token=$static_token}
{addJsDef token=$token}
{addJsDef priceDisplayPrecision=$priceDisplayPrecision|intval*$currency->decimals|intval}
{addJsDef priceDisplayMethod=$priceDisplay|intval}
{addJsDef roundMode=$roundMode|intval}
{addJsDef isUserLogged=$logged|intval}
{addJsDef priceDisplayPrecision=$priceDisplayPrecision*$currency->decimals}
{addJsDef priceDisplayMethod=$priceDisplay}
{addJsDef roundMode=$roundMode}
{addJsDef logged=$logged}
{/strip}
6 changes: 3 additions & 3 deletions themes/default-bootstrap/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
<link rel="stylesheet" href="{$css_uri}" type="text/css" media="{$media}" />
{/foreach}
{/if}
{$HOOK_HEADER}
<!--[if IE 8]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
{$HOOK_HEADER}
</head>
<body{if isset($page_name)} id="{$page_name|escape:'html':'UTF-8'}"{/if} class="{if isset($page_name)}{$page_name|escape:'html':'UTF-8'}{/if}{if isset($body_classes) && $body_classes|@count} {implode value=$body_classes separator=' '}{/if}{if $hide_left_column} hide-left-column{/if}{if $hide_right_column} hide-right-column{/if}{if $content_only} content_only{/if} lang_{$lang_iso}">
{if !$content_only}
Expand Down
37 changes: 15 additions & 22 deletions themes/default-bootstrap/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,22 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*}

{if isset($HOOK_HOME_TAB_CONTENT)}
<div class="clearfix"></div>
{if isset($HOOK_HOME_TAB)}
<ul id="home-page-tabs" class="nav nav-tabs">{/if}{$HOOK_HOME_TAB}{if isset($HOOK_HOME_TAB)}</ul>
{/if}
<script type="text/javascript">
var min_item = '{l s='Please select at least one product' js=1}';
var max_item = "{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}";
var comparator_max_item = {$comparator_max_item};
var comparedProductsIds = [];
{foreach from=$compared_products key=k item=product}comparedProductsIds.push({$product});{/foreach}
$(document).ready(function(){
$('#home-page-tabs li').first().find('a').trigger('click');
blockHover();
if (typeof reloadProductComparison != 'undefined')
reloadProductComparison();
});
</script>
{if isset($HOOK_HOME_TAB_CONTENT) && $HOOK_HOME_TAB_CONTENT|trim}
{if isset($HOOK_HOME_TAB) && $HOOK_HOME_TAB|trim}
<ul id="home-page-tabs" class="nav nav-tabs clearfix">
{$HOOK_HOME_TAB}
</ul>
{/if}
<div class="tab-content">
{$HOOK_HOME_TAB_CONTENT}
</div>
{/if}
<div class="clearfix">
{$HOOK_HOME}
</div>
{if isset($HOOK_HOME) && $HOOK_HOME|trim}
<div class="clearfix">
{$HOOK_HOME}
</div>
{/if}
{addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL}
{addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL}
{addJsDef comparator_max_item=$comparator_max_item}
{addJsDef comparedProductsIds=$compared_products}
28 changes: 28 additions & 0 deletions themes/default-bootstrap/javascript.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{if isset($js_files)}
{foreach from=$js_files key=k item=js_uri}
<script type="text/javascript" src="{$js_uri}"></script>
{/foreach}
{/if}
<script type="text/javascript">
{if isset($js_def) && is_array($js_def) && $js_def|@count}
{foreach from=$js_def key=k item=def}
{if !empty($k)}
{if is_bool($def)}
var {$k|strval} = {$def|var_export:true};
{elseif is_int($def)}
var {$k|strval} = {$def|intval};
{elseif is_float($def)}
var {$k|strval} = {$def|floatval};
{elseif is_string($def)}
var {$k|strval} = '{$def|strval}';
{elseif is_array($def) || is_object($def)}
var {$k|strval} = {$def|json_encode};
{elseif is_null($def)}
var {$k|strval} = null;
{else}
var {$k|strval} = '{$def|@addcslashes:'\''}';
{/if}
{/if}
{/foreach}
{/if}
</script>
31 changes: 31 additions & 0 deletions themes/default-bootstrap/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
$(document).ready(function(){
$('#home-page-tabs li').first().find('a').trigger('click');
if (typeof blockHover != 'undefined')
blockHover();
if (typeof reloadProductComparison != 'undefined')
reloadProductComparison();
});
14 changes: 0 additions & 14 deletions themes/default-bootstrap/jsdefs.tpl

This file was deleted.

2 changes: 1 addition & 1 deletion themes/default-bootstrap/mobile/contact-form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{if !$PS_CATALOG_MODE}
{if (!isset($customerThread.id_order) || $customerThread.id_order > 0)}
<fieldset>
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged == 1}
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged}
<select name="id_order" ><option value="0">-- {l s='Order ID'} --</option>
{foreach from=$orderList item=order}
<option value="{$order.value|intval}" {if $order.selected|intval}selected="selected"{/if}>{$order.label|escape:'html':'UTF-8'}</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(function(){
});
</script>
{if (!$content_only && (($nbComments == 0 && $too_early == false && $logged == 1) || ($nbComments != 0)))}
{if (!$content_only && (($nbComments == 0 && $too_early == false && $logged) || ($nbComments != 0)))}
<div id="product_comments_block_extra" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
{if $nbComments != 0}
<div class="comments_note clearfix">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var moderation_active = {$moderation_active};
{l s='%1$d out of %2$d people found this review useful.' sprintf=[$comment.total_useful,$comment.total_advice] mod='productcomments'}
</li>
{/if}
{if $logged == 1}
{if $logged}
{if !$comment.customer_advice}
<li>
{l s='Was this comment useful to you?' mod='productcomments'}
Expand Down
14 changes: 7 additions & 7 deletions themes/default-bootstrap/product.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
{/foreach}
{/if}
// Translations
var doesntExist = '{l s='This combination does not exist for this product. Please select another combination.' js=1}';
var doesntExistNoMore = '{l s='This product is no longer in stock' js=1}';
var doesntExistNoMoreBut = '{l s='with those attributes but is available with others.' js=1}';
var uploading_in_progress = '{l s='Uploading in progress, please be patient.' js=1}';
var fieldRequired = '{l s='Please fill in all the required fields before saving your customization.' js=1}';
{addJsDefL name=doesntExist}{l s='This combination does not exist for this product. Please select another combination.' js=1}{/addJsDefL}
{addJsDefL name=doesntExistNoMore}{l s='This product is no longer in stock' js=1}{/addJsDefL}
{addJsDefL name=doesntExistNoMoreBut}{l s='with those attributes but is available with others.' js=1}{/addJsDefL}
{addJsDefL name=uploading_in_progress}{l s='Uploading in progress, please be patient.' js=1}{/addJsDefL}
{addJsDefL name=fieldRequired}{l s='Please fill in all the required fields before saving your customization.' js=1}{/addJsDefL}
{if isset($groups)}
// Combinations
Expand Down Expand Up @@ -149,8 +149,8 @@
attributesCombinations.push(tabInfos);
{/foreach}
{/if}
var isLoggedWishlist = {$logged|intval};
var contentOnly = {$content_only|intval};
{addJsDef isLoggedWishlist=$logged}
{addJsDef contentOnly=$content_only}
//]]>
</script>

Expand Down

0 comments on commit f4afd93

Please sign in to comment.