0

I got this 'ReferenceError: display is not defined' where my script link are as below.

<script type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/ui/jquery-ui-1.8.16.custom.min.js"></script>

I replace them with latest version 1.11.1 and tried with

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

But still there is Reference Error. What should i change my display function(Script):

function display(view) {
  if (view == 'list') {
    $('.product-grid').attr('class', 'product-list');
    $('.product-list > div').each(function(index, element) {
        html = '<div class="left">';
        var image = $(element).find('.image').html();   
        if (image != null) { 
            html += '<div class="image">' + image + '</div>';
        }
        html += '<div class="mask hide-phone">';
        html += '  <div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
        html += '  <div class="compare">' + $(element).find('.compare').html() + '</div>';
        html += '</div>';           
        html += '  <div class="name">' + $(element).find('.name').html() + '</div>';
        html += '  <div class="description">' + $(element).find('.description').html() + '</div>';
        var rating = $(element).find('.rating').html();         
        if (rating != null) {
            html += '<div class="rating">' + rating + '</div>';
        }
        var price = $(element).find('.price').html();       
        if (price != null) {
            html += '<div class="price">' + price  + '</div>';
        }
        html += '  <div class="cart">' + $(element).find('.cart').html() + '</div>';
        html += '  <div class="cart-phone show-phone hide-desktop hide-tablet">' + $(element).find('.cart-phone').html() + '</div>';            
        html += '</div>';
        $(element).html(html);
    });     
    $('.display').html(' <div id="list_b"></div>  <a id="grid_a" title="<?php echo $text_grid; ?>" onclick="display(\'grid\');"></a>');
    $.totalStorage('display', 'list'); 
    } else {
    $('.product-list').attr('class', 'product-grid');
    $('.product-grid > div').each(function(index, element) {
        html = '';
        var image = $(element).find('.image').html();
    if (image != null) {
            html += '<div class="image">' + image + '</div>';
        }
        html += '<div class="mask hide-phone">';
        html += '  <div class="wishlist">' + $(element).find('.wishlist').html() + '</div>';
        html += '  <div class="compare">' + $(element).find('.compare').html() + '</div>';
        html += '</div>';
        html += '<div class="name">' + $(element).find('.name').html() + '</div>';
        html += '<div class="description">' + $(element).find('.description').html() + '</div>';
    var rating = $(element).find('.rating').html();
        if (rating != null) {
            html += '<div class="rating">' + rating + '</div>';
        }
        var price = $(element).find('.price').html();
        if (price != null) {
            html += '<div class="price">' + price  + '</div>';
        }
        html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
        html += '  <div class="cart-phone show-phone hide-desktop hide-tablet">' + $(element).find('.cart-phone').html() + '</div>';
        $(element).html(html);
    });                     
    $('.display').html(' <a id="list_a" title="<?php echo $text_list; ?>" onclick="display(\'list\');"><?php echo $text_list; ?></a> <div id="grid_b"></div>');
$.totalStorage('display', 'grid');
  }
 }
view = $.totalStorage('display');    
if (view) {    
    display(view);    
} else {    
    display('list');    
}
shankar.parshimoni
  • 1,279
  • 4
  • 22
  • 42
Piyush
  • 3,697
  • 7
  • 31
  • 63

1 Answers1

2

you can see that your conactenation is creating issues:
copied from the source of your link

            html += '  
                     <div class="cart" >
                    ' + $(element).find('.cart').html() + '</div>';

at this line your div is having a newline character. may be this is caused by something else but you can do this:

    html += '  <div class="cart">' + $(element).find('.cart').html() + '</div>';
    html += '  <div class="cart-phone show-phone hide-desktop hide-tablet">' + $(element).find('.cart-phone').html() + '</div>';            
    html += '</div>';

here you can see html+=' <div>' this line is having a space before the div so you can remove it.

    html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
    html += '<div class="cart-phone show-phone hide-desktop hide-tablet">' + $(element).find('.cart-phone').html() + '</div>';            
    html += '</div>';
Jai
  • 71,335
  • 12
  • 70
  • 93