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

Last change on this file since 18737 was 18737, checked in by cljosse, 12 years ago

[extensions] Autosize fix compatibility with 2.4 (prechargement)

File size: 3.9 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").height(params.height[derivatives.done]);
21      jQuery("#theMainImage").width(params.width[derivatives.done]);
22
23      jQuery("#theMainImage").show();
24      jQuery("#theMainImage").trigger("ON", [{ nb: derivatives.total - derivatives.done, total: derivatives.total, done: derivatives.done,status:"ok",src:data.url}]);
25    } else {
26
27    if (data.statusText == "OK") {
28 
29    } else {
30      jQuery("#theMainImage").trigger("ON", [{ nb: derivatives.total - derivatives.done, total: derivatives.total, done: derivatives.done, status: "Nok", responseText: data.responseText}]);
31    }
32    }
33
34    if (derivatives.finished()) {
35      jQuery("#theMainImage").trigger("Finish", [derivatives]);
36    }
37
38    }
39
40  derivatives.elements = [];
41  var ids = derivatives.elements.splice(0, 500);
42  var params = { max_urls: 10, ids: ids, types: [], src: [],width:[], height:[]  };
43
44  function getDerivativeUrls(nofile) {
45    params.max_urls = nofile.length;
46    jQuery(nofile).each(function (i, t) {
47      if (typeof t.file != "undefined") {
48        nbsrc = params.src.length;
49        t.file=   t.file.replace("/","",1);
50        if (nbsrc == 0) {
51          params.ids.push(t.id);
52          params.types.push(t.type);
53          params.src.push(t.file);
54          params.width.push(t.width);
55          params.height.push(t.height);
56
57        } else if (~jQuery.inArray(t.file, params.src)) {
58          jQuery.noop();
59        } else {
60          params.ids.push(t.id);
61          params.types.push(t.type);
62          params.src.push(t.file);
63          params.width.push(t.width);
64          params.height.push(t.height);
65        }
66      }
67    });
68
69    if(derivatives.elements.length==0)
70            derivatives.elements = params.ids;
71    derivatives.total += params.src.length;
72
73
74    Set_images = function (dataUrls) {
75      if (typeof jQuery.manageAjax != "undefined") {
76        for (var i = 0; i < dataUrls.length; i++) {
77          fichier = dataUrls[i];
78          if (fichier != "")
79            jQuery.manageAjax.add("queued", {
80              type: 'GET',
81              url: 'i.php?' + fichier + "&ajaxload=true",
82              dataType: 'json',
83              success: (function (data) {
84                j = derivatives.done;
85                derivatives.done++;
86                for (var j = 0; j < params.src.length; j++) {
87                  if (data.url.match(params.src[j])) {
88                    params.src[j] = ""; break;
89                  }
90                }
91                progress(true, data);
92              }),
93              error: (function (data) {
94                // derivatives.done++;
95                progress(data.statusText == "NOK", data);
96              }),
97              fail: (function (data) {
98                a = data.statusText;
99              }),
100              progress: (function (data) {
101                a = data.statusText;
102              }),
103
104              complete: (function (data) {
105                progress(false, data);
106              }),
107              isRejected: (function (data) {
108                a = data.responseText;
109              })
110
111            });
112        }
113
114      }
115    }
116
117    jQuery("body").append("<div style='position:abosolute;left:-200;top:-200'>");
118  if (derivatives.elements.length) {
119    if (derivatives.total - derivatives.done > 0)
120      setTimeout("Set_images(params.src)", 500 * (derivatives.total - derivatives.done));
121  }
122
123   
124
125        } //ready
126  //===============================================================
Note: See TracBrowser for help on using the repository browser.