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

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

[extensions] Autosize fix compatibility with 2.4 (option marge bottom)

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