[-] MO : #PSCFV-3049 - Fix Bug with module block search
// Removing code duplication
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
{if $instantsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
function tryToCloseInstantSearch() {
|
||||
if ($('#old_center_column').length > 0)
|
||||
{
|
||||
$('#center_column').remove();
|
||||
$('#old_center_column').attr('id', 'center_column');
|
||||
$('#center_column').show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
instantSearchQueries = new Array();
|
||||
function stopInstantSearchQueries(){
|
||||
for(i=0;i<instantSearchQueries.length;i++) {
|
||||
instantSearchQueries[i].abort();
|
||||
}
|
||||
instantSearchQueries = new Array();
|
||||
}
|
||||
|
||||
$("#search_query_{$blocksearch_type}").keyup(function(){
|
||||
if($(this).val().length > 0){
|
||||
stopInstantSearchQueries();
|
||||
instantSearchQuery = $.ajax({
|
||||
url: '{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}',
|
||||
data: {
|
||||
instantSearch: 1,
|
||||
id_lang: {$cookie->id_lang},
|
||||
q: $(this).val()
|
||||
},
|
||||
dataType: 'html',
|
||||
type: 'POST',
|
||||
success: function(data){
|
||||
if($("#search_query_{$blocksearch_type}").val().length > 0)
|
||||
{
|
||||
tryToCloseInstantSearch();
|
||||
$('#center_column').attr('id', 'old_center_column');
|
||||
$('#old_center_column').after('<div id="center_column" class="' + $('#old_center_column').attr('class') + '">'+data+'</div>');
|
||||
$('#old_center_column').hide();
|
||||
$("#instant_search_results a.close").click(function() {
|
||||
$("#search_query_{$blocksearch_type}").val('');
|
||||
return tryToCloseInstantSearch();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
}
|
||||
});
|
||||
instantSearchQueries.push(instantSearchQuery);
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
||||
{$blocksearch_type|elog}
|
||||
{if $ajaxsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
$('document').ready( function() {
|
||||
$("#search_query_{$blocksearch_type}")
|
||||
.autocomplete(
|
||||
'{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}', {
|
||||
minChars: 3,
|
||||
max: 10,
|
||||
width: 500,
|
||||
selectFirst: false,
|
||||
scroll: false,
|
||||
dataType: "json",
|
||||
formatItem: function(data, i, max, value, term) {
|
||||
return value;
|
||||
},
|
||||
parse: function(data) {
|
||||
var mytab = new Array();
|
||||
for (var i = 0; i < data.length; i++)
|
||||
mytab[mytab.length] = { data: data[i], value: data[i].cname + ' > ' + data[i].pname };
|
||||
return mytab;
|
||||
},
|
||||
extraParams: {
|
||||
ajaxSearch: 1,
|
||||
id_lang: {$cookie->id_lang}
|
||||
}
|
||||
}
|
||||
)
|
||||
.result(function(event, data, formatted) {
|
||||
$('#search_query_{$blocksearch_type}').val(data.pname);
|
||||
document.location.href = data.product_link;
|
||||
})
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
||||
@@ -37,103 +37,5 @@
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
{if $instantsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
{literal}
|
||||
function tryToCloseInstantSearch() {
|
||||
if ($('#old_center_column').length > 0)
|
||||
{
|
||||
$('#center_column').remove();
|
||||
$('#old_center_column').attr('id', 'center_column');
|
||||
$('#center_column').show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
instantSearchQueries = new Array();
|
||||
function stopInstantSearchQueries(){
|
||||
for(i=0;i<instantSearchQueries.length;i++) {
|
||||
instantSearchQueries[i].abort();
|
||||
}
|
||||
instantSearchQueries = new Array();
|
||||
}
|
||||
|
||||
$("#search_query_top").keyup(function(){
|
||||
if($(this).val().length > 0){
|
||||
stopInstantSearchQueries();
|
||||
instantSearchQuery = $.ajax({
|
||||
url: '{/literal}{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}{literal}',
|
||||
data: {
|
||||
instantSearch: 1,
|
||||
id_lang: {/literal}{$cookie->id_lang}{literal},
|
||||
q: $(this).val()
|
||||
},
|
||||
dataType: 'html',
|
||||
type: 'POST',
|
||||
success: function(data){
|
||||
if($("#search_query_top").val().length > 0)
|
||||
{
|
||||
tryToCloseInstantSearch();
|
||||
$('#center_column').attr('id', 'old_center_column');
|
||||
$('#old_center_column').after('<div id="center_column" class="' + $('#old_center_column').attr('class') + '">'+data+'</div>');
|
||||
$('#old_center_column').hide();
|
||||
$("#instant_search_results a.close").click(function() {
|
||||
$("#search_query_top").val('');
|
||||
return tryToCloseInstantSearch();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
}
|
||||
});
|
||||
instantSearchQueries.push(instantSearchQuery);
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
});
|
||||
// ]]>
|
||||
{/literal}
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{if $ajaxsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
{literal}
|
||||
$('document').ready( function() {
|
||||
$("#search_query_top")
|
||||
.autocomplete(
|
||||
'{/literal}{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}{literal}', {
|
||||
minChars: 3,
|
||||
max: 10,
|
||||
width: 500,
|
||||
selectFirst: false,
|
||||
scroll: false,
|
||||
dataType: "json",
|
||||
formatItem: function(data, i, max, value, term) {
|
||||
return value;
|
||||
},
|
||||
parse: function(data) {
|
||||
var mytab = new Array();
|
||||
for (var i = 0; i < data.length; i++)
|
||||
mytab[mytab.length] = { data: data[i], value: data[i].cname + ' > ' + data[i].pname };
|
||||
return mytab;
|
||||
},
|
||||
extraParams: {
|
||||
ajaxSearch: 1,
|
||||
id_lang: {/literal}{$cookie->id_lang}{literal}
|
||||
}
|
||||
}
|
||||
)
|
||||
.result(function(event, data, formatted) {
|
||||
$('#search_query_top').val(data.pname);
|
||||
document.location.href = data.product_link;
|
||||
})
|
||||
});
|
||||
{/literal}
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
||||
{include file="$self/blocksearch-instantsearch.tpl"}
|
||||
<!-- /Block search module TOP -->
|
||||
|
||||
@@ -34,7 +34,7 @@ class BlockSearch extends Module
|
||||
{
|
||||
$this->name = 'blocksearch';
|
||||
$this->tab = 'search_filter';
|
||||
$this->version = 1.1;
|
||||
$this->version = 1.2;
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
@@ -67,12 +67,14 @@ class BlockSearch extends Module
|
||||
public function hookRightColumn($params)
|
||||
{
|
||||
$this->calculHookCommon($params);
|
||||
$this->smarty->assign('blocksearch_type', 'block');
|
||||
return $this->display(__FILE__, 'blocksearch.tpl');
|
||||
}
|
||||
|
||||
public function hookTop($params)
|
||||
{
|
||||
$this->calculHookCommon($params);
|
||||
$this->smarty->assign('blocksearch_type', 'top');
|
||||
return $this->display(__FILE__, 'blocksearch-top.tpl');
|
||||
}
|
||||
|
||||
@@ -89,6 +91,7 @@ class BlockSearch extends Module
|
||||
'search_ssl' => Tools::usingSecureMode(),
|
||||
'ajaxsearch' => Configuration::get('PS_SEARCH_AJAX'),
|
||||
'instantsearch' => Configuration::get('PS_INSTANT_SEARCH'),
|
||||
'self' => dirname(__FILE__),
|
||||
));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -38,98 +38,5 @@
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
{if $instantsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
{literal}
|
||||
function tryToCloseInstantSearch() {
|
||||
if ($('#old_center_column').length > 0)
|
||||
{
|
||||
$('#center_column').remove();
|
||||
$('#old_center_column').attr('id', 'center_column');
|
||||
$('#center_column').show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
instantSearchQueries = new Array();
|
||||
function stopInstantSearchQueries(){
|
||||
for(i=0;i<instantSearchQueries.length;i++) {
|
||||
instantSearchQueries[i].abort();
|
||||
}
|
||||
instantSearchQueries = new Array();
|
||||
}
|
||||
|
||||
$("#search_query_block").keyup(function(){
|
||||
if($(this).val().length > 0){
|
||||
stopInstantSearchQueries();
|
||||
instantSearchQuery = $.ajax({
|
||||
url: '{/literal}{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}{literal}',
|
||||
data: 'instantSearch=1&id_lang={/literal}{$cookie->id_lang}{literal}&q='+$(this).val(),
|
||||
dataType: 'html',
|
||||
success: function(data){
|
||||
if($("#search_query_block").val().length > 0)
|
||||
{
|
||||
tryToCloseInstantSearch();
|
||||
$('#center_column').attr('id', 'old_center_column');
|
||||
$('#old_center_column').after('<div id="center_column">'+data+'</div>');
|
||||
$('#old_center_column').hide();
|
||||
$("#instant_search_results a.close").click(function() {
|
||||
$("#search_query_block").val('');
|
||||
return tryToCloseInstantSearch();
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
}
|
||||
});
|
||||
instantSearchQueries.push(instantSearchQuery);
|
||||
}
|
||||
else
|
||||
tryToCloseInstantSearch();
|
||||
});
|
||||
// ]]>
|
||||
{/literal}
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{if $ajaxsearch}
|
||||
<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
{literal}
|
||||
$('document').ready( function() {
|
||||
$("#search_query_block")
|
||||
.autocomplete(
|
||||
'{/literal}{if $search_ssl == 1}{$link->getPageLink('search', true)}{else}{$link->getPageLink('search')}{/if}{literal}', {
|
||||
minChars: 3,
|
||||
max: 10,
|
||||
width: 500,
|
||||
selectFirst: false,
|
||||
scroll: false,
|
||||
dataType: "json",
|
||||
formatItem: function(data, i, max, value, term) {
|
||||
return value;
|
||||
},
|
||||
parse: function(data) {
|
||||
var mytab = new Array();
|
||||
for (var i = 0; i < data.length; i++)
|
||||
mytab[mytab.length] = { data: data[i], value: data[i].cname + ' > ' + data[i].pname };
|
||||
return mytab;
|
||||
},
|
||||
extraParams: {
|
||||
ajaxSearch: 1,
|
||||
id_lang: {/literal}{$cookie->id_lang}{literal}
|
||||
}
|
||||
}
|
||||
)
|
||||
.result(function(event, data, formatted) {
|
||||
$('#search_query_block').val(data.pname);
|
||||
document.location.href = data.product_link;
|
||||
})
|
||||
});
|
||||
{/literal}
|
||||
// ]]>
|
||||
</script>
|
||||
{/if}
|
||||
{include file="$self/blocksearch-instantsearch.tpl"}
|
||||
<!-- /Block search module -->
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<module>
|
||||
<name>blocksearch</name>
|
||||
<displayName><![CDATA[Quick Search block]]></displayName>
|
||||
<version><![CDATA[1.1]]></version>
|
||||
<version><![CDATA[1.2]]></version>
|
||||
<description><![CDATA[Adds a block with a quick search field.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[search_filter]]></tab>
|
||||
|
||||
Reference in New Issue
Block a user