source: extensions/Autosize/js/autosize_ajax.js @ 18724

Last change on this file since 18724 was 18724, checked in by cljosse, 11 years ago

[extensions] Autosize fix compatibility with 2.4 (init picture)

File size: 3.2 KB
Line 
1jQuery(document).ready(
2  function (jQuery) {
3
4
5  });
6
7  //============================================================
8   var derivatives = {
9            elements: null,
10            done: 0,
11            total: 0,   
12            finished: function() {
13            derivatives.elements.splice(0, 1);
14                        return derivatives.done == derivatives.total && derivatives.elements && derivatives.elements.length==0;
15                  }
16      };
17   
18  function progress(success,data) {
19    if (success) {
20      jQuery("#theMainImage").trigger("ON", [{ nb: derivatives.total - derivatives.done, total: derivatives.total, done: derivatives.done,status:"ok",src:data.url}]);
21    } else {
22      jQuery("#theMainImage").trigger("ON", [{ nb: derivatives.total - derivatives.done, total: derivatives.total, done: derivatives.done, status: "Nok"}]);
23    }
24
25    if (derivatives.finished()) {
26      jQuery("#theMainImage").trigger("Finish", [derivatives]);
27    }
28
29    }
30
31  derivatives.elements = [];
32  var ids = derivatives.elements.splice(0, 500);
33  var params = { max_urls: 10, ids: ids, types: [], src: []  };
34
35  function getDerivativeUrls(nofile) {
36    params.max_urls = nofile.length;
37    popup = jQuery(".infos");
38    if (popup.length == 0) {
39   //   jQuery("#theImage").append("<div class='infos'></div>");
40    }
41
42    jQuery(nofile).each(function (i, t) {
43      if (typeof t.file != "undefined") {
44        nbsrc = params.src.length;
45        if (nbsrc == 0) {
46          params.ids.push(t.id);
47          params.types.push(t.type);
48          params.src.push(t.file);
49        }else if (~jQuery.inArray( t.file,params.src )) {
50          jQuery.noop();
51        } else {
52          params.ids.push(t.id);
53          params.types.push(t.type);
54          params.src.push(t.file);
55
56        }
57      }
58    });
59    if(derivatives.elements.length==0)
60    derivatives.elements = params.ids;
61
62
63    jQuery.ajax({
64      type: "POST",
65      url: 'ws.php?format=json&method=pwg.getMissingDerivatives',
66      data: params,
67      dataType: "json",
68      success: function (data) {
69        if (!data.stat || data.stat != "ok") {
70          return;
71        }
72        derivatives.total += data.result.urls.length;
73        if (typeof jQuery.manageAjax != "undefined") {
74          for (var i = 0; i < data.result.urls.length; i++) {
75         
76            jQuery.manageAjax.add("queued", {
77              type: 'GET',
78              url: data.result.urls[i] + "&ajaxload=true",
79              dataType: 'json',
80              success: (function (data) {
81                         derivatives.done++;
82                         progress(true, data);
83                      }),
84              error:  (function (data) {
85                          derivatives.done++; 
86                          progress(false, data);
87                      }) 
88              });
89          }
90          if (derivatives.elements.length) {     
91              if(derivatives.total - derivatives.done > 0    ) 
92                  setTimeout("getDerivativeUrls(nofile)", 100 * (derivatives.total - derivatives.done));
93          }
94        }
95      },
96      error: function (data) {
97        progress(false);
98      }
99    });
100        }
101  //===============================================================
Note: See TracBrowser for help on using the repository browser.