// call to checkUrl() only if the URL has changed
This commit is contained in:
1 parent
16de31ac9e
commit
4d0719d8f7
1 file changed
+44
-35
@@ -621,51 +621,60 @@ function getProductAttribute()
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
original_url = window.location+'';
|
||||||
|
first_url_check = true;
|
||||||
checkUrl();
|
checkUrl();
|
||||||
initLocationChange(2000);
|
initLocationChange();
|
||||||
});
|
});
|
||||||
|
|
||||||
function initLocationChange(time)
|
function initLocationChange(time)
|
||||||
{
|
{
|
||||||
if(!time) time = 1000;
|
if(!time) time = 500;
|
||||||
setInterval(checkUrl, time);
|
setInterval(checkUrl, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkUrl()
|
function checkUrl()
|
||||||
{
|
{
|
||||||
url = window.location+'';
|
if (original_url != window.location || first_url_check)
|
||||||
// if we need to load a specific combination
|
|
||||||
if (url.indexOf('#/') != -1)
|
|
||||||
{
|
{
|
||||||
// get the params to fill from a "normal" url
|
first_url_check = false;
|
||||||
params = url.substring(url.indexOf('#') + 1, url.length);
|
url = window.location+'';
|
||||||
tabParams = params.split('/');
|
// if we need to load a specific combination
|
||||||
tabValues = new Array();
|
if (url.indexOf('#/') != -1)
|
||||||
if (tabParams[0] == '')
|
{
|
||||||
tabParams.shift();
|
// get the params to fill from a "normal" url
|
||||||
for (i in tabParams)
|
params = url.substring(url.indexOf('#') + 1, url.length);
|
||||||
tabValues.push(tabParams[i].split('-'));
|
tabParams = params.split('/');
|
||||||
product_id = $('#product_page_product_id').val();
|
tabValues = new Array();
|
||||||
// fill html with values
|
if (tabParams[0] == '')
|
||||||
$('.color_pick').removeClass('selected');
|
tabParams.shift();
|
||||||
count = 0;
|
for (i in tabParams)
|
||||||
for (z in tabValues)
|
tabValues.push(tabParams[i].split('-'));
|
||||||
for (a in attributesCombinations)
|
product_id = $('#product_page_product_id').val();
|
||||||
if (attributesCombinations[a]['group'] == tabValues[z][0]
|
// fill html with values
|
||||||
&& attributesCombinations[a]['attribute'] == tabValues[z][1])
|
$('.color_pick').removeClass('selected');
|
||||||
{
|
count = 0;
|
||||||
count++;
|
for (z in tabValues)
|
||||||
// add class 'selected' to the selected color
|
for (a in attributesCombinations)
|
||||||
$('#color_'+attributesCombinations[a]['id_attribute']).addClass('selected');
|
if (attributesCombinations[a]['group'] == tabValues[z][0]
|
||||||
$('input:radio[value='+attributesCombinations[a]['id_attribute']+']').attr('checked', 'checked');
|
&& attributesCombinations[a]['attribute'] == tabValues[z][1])
|
||||||
$('input:hidden[name=group_'+attributesCombinations[a]['id_attribute_group']+']').val(attributesCombinations[a]['id_attribute']);
|
{
|
||||||
$('select[name=group_'+attributesCombinations[a]['id_attribute_group']+']').val(attributesCombinations[a]['id_attribute']);
|
count++;
|
||||||
}
|
// add class 'selected' to the selected color
|
||||||
// find combination
|
$('#color_'+attributesCombinations[a]['id_attribute']).addClass('selected');
|
||||||
if (count > 0)
|
$('input:radio[value='+attributesCombinations[a]['id_attribute']+']').attr('checked', 'checked');
|
||||||
findCombination();
|
$('input:hidden[name=group_'+attributesCombinations[a]['id_attribute_group']+']').val(attributesCombinations[a]['id_attribute']);
|
||||||
// no combination found = removing attributes from url
|
$('select[name=group_'+attributesCombinations[a]['id_attribute_group']+']').val(attributesCombinations[a]['id_attribute']);
|
||||||
else
|
}
|
||||||
window.location = url.substring(0, url.indexOf('#'));
|
// find combination
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
findCombination();
|
||||||
|
original_url = window.location+'';
|
||||||
|
}
|
||||||
|
// no combination found = removing attributes from url
|
||||||
|
else
|
||||||
|
window.location = url.substring(0, url.indexOf('#'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user