Ignore:
Timestamp:
Jan 17, 2013, 7:38:54 PM (11 years ago)
Author:
flop25
Message:

bug:2820 & bug:2684
much better code : ability to pass max_requests to the js file like error_icon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/themes/default/template/mainpage_categories.tpl

    r20161 r20212  
    88}
    99{/html_style}{/strip}
     10{footer_script}
     11  var error_icon = "{$ROOT_URL}{$themeconf.icon_dir}/errors_small.png";
     12  var max_requests = "{$maxRequests}";
     13{/footer_script}
    1014<div class="loader" style="display: none; position: fixed; right: 0;bottom: 0;"><img src="{$ROOT_URL}{$themeconf.img_dir}/ajax_loader.gif"></div>
    1115<ul class="thumbnailCategories">
    1216{foreach from=$category_thumbnails item=cat name=cat_loop}
    1317{assign var=derivative value=$pwg->derivative($derivative_params, $cat.representative.src_image)}
    14 {if !$derivative->is_cached() and !$js_loaded}
     18{if !$derivative->is_cached()}
    1519{combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load='footer'}
    16 {*combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'*}
    17 {footer_script}{literal}
    18 var thumbnails_queue = jQuery.manageAjax.create('queued', {
    19   queue: true, 
    20   cacheResponse: false,
    21   maxRequests: {/literal}{$maxRequests}{literal},
    22   preventDoubleRequests: false
    23 });
    24 
    25 function add_thumbnail_to_queue(img, loop) {
    26   thumbnails_queue.add({
    27     type: 'GET',
    28     url: img.data('src'),
    29     data: { ajaxload: 'true' },
    30     dataType: 'json',
    31     beforeSend: function(){jQuery('.loader').show()},
    32     success: function(result) {
    33       img.attr('src', result.url);
    34       jQuery('.loader').hide();
    35     },
    36     error: function() {
    37       if (loop < 3)
    38         add_thumbnail_to_queue(img, ++loop); // Retry 3 times
    39       img.attr('src', {/literal}"{$ROOT_URL}{$themeconf.icon_dir}/errors_small.png"{literal});
    40       jQuery('.loader').hide();
    41     }
    42   });
    43 }
    44 
    45 function pwg_ajax_thumbnails_loader() {
    46   jQuery('img[data-src]').each(function() {
    47     add_thumbnail_to_queue(jQuery(this), 0);
    48   });
    49 }
    50 jQuery(document).ready(pwg_ajax_thumbnails_loader);
    51 {/literal}{/footer_script}
    52 {assign var=js_loaded value=true}
     20{combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'}
    5321{/if}
    5422  <li class="{if $smarty.foreach.cat_loop.index is odd}odd{else}even{/if}">
Note: See TracChangeset for help on using the changeset viewer.