PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jandcode-wax-core/src/jandcode/wax/core/js/jquery/plupload/plupload.html4.js

https://bitbucket.org/gkraser/jandcode-core
JavaScript | 235 lines | 232 code | 3 blank | 0 comment | 49 complexity | a8fb7bb573a5466e9aec5f9e3c6e21f1 MD5 | raw file
  1. (function(d, a, b, c) {
  2. function e(f) {
  3. return a.getElementById(f)
  4. }
  5. b.runtimes.Html4 = b.addRuntime("html4", {getFeatures: function() {
  6. return{multipart: true, triggerDialog: (b.ua.gecko && d.FormData || b.ua.webkit)}
  7. }, init: function(f, g) {
  8. f.bind("Init", function(p) {
  9. var j = a.body, n, h = "javascript", k, x, q, z = [], r = /MSIE/.test(navigator.userAgent), t = [], m = p.settings.filters, o, l, s, w;
  10. no_type_restriction:for (o = 0; o < m.length; o++) {
  11. l = m[o].extensions.split(/,/);
  12. for (w = 0; w < l.length; w++) {
  13. if (l[w] === "*") {
  14. t = [];
  15. break no_type_restriction
  16. }
  17. s = b.mimeTypes[l[w]];
  18. if (s && b.inArray(s, t) === -1) {
  19. t.push(s)
  20. }
  21. }
  22. }
  23. t = t.join(",");
  24. function v() {
  25. var B, y, i, A;
  26. q = b.guid();
  27. z.push(q);
  28. B = a.createElement("form");
  29. B.setAttribute("id", "form_" + q);
  30. B.setAttribute("method", "post");
  31. B.setAttribute("enctype", "multipart/form-data");
  32. B.setAttribute("encoding", "multipart/form-data");
  33. B.setAttribute("target", p.id + "_iframe");
  34. B.style.position = "absolute";
  35. y = a.createElement("input");
  36. y.setAttribute("id", "input_" + q);
  37. y.setAttribute("type", "file");
  38. y.setAttribute("accept", t);
  39. y.setAttribute("size", 1);
  40. A = e(p.settings.browse_button);
  41. if (p.features.triggerDialog && A) {
  42. b.addEvent(e(p.settings.browse_button), "click", function(C) {
  43. if (!y.disabled) {
  44. y.click()
  45. }
  46. C.preventDefault()
  47. }, p.id)
  48. }
  49. b.extend(y.style, {width: "100%", height: "100%", opacity: 0, fontSize: "99px", cursor: "pointer"});
  50. b.extend(B.style, {overflow: "hidden"});
  51. i = p.settings.shim_bgcolor;
  52. if (i) {
  53. B.style.background = i
  54. }
  55. if (r) {
  56. b.extend(y.style, {filter: "alpha(opacity=0)"})
  57. }
  58. b.addEvent(y, "change", function(F) {
  59. var D = F.target, C, E = [], G;
  60. if (D.value) {
  61. e("form_" + q).style.top = -1048575 + "px";
  62. C = D.value.replace(/\\/g, "/");
  63. C = C.substring(C.length, C.lastIndexOf("/") + 1);
  64. E.push(new b.File(q, C));
  65. if (!p.features.triggerDialog) {
  66. b.removeAllEvents(B, p.id)
  67. } else {
  68. b.removeEvent(A, "click", p.id)
  69. }
  70. b.removeEvent(y, "change", p.id);
  71. v();
  72. if (E.length) {
  73. f.trigger("FilesAdded", E)
  74. }
  75. }
  76. }, p.id);
  77. B.appendChild(y);
  78. j.appendChild(B);
  79. p.refresh()
  80. }
  81. function u() {
  82. var i = a.createElement("div");
  83. i.innerHTML = '<iframe id="' + p.id + '_iframe" name="' + p.id + '_iframe" src="' + h + ':&quot;&quot;" style="display:none"></iframe>';
  84. n = i.firstChild;
  85. j.appendChild(n);
  86. b.addEvent(n, "load", function(C) {
  87. var D = C.target, B, y;
  88. if (!k) {
  89. return
  90. }
  91. try {
  92. B = D.contentWindow.document || D.contentDocument || d.frames[D.id].document
  93. } catch(A) {
  94. p.trigger("Error", {code: b.SECURITY_ERROR, message: b.translate("Security error."), file: k});
  95. return
  96. }
  97. y = B.body.innerHTML;
  98. if (y) {
  99. k.status = b.DONE;
  100. k.loaded = 1025;
  101. k.percent = 100;
  102. p.trigger("UploadProgress", k);
  103. p.trigger("FileUploaded", k, {response: y})
  104. }
  105. }, p.id)
  106. }
  107. if (p.settings.container) {
  108. j = e(p.settings.container);
  109. if (b.getStyle(j, "position") === "static") {
  110. j.style.position = "relative"
  111. }
  112. }
  113. p.bind("UploadFile", function(i, A) {
  114. var B, y;
  115. if (A.status == b.DONE || A.status == b.FAILED || i.state == b.STOPPED) {
  116. return
  117. }
  118. B = e("form_" + A.id);
  119. y = e("input_" + A.id);
  120. y.setAttribute("name", i.settings.file_data_name);
  121. B.setAttribute("action", i.settings.url);
  122. b.each(b.extend({name: A.target_name || A.name}, i.settings.multipart_params), function(E, C) {
  123. var D = a.createElement("input");
  124. b.extend(D, {type: "hidden", name: C, value: E});
  125. B.insertBefore(D, B.firstChild)
  126. });
  127. k = A;
  128. e("form_" + q).style.top = -1048575 + "px";
  129. B.submit()
  130. });
  131. p.bind("FileUploaded", function(i) {
  132. i.refresh()
  133. });
  134. p.bind("StateChanged", function(i) {
  135. if (i.state == b.STARTED) {
  136. u()
  137. } else {
  138. if (i.state == b.STOPPED) {
  139. d.setTimeout(function() {
  140. b.removeEvent(n, "load", i.id);
  141. if (n.parentNode) {
  142. n.parentNode.removeChild(n)
  143. }
  144. }, 0)
  145. }
  146. }
  147. b.each(i.files, function(A, y) {
  148. if (A.status === b.DONE || A.status === b.FAILED) {
  149. var B = e("form_" + A.id);
  150. if (B) {
  151. B.parentNode.removeChild(B)
  152. }
  153. }
  154. })
  155. });
  156. p.bind("Refresh", function(y) {
  157. var F, A, B, C, i, G, H, E, D;
  158. F = e(y.settings.browse_button);
  159. if (F) {
  160. i = b.getPos(F, e(y.settings.container));
  161. G = b.getSize(F);
  162. H = e("form_" + q);
  163. E = e("input_" + q);
  164. b.extend(H.style, {top: i.y + "px", left: i.x + "px", width: G.w + "px", height: G.h + "px"});
  165. if (y.features.triggerDialog) {
  166. if (b.getStyle(F, "position") === "static") {
  167. b.extend(F.style, {position: "relative"})
  168. }
  169. D = parseInt(F.style.zIndex, 10);
  170. if (isNaN(D)) {
  171. D = 0
  172. }
  173. b.extend(F.style, {zIndex: D});
  174. b.extend(H.style, {zIndex: D - 1})
  175. }
  176. B = y.settings.browse_button_hover;
  177. C = y.settings.browse_button_active;
  178. A = y.features.triggerDialog ? F : H;
  179. if (B) {
  180. b.addEvent(A, "mouseover", function() {
  181. b.addClass(F, B)
  182. }, y.id);
  183. b.addEvent(A, "mouseout", function() {
  184. b.removeClass(F, B)
  185. }, y.id)
  186. }
  187. if (C) {
  188. b.addEvent(A, "mousedown", function() {
  189. b.addClass(F, C)
  190. }, y.id);
  191. b.addEvent(a.body, "mouseup", function() {
  192. b.removeClass(F, C)
  193. }, y.id)
  194. }
  195. }
  196. });
  197. f.bind("FilesRemoved", function(y, B) {
  198. var A, C;
  199. for (A = 0; A < B.length; A++) {
  200. C = e("form_" + B[A].id);
  201. if (C) {
  202. C.parentNode.removeChild(C)
  203. }
  204. }
  205. });
  206. f.bind("DisableBrowse", function(i, A) {
  207. var y = a.getElementById("input_" + q);
  208. if (y) {
  209. y.disabled = A
  210. }
  211. });
  212. f.bind("Destroy", function(i) {
  213. var y, A, B, C = {inputContainer: "form_" + q, inputFile: "input_" + q, browseButton: i.settings.browse_button};
  214. for (y in C) {
  215. A = e(C[y]);
  216. if (A) {
  217. b.removeAllEvents(A, i.id)
  218. }
  219. }
  220. b.removeAllEvents(a.body, i.id);
  221. b.each(z, function(E, D) {
  222. B = e("form_" + E);
  223. if (B) {
  224. j.removeChild(B)
  225. }
  226. })
  227. });
  228. v()
  229. });
  230. g({success: true})
  231. }})
  232. })(window, document, plupload);