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
RevLine 
[18716]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() {
[18723]13            derivatives.elements.splice(0, 1);
[18716]14                        return derivatives.done == derivatives.total && derivatives.elements && derivatives.elements.length==0;
15                  }
16      };
17   
[18723]18  function progress(success,data) {
[18716]19    if (success) {
[18735]20      jQuery("#theMainImage").height(params.height[derivatives.done]);
[18737]21      jQuery("#theMainImage").width(params.width[derivatives.done]);
22
[18735]23      jQuery("#theMainImage").show();
[18723]24      jQuery("#theMainImage").trigger("ON", [{ nb: derivatives.total - derivatives.done, total: derivatives.total, done: derivatives.done,status:"ok",src:data.url}]);
[18716]25    } else {
[18731]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}]);
[18723]31    }
[18731]32    }
[18723]33
34    if (derivatives.finished()) {
35      jQuery("#theMainImage").trigger("Finish", [derivatives]);
[18716]36    }
[18723]37
[18716]38    }
39
40  derivatives.elements = [];
41  var ids = derivatives.elements.splice(0, 500);
[18735]42  var params = { max_urls: 10, ids: ids, types: [], src: [],width:[], height:[]  };
[18716]43
44  function getDerivativeUrls(nofile) {
[18723]45    params.max_urls = nofile.length;
[18716]46    jQuery(nofile).each(function (i, t) {
[18723]47      if (typeof t.file != "undefined") {
48        nbsrc = params.src.length;
[18731]49        t.file=   t.file.replace("/","",1);
[18723]50        if (nbsrc == 0) {
51          params.ids.push(t.id);
52          params.types.push(t.type);
53          params.src.push(t.file);
[18735]54          params.width.push(t.width);
55          params.height.push(t.height);
56
[18731]57        } else if (~jQuery.inArray(t.file, params.src)) {
[18723]58          jQuery.noop();
59        } else {
60          params.ids.push(t.id);
61          params.types.push(t.type);
62          params.src.push(t.file);
[18735]63          params.width.push(t.width);
64          params.height.push(t.height);
[18723]65        }
[18716]66      }
[18723]67    });
[18731]68
[18723]69    if(derivatives.elements.length==0)
[18731]70            derivatives.elements = params.ids;
71    derivatives.total += params.src.length;
[18716]72
[18723]73
[18735]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              }),
[18731]103
[18735]104              complete: (function (data) {
105                progress(false, data);
106              }),
107              isRejected: (function (data) {
108                a = data.responseText;
109              })
110
111            });
112        }
113
[18723]114      }
[18731]115    }
116
[18735]117    jQuery("body").append("<div style='position:abosolute;left:-200;top:-200'>");
[18731]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
[18716]126  //===============================================================
Note: See TracBrowser for help on using the repository browser.