Jump to content

Error When Minifying Inline Javascript ( JSMin: Unterminated String at byte 3608)


Recommended Posts

Hello,

 

I have an inline JS code that uses a smarty function. The problem im having is that when I enable the minify inline HTMl config, Im getting a JSMin error and my entires javascript fails on my page.

 

This is the code:

 

if(hasVisacuotas){
    $('#total_price_summary').text('{displayPrice price=$total_price_without_tax}');

    // Add extra fee row from cart summary
    $('#cart_discount_'+visacuotasFee.id_cart_rule).show();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).show();
    $('#activeMultiPayments').prop('checked', true);
    $('.visacuotas-selector').removeClass('hidden');
}
else{
    $('#cart_discount_'+visacuotasFee.id_cart_rule).hide();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).hide();
    $('#activeMultiPayments').prop('checked', false);
    $('.visacuotas-selector').addClass('hidden');
}

 

In that state, the JSMin throws:

 JSMin: Unterminated String at byte 3608

 

If I comment the line of the smarty function

if(hasVisacuotas){
    {*$('#total_price_summary').text('{displayPrice price=$total_price_without_tax}');*}

    // Add extra fee row from cart summary
    $('#cart_discount_'+visacuotasFee.id_cart_rule).show();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).show();
    $('#activeMultiPayments').prop('checked', true);
    $('.visacuotas-selector').removeClass('hidden');
}
else{
    $('#cart_discount_'+visacuotasFee.id_cart_rule).hide();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).hide();
    $('#activeMultiPayments').prop('checked', false);
    $('.visacuotas-selector').addClass('hidden');
}

 

It all works fine.

 

How can I use the smarty function in the inline JS without disabling the inline compression of JS?

 

 

 

Link to comment
Share on other sites

Hello,

Try creating a variable first:

var total_price_without_tax = '{displayPrice price=$total_price_without_tax}';

if(hasVisacuotas){
    $('#total_price_summary').text(total_price_without_tax);

    // Add extra fee row from cart summary
    $('#cart_discount_'+visacuotasFee.id_cart_rule).show();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).show();
    $('#activeMultiPayments').prop('checked', true);
    $('.visacuotas-selector').removeClass('hidden');
}
else{
    $('#cart_discount_'+visacuotasFee.id_cart_rule).hide();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).hide();
    $('#activeMultiPayments').prop('checked', false);
    $('.visacuotas-selector').addClass('hidden');
}

I really don't know if this works, but you can try,

 

Regards!

Link to comment
Share on other sites

On 7/22/2018 at 10:35 AM, Rolige said:

Hello,

Try creating a variable first:


var total_price_without_tax = '{displayPrice price=$total_price_without_tax}';

if(hasVisacuotas){
    $('#total_price_summary').text(total_price_without_tax);

    // Add extra fee row from cart summary
    $('#cart_discount_'+visacuotasFee.id_cart_rule).show();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).show();
    $('#activeMultiPayments').prop('checked', true);
    $('.visacuotas-selector').removeClass('hidden');
}
else{
    $('#cart_discount_'+visacuotasFee.id_cart_rule).hide();
    $('#extrafee_cart_'+visacuotasFee.id_cart_rule).hide();
    $('#activeMultiPayments').prop('checked', false);
    $('.visacuotas-selector').addClass('hidden');
}

I really don't know if this works, but you can try,

 

Regards!

Thanks for the answer... but it did not work :(

Link to comment
Share on other sites

Ok, maybe the issue could be that the variable "$total_price_without_tax" doesn't exists in that section, thats why it works perfectly when you comment the code, I do not think there is another explanation.

Regards!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...