source: extensions/Versa/js/thumbnails.loader.js

Last change on this file was 31833, checked in by lexming, 7 years ago

Initial commit

  • Property svn:executable set to *
File size: 1.1 KB
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      img.parent().css( "background-image", "url(" + result.url + ")" );
21      img.parent().css( "background-size", "" );
22      jQuery('.loader').hide();
23    },
24    error: function() {
25      if (loop < 3)
26        add_thumbnail_to_queue(img, ++loop); // Retry 3 times
27      if ( typeof( error_icon ) != "undefined" )
28        img.attr('src', error_icon);
29      jQuery('.loader').hide();
30    }
31  }); 
32}
33
34function pwg_ajax_thumbnails_loader() {
35  jQuery('img[data-src]').each(function() {
36    add_thumbnail_to_queue(jQuery(this), 0);
37  });
38}
39
40jQuery(document).ready(pwg_ajax_thumbnails_loader);
Note: See TracBrowser for help on using the repository browser.