source: trunk/themes/default/js/thumbnails.loader.js @ 20212

Last change on this file since 20212 was 20212, checked in by flop25, 11 years ago

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

File size: 990 bytes
Line 
1if ( typeof( max_requests ) == "undefined" )
2  max_requests = 3;
3
4var thumbnails_queue = jQuery.manageAjax.create('queued', {
5  queue: true, 
6  cacheResponse: false,
7  maxRequests: max_requests,
8  preventDoubleRequests: false
9});
10
11function add_thumbnail_to_queue(img, loop) {
12  thumbnails_queue.add({
13    type: 'GET', 
14    url: img.data('src'), 
15    data: { ajaxload: 'true' },
16    dataType: 'json',
17    beforeSend: function(){jQuery('.loader').show()},
18    success: function(result) {
19      img.attr('src', result.url);
20      jQuery('.loader').hide();
21    },
22    error: function() {
23      if (loop < 3)
24        add_thumbnail_to_queue(img, ++loop); // Retry 3 times
25      if ( typeof( error_icon ) != "undefined" )
26        img.attr('src', error_icon);
27      jQuery('.loader').hide();
28    }
29  }); 
30}
31
32function pwg_ajax_thumbnails_loader() {
33  jQuery('img[data-src]').each(function() {
34    add_thumbnail_to_queue(jQuery(this), 0);
35  });
36}
37
38jQuery(document).ready(pwg_ajax_thumbnails_loader);
Note: See TracBrowser for help on using the repository browser.