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

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

[extensions] Autosize fix compatibility with 2.4 (charlie's,Embedded Videos)

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