Line | |
---|
1 | if ( typeof( max_requests ) == "undefined" ) |
---|
2 | max_requests = 3; |
---|
3 | |
---|
4 | var thumbnails_queue = jQuery.manageAjax.create('queued', { |
---|
5 | queue: true, |
---|
6 | cacheResponse: false, |
---|
7 | maxRequests: max_requests, |
---|
8 | preventDoubleRequests: false |
---|
9 | }); |
---|
10 | |
---|
11 | function 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 | |
---|
32 | function pwg_ajax_thumbnails_loader() { |
---|
33 | jQuery('img[data-src]').each(function() { |
---|
34 | add_thumbnail_to_queue(jQuery(this), 0); |
---|
35 | }); |
---|
36 | } |
---|
37 | |
---|
38 | jQuery(document).ready(pwg_ajax_thumbnails_loader); |
---|
Note: See
TracBrowser
for help on using the repository browser.