ueditor_rails4 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +45 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/images/ueditor/themes/default/anchor.gif +0 -0
  6. data/app/assets/images/ueditor/themes/default/arrow.png +0 -0
  7. data/app/assets/images/ueditor/themes/default/button-bg.gif +0 -0
  8. data/app/assets/images/ueditor/themes/default/cancelbutton.gif +0 -0
  9. data/app/assets/images/ueditor/themes/default/cursor_h.gif +0 -0
  10. data/app/assets/images/ueditor/themes/default/cursor_h.png +0 -0
  11. data/app/assets/images/ueditor/themes/default/cursor_v.gif +0 -0
  12. data/app/assets/images/ueditor/themes/default/cursor_v.png +0 -0
  13. data/app/assets/images/ueditor/themes/default/dialog-title-bg.png +0 -0
  14. data/app/assets/images/ueditor/themes/default/filescan.png +0 -0
  15. data/app/assets/images/ueditor/themes/default/highlighted.gif +0 -0
  16. data/app/assets/images/ueditor/themes/default/icons-all.gif +0 -0
  17. data/app/assets/images/ueditor/themes/default/icons.gif +0 -0
  18. data/app/assets/images/ueditor/themes/default/icons.png +0 -0
  19. data/app/assets/images/ueditor/themes/default/lock.gif +0 -0
  20. data/app/assets/images/ueditor/themes/default/neweditor-tab-bg.png +0 -0
  21. data/app/assets/images/ueditor/themes/default/pagebreak.gif +0 -0
  22. data/app/assets/images/ueditor/themes/default/scale.png +0 -0
  23. data/app/assets/images/ueditor/themes/default/spacer.gif +0 -0
  24. data/app/assets/images/ueditor/themes/default/sparator_v.png +0 -0
  25. data/app/assets/images/ueditor/themes/default/toolbar_bg.png +0 -0
  26. data/app/assets/images/ueditor/themes/default/unhighlighted.gif +0 -0
  27. data/app/assets/images/ueditor/themes/default/upload.png +0 -0
  28. data/app/assets/images/ueditor/themes/default/videologo.gif +0 -0
  29. data/app/assets/images/ueditor/themes/default/word.gif +0 -0
  30. data/app/assets/images/ueditor/themes/default/wordpaste.png +0 -0
  31. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_chm.gif +0 -0
  32. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_default.png +0 -0
  33. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_doc.gif +0 -0
  34. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_exe.gif +0 -0
  35. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_mp3.gif +0 -0
  36. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_mv.gif +0 -0
  37. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_pdf.gif +0 -0
  38. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_ppt.gif +0 -0
  39. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_psd.gif +0 -0
  40. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_rar.gif +0 -0
  41. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_txt.gif +0 -0
  42. data/app/assets/images/ueditor_rails/dialogs/attachment/fileTypeImages/icon_xls.gif +0 -0
  43. data/app/assets/images/ueditor_rails/dialogs/image/center_focus.jpg +0 -0
  44. data/app/assets/images/ueditor_rails/dialogs/image/left_focus.jpg +0 -0
  45. data/app/assets/images/ueditor_rails/dialogs/image/none_focus.jpg +0 -0
  46. data/app/assets/images/ueditor_rails/dialogs/image/right_focus.jpg +0 -0
  47. data/app/assets/images/ueditor_rails/dialogs/scrawl/addimg.png +0 -0
  48. data/app/assets/images/ueditor_rails/dialogs/scrawl/brush.png +0 -0
  49. data/app/assets/images/ueditor_rails/dialogs/scrawl/delimg.png +0 -0
  50. data/app/assets/images/ueditor_rails/dialogs/scrawl/delimgH.png +0 -0
  51. data/app/assets/images/ueditor_rails/dialogs/scrawl/empty.png +0 -0
  52. data/app/assets/images/ueditor_rails/dialogs/scrawl/emptyH.png +0 -0
  53. data/app/assets/images/ueditor_rails/dialogs/scrawl/eraser.png +0 -0
  54. data/app/assets/images/ueditor_rails/dialogs/scrawl/redo.png +0 -0
  55. data/app/assets/images/ueditor_rails/dialogs/scrawl/redoH.png +0 -0
  56. data/app/assets/images/ueditor_rails/dialogs/scrawl/scale.png +0 -0
  57. data/app/assets/images/ueditor_rails/dialogs/scrawl/scaleH.png +0 -0
  58. data/app/assets/images/ueditor_rails/dialogs/scrawl/size.png +0 -0
  59. data/app/assets/images/ueditor_rails/dialogs/scrawl/undo.png +0 -0
  60. data/app/assets/images/ueditor_rails/dialogs/scrawl/undoH.png +0 -0
  61. data/app/assets/javascripts/ueditor_rails/_config.js.erb +211 -0
  62. data/app/assets/javascripts/ueditor_rails/dialogs/attachment.js +5 -0
  63. data/app/assets/javascripts/ueditor_rails/dialogs/attachment/_callbacks.js +166 -0
  64. data/app/assets/javascripts/ueditor_rails/dialogs/attachment/_file_type_maps.js.erb +14 -0
  65. data/app/assets/javascripts/ueditor_rails/dialogs/image.js.erb +724 -0
  66. data/app/assets/javascripts/ueditor_rails/dialogs/scrawl.js +655 -0
  67. data/app/assets/javascripts/ueditor_rails/dialogs/wordimage.js +154 -0
  68. data/app/assets/javascripts/ueditor_rails/init.js +12 -0
  69. data/app/assets/stylesheets/ueditor/themes/default/dialogbase.css.erb +100 -0
  70. data/app/assets/stylesheets/ueditor/themes/default/ueditor.css +1582 -0
  71. data/app/assets/stylesheets/ueditor/themes/iframe.css +1 -0
  72. data/app/assets/stylesheets/ueditor_rails/dialogs/attachment.css.erb +161 -0
  73. data/app/assets/stylesheets/ueditor_rails/dialogs/image.css.erb +69 -0
  74. data/app/assets/stylesheets/ueditor_rails/dialogs/scrawl.css.erb +72 -0
  75. data/app/controllers/ueditor_rails/application_controller.rb +5 -0
  76. data/app/controllers/ueditor_rails/dialogs_controller.rb +21 -0
  77. data/app/controllers/ueditor_rails/libs_controller.rb +33 -0
  78. data/app/helpers/ueditor_rails/application_helper.rb +27 -0
  79. data/app/views/ueditor_rails/dialogs/attachment.html.erb +124 -0
  80. data/app/views/ueditor_rails/dialogs/image.html.erb +203 -0
  81. data/app/views/ueditor_rails/dialogs/scrawl.html.erb +96 -0
  82. data/app/views/ueditor_rails/dialogs/wordimage.html.erb +155 -0
  83. data/config/routes.rb +11 -0
  84. data/lib/generators/ueditor_rails/USAGE +8 -0
  85. data/lib/generators/ueditor_rails/install_generator.rb +15 -0
  86. data/lib/generators/ueditor_rails/templates/ueditor_config.js.erb +216 -0
  87. data/lib/tasks/ueditor_rails_tasks.rake +4 -0
  88. data/lib/ueditor_rails/engine.rb +17 -0
  89. data/lib/ueditor_rails/helpers/form_builder.rb +11 -0
  90. data/lib/ueditor_rails/helpers/form_helper.rb +37 -0
  91. data/lib/ueditor_rails/helpers/view_helper.rb +21 -0
  92. data/lib/ueditor_rails/util.rb +42 -0
  93. data/lib/ueditor_rails/version.rb +3 -0
  94. data/lib/ueditor_rails4.rb +32 -0
  95. data/test/dummy/README.rdoc +261 -0
  96. data/test/dummy/Rakefile +7 -0
  97. data/test/dummy/app/assets/javascripts/application.js +16 -0
  98. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  99. data/test/dummy/app/assets/javascripts/ueditor_config.js.erb +208 -0
  100. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  101. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  102. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  103. data/test/dummy/app/controllers/application_controller.rb +3 -0
  104. data/test/dummy/app/controllers/posts_controller.rb +83 -0
  105. data/test/dummy/app/helpers/application_helper.rb +2 -0
  106. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  107. data/test/dummy/app/models/post.rb +3 -0
  108. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  109. data/test/dummy/app/views/posts/_form.html.erb +25 -0
  110. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  111. data/test/dummy/app/views/posts/index.html.erb +29 -0
  112. data/test/dummy/app/views/posts/new.html.erb +5 -0
  113. data/test/dummy/app/views/posts/show.html.erb +14 -0
  114. data/test/dummy/config.ru +4 -0
  115. data/test/dummy/config/application.rb +61 -0
  116. data/test/dummy/config/boot.rb +10 -0
  117. data/test/dummy/config/database.yml +25 -0
  118. data/test/dummy/config/environment.rb +5 -0
  119. data/test/dummy/config/environments/development.rb +37 -0
  120. data/test/dummy/config/environments/production.rb +67 -0
  121. data/test/dummy/config/environments/test.rb +37 -0
  122. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  123. data/test/dummy/config/initializers/inflections.rb +15 -0
  124. data/test/dummy/config/initializers/mime_types.rb +5 -0
  125. data/test/dummy/config/initializers/secret_token.rb +7 -0
  126. data/test/dummy/config/initializers/session_store.rb +8 -0
  127. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  128. data/test/dummy/config/locales/en.yml +5 -0
  129. data/test/dummy/config/routes.rb +8 -0
  130. data/test/dummy/db/migrate/20130327173045_create_posts.rb +10 -0
  131. data/test/dummy/db/schema.rb +23 -0
  132. data/test/dummy/public/404.html +26 -0
  133. data/test/dummy/public/422.html +26 -0
  134. data/test/dummy/public/500.html +25 -0
  135. data/test/dummy/public/favicon.ico +0 -0
  136. data/test/dummy/script/rails +6 -0
  137. data/test/dummy/test/fixtures/posts.yml +9 -0
  138. data/test/dummy/test/functional/posts_controller_test.rb +49 -0
  139. data/test/dummy/test/unit/helpers/posts_helper_test.rb +4 -0
  140. data/test/dummy/test/unit/post_test.rb +7 -0
  141. data/test/functional/ueditor_rails/dialogs_controller_test.rb +16 -0
  142. data/test/functional/ueditor_rails/libs_controller_test.rb +21 -0
  143. data/test/integration/navigation_test.rb +10 -0
  144. data/test/test_helper.rb +15 -0
  145. data/test/ueditor_rails_test.rb +7 -0
  146. data/vendor/assets/javascripts/ueditor/dialogs/anchor/anchor.html.erb +57 -0
  147. data/vendor/assets/javascripts/ueditor/dialogs/background/background.css +24 -0
  148. data/vendor/assets/javascripts/ueditor/dialogs/background/background.html.erb +55 -0
  149. data/vendor/assets/javascripts/ueditor/dialogs/background/background.js +348 -0
  150. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.css.erb +43 -0
  151. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.html.erb +54 -0
  152. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.js +186 -0
  153. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/0.gif +0 -0
  154. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/bface.gif +0 -0
  155. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/cface.gif +0 -0
  156. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/fface.gif +0 -0
  157. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/jxface2.gif +0 -0
  158. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/neweditor-tab-bg.png +0 -0
  159. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/tface.gif +0 -0
  160. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/wface.gif +0 -0
  161. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/yface.gif +0 -0
  162. data/vendor/assets/javascripts/ueditor/dialogs/gmap/gmap.html.erb +89 -0
  163. data/vendor/assets/javascripts/ueditor/dialogs/help/help.css +7 -0
  164. data/vendor/assets/javascripts/ueditor/dialogs/help/help.html.erb +84 -0
  165. data/vendor/assets/javascripts/ueditor/dialogs/help/help.js +54 -0
  166. data/vendor/assets/javascripts/ueditor/dialogs/highlightcode/highlightcode.html.erb +131 -0
  167. data/vendor/assets/javascripts/ueditor/dialogs/insertframe/insertframe.html.erb +98 -0
  168. data/vendor/assets/javascripts/ueditor/dialogs/internal.js +79 -0
  169. data/vendor/assets/javascripts/ueditor/dialogs/link/link.html.erb +141 -0
  170. data/vendor/assets/javascripts/ueditor/dialogs/map/map.html.erb +105 -0
  171. data/vendor/assets/javascripts/ueditor/dialogs/music/music.css +30 -0
  172. data/vendor/assets/javascripts/ueditor/dialogs/music/music.html.erb +32 -0
  173. data/vendor/assets/javascripts/ueditor/dialogs/music/music.js +192 -0
  174. data/vendor/assets/javascripts/ueditor/dialogs/searchreplace/searchreplace.html.erb +74 -0
  175. data/vendor/assets/javascripts/ueditor/dialogs/searchreplace/searchreplace.js +160 -0
  176. data/vendor/assets/javascripts/ueditor/dialogs/snapscreen/snapscreen.html.erb +91 -0
  177. data/vendor/assets/javascripts/ueditor/dialogs/spechars/spechars.html.erb +21 -0
  178. data/vendor/assets/javascripts/ueditor/dialogs/spechars/spechars.js +56 -0
  179. data/vendor/assets/javascripts/ueditor/dialogs/table/dragicon.png +0 -0
  180. data/vendor/assets/javascripts/ueditor/dialogs/table/edittable.css +75 -0
  181. data/vendor/assets/javascripts/ueditor/dialogs/table/edittable.html.erb +57 -0
  182. data/vendor/assets/javascripts/ueditor/dialogs/table/edittable.js +182 -0
  183. data/vendor/assets/javascripts/ueditor/dialogs/table/edittd.html.erb +51 -0
  184. data/vendor/assets/javascripts/ueditor/dialogs/table/edittip.html.erb +33 -0
  185. data/vendor/assets/javascripts/ueditor/dialogs/tangram.js +1238 -0
  186. data/vendor/assets/javascripts/ueditor/dialogs/template/config.js +42 -0
  187. data/vendor/assets/javascripts/ueditor/dialogs/template/images/bg.gif +0 -0
  188. data/vendor/assets/javascripts/ueditor/dialogs/template/images/pre0.png +0 -0
  189. data/vendor/assets/javascripts/ueditor/dialogs/template/images/pre1.png +0 -0
  190. data/vendor/assets/javascripts/ueditor/dialogs/template/images/pre2.png +0 -0
  191. data/vendor/assets/javascripts/ueditor/dialogs/template/images/pre3.png +0 -0
  192. data/vendor/assets/javascripts/ueditor/dialogs/template/images/pre4.png +0 -0
  193. data/vendor/assets/javascripts/ueditor/dialogs/template/template.css +18 -0
  194. data/vendor/assets/javascripts/ueditor/dialogs/template/template.html.erb +26 -0
  195. data/vendor/assets/javascripts/ueditor/dialogs/template/template.js +53 -0
  196. data/vendor/assets/javascripts/ueditor/dialogs/video/images/center_focus.jpg +0 -0
  197. data/vendor/assets/javascripts/ueditor/dialogs/video/images/left_focus.jpg +0 -0
  198. data/vendor/assets/javascripts/ueditor/dialogs/video/images/none_focus.jpg +0 -0
  199. data/vendor/assets/javascripts/ueditor/dialogs/video/images/right_focus.jpg +0 -0
  200. data/vendor/assets/javascripts/ueditor/dialogs/video/video.css +59 -0
  201. data/vendor/assets/javascripts/ueditor/dialogs/video/video.html.erb +78 -0
  202. data/vendor/assets/javascripts/ueditor/dialogs/video/video.js.erb +409 -0
  203. data/vendor/assets/javascripts/ueditor/dialogs/webapp/webapp.html.erb +64 -0
  204. data/vendor/assets/javascripts/ueditor/editor_all.js.erb +19133 -0
  205. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/copy.png +0 -0
  206. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/imglabel.png +0 -0
  207. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/localimage.png +0 -0
  208. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/music.png +0 -0
  209. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/upload.png +0 -0
  210. data/vendor/assets/javascripts/ueditor/lang/zh-cn/zh-cn.js +492 -0
  211. data/vendor/assets/javascripts/ueditor/third-party/SyntaxHighlighter/shCore.js +3655 -0
  212. data/vendor/assets/javascripts/ueditor/third-party/SyntaxHighlighter/shCoreDefault.css +316 -0
  213. data/vendor/assets/javascripts/ueditor/third-party/codemirror/codemirror.css +104 -0
  214. data/vendor/assets/javascripts/ueditor/third-party/codemirror/codemirror.js +3581 -0
  215. data/vendor/assets/javascripts/ueditor/third-party/fClipboard_ueditor.swf +0 -0
  216. data/vendor/assets/javascripts/ueditor/third-party/imageUploader.swf +0 -0
  217. data/vendor/assets/javascripts/ueditor/third-party/snapscreen/UEditorSnapscreen.exe +0 -0
  218. data/vendor/assets/javascripts/ueditor/third-party/swfupload/fileprogress.js +215 -0
  219. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.cookies.js +53 -0
  220. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.js +1132 -0
  221. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.proxy.js +96 -0
  222. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.queue.js +98 -0
  223. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.speed.js +346 -0
  224. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload.swf +0 -0
  225. data/vendor/assets/javascripts/ueditor/third-party/swfupload/swfupload_fp9.swf +0 -0
  226. data/vendor/assets/javascripts/ueditor/uparse.js +348 -0
  227. metadata +363 -0
@@ -0,0 +1,96 @@
1
+ /*
2
+ Proxy Plug-in
3
+
4
+ Features:
5
+ Times an upload to see if it appear suspiciously fast which might indicate a proxy server or anti-virus suite intercepting the upload.
6
+ If the upload seems too fast an uploadError event is fired with PROXY error code after the final uploadProgress event.
7
+
8
+ Adds a SWFUpload setting allowing you to tweak the bytes/s for triggering the error:
9
+ proxy_detect_threshold : 256000
10
+
11
+ Adds an UPLOAD_ERROR entry called PROXY:
12
+ function uploadError(file, errorCode, message) {
13
+ if (errorCode === SWFUpload.UPLOAD_ERROR.PROXY) {
14
+ alert("You might have a proxy!");
15
+ }
16
+ }
17
+ */
18
+
19
+ var SWFUpload;
20
+ if (typeof(SWFUpload) === "function") {
21
+ SWFUpload.proxyDetect = {};
22
+ SWFUpload.UPLOAD_ERROR.PROXY = -30300;
23
+
24
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
25
+ return function (userSettings) {
26
+ if (typeof(oldInitSettings) === "function") {
27
+ oldInitSettings.call(this, userSettings);
28
+ }
29
+
30
+ this.ensureDefault = function (settingName, defaultValue) {
31
+ this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName];
32
+ };
33
+
34
+ // List used to keep the speed stats for the files we are tracking
35
+ this.proxyDetectFileStartTimes = {};
36
+ this.proxyDetectSettings = {};
37
+
38
+ this.ensureDefault("proxy_detect_threshold", 256000); // Default is 250 KB per second
39
+
40
+ this.proxyDetectSettings.user_upload_progress_handler = this.settings.upload_progress_handler;
41
+ this.proxyDetectSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
42
+
43
+ this.settings.upload_progress_handler = SWFUpload.proxyDetect.uploadProgressHandler;
44
+ this.settings.upload_complete_handler = SWFUpload.proxyDetect.uploadCompleteHandler;
45
+
46
+
47
+ delete this.ensureDefault;
48
+ };
49
+ }(SWFUpload.prototype.initSettings));
50
+
51
+ SWFUpload.proxyDetect.uploadProgressHandler = function (file, bytesComplete, bytesTotal) {
52
+ var ex1 = null, time, differenceMS, bps;
53
+ try {
54
+ if (typeof this.proxyDetectSettings.user_upload_progress_handler === "function") {
55
+ this.proxyDetectSettings.user_upload_progress_handler.call(this, file, bytesComplete, bytesTotal);
56
+ }
57
+ } catch (ex1) { }
58
+
59
+
60
+ if (bytesComplete === 0) {
61
+ this.proxyDetectFileStartTimes[file.ID] = new Date();
62
+
63
+ } else if (bytesComplete === bytesTotal) {
64
+ try {
65
+ // Calculate the Bps and decide if we should trigger the error
66
+ time = new Date();
67
+ differenceMS = time.getTime() - this.proxyDetectFileStartTimes[file.ID].getTime();
68
+
69
+ if (differenceMS === 0) {
70
+ differenceMS = 1;
71
+ }
72
+
73
+ bps = bytesTotal / (differenceMS * 1000);
74
+ if (bps > parseInt(this.settings.proxy_detect_threshold, 10)) {
75
+ this.queueEvent("upload_error_handler", [file, SWFUpload.UPLOAD_ERROR.PROXY, bps]);
76
+ }
77
+ } catch (ex) {
78
+ }
79
+ }
80
+
81
+ if (ex1 !== null) {
82
+ throw(ex1);
83
+ }
84
+ };
85
+
86
+ SWFUpload.proxyDetect.uploadCompleteHandler = function (file) {
87
+ try {
88
+ delete this.proxyDetectFileStartTimes[file.ID];
89
+ } catch (ex) {
90
+ }
91
+
92
+ if (typeof this.proxyDetectSettings.user_upload_progress_handler === "function") {
93
+ return this.proxyDetectSettings.user_upload_progress_handler.call(this, file);
94
+ }
95
+ };
96
+ }
@@ -0,0 +1,98 @@
1
+ /*
2
+ Queue Plug-in
3
+
4
+ Features:
5
+ *Adds a cancelQueue() method for cancelling the entire queue.
6
+ *All queued files are uploaded when startUpload() is called.
7
+ *If false is returned from uploadComplete then the queue upload is stopped.
8
+ If false is not returned (strict comparison) then the queue upload is continued.
9
+ *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
10
+ Set the event handler with the queue_complete_handler setting.
11
+
12
+ */
13
+
14
+ var SWFUpload;
15
+ if (typeof(SWFUpload) === "function") {
16
+ SWFUpload.queue = {};
17
+
18
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
19
+ return function (userSettings) {
20
+ if (typeof(oldInitSettings) === "function") {
21
+ oldInitSettings.call(this, userSettings);
22
+ }
23
+
24
+ this.queueSettings = {};
25
+
26
+ this.queueSettings.queue_cancelled_flag = false;
27
+ this.queueSettings.queue_upload_count = 0;
28
+
29
+ this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
30
+ this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
31
+ this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
32
+ this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
33
+
34
+ this.settings.queue_complete_handler = userSettings.queue_complete_handler || null;
35
+ };
36
+ })(SWFUpload.prototype.initSettings);
37
+
38
+ SWFUpload.prototype.startUpload = function (fileID) {
39
+ this.queueSettings.queue_cancelled_flag = false;
40
+ this.callFlash("StartUpload", [fileID]);
41
+ };
42
+
43
+ SWFUpload.prototype.cancelQueue = function () {
44
+ this.queueSettings.queue_cancelled_flag = true;
45
+ this.stopUpload();
46
+
47
+ var stats = this.getStats();
48
+ while (stats.files_queued > 0) {
49
+ this.cancelUpload();
50
+ stats = this.getStats();
51
+ }
52
+ };
53
+
54
+ SWFUpload.queue.uploadStartHandler = function (file) {
55
+ var returnValue;
56
+ if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
57
+ returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
58
+ }
59
+
60
+ // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
61
+ returnValue = (returnValue === false) ? false : true;
62
+
63
+ this.queueSettings.queue_cancelled_flag = !returnValue;
64
+
65
+ return returnValue;
66
+ };
67
+
68
+ SWFUpload.queue.uploadCompleteHandler = function (file) {
69
+ var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
70
+ var continueUpload;
71
+
72
+ if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
73
+ this.queueSettings.queue_upload_count++;
74
+ }
75
+
76
+ if (typeof(user_upload_complete_handler) === "function") {
77
+ continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
78
+ } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
79
+ // If the file was stopped and re-queued don't restart the upload
80
+ continueUpload = false;
81
+ } else {
82
+ continueUpload = true;
83
+ }
84
+
85
+ if (continueUpload) {
86
+ var stats = this.getStats();
87
+ if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
88
+ this.startUpload();
89
+ } else if (this.queueSettings.queue_cancelled_flag === false) {
90
+ this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
91
+ this.queueSettings.queue_upload_count = 0;
92
+ } else {
93
+ this.queueSettings.queue_cancelled_flag = false;
94
+ this.queueSettings.queue_upload_count = 0;
95
+ }
96
+ }
97
+ };
98
+ }
@@ -0,0 +1,346 @@
1
+ /*
2
+ Speed Plug-in
3
+
4
+ Features:
5
+ *Adds several properties to the 'file' object indicated upload speed, time left, upload time, etc.
6
+ - currentSpeed -- String indicating the upload speed, bits per second
7
+ - averageSpeed -- Overall average upload speed, bits per second
8
+ - movingAverageSpeed -- Speed over averaged over the last several measurements, bits per second
9
+ - timeRemaining -- Estimated remaining upload time in seconds
10
+ - timeElapsed -- Number of seconds passed for this upload
11
+ - percentUploaded -- Percentage of the file uploaded (0 to 100)
12
+ - sizeUploaded -- Formatted size uploaded so far, bytes
13
+
14
+ *Adds setting 'moving_average_history_size' for defining the window size used to calculate the moving average speed.
15
+
16
+ *Adds several Formatting functions for formatting that values provided on the file object.
17
+ - SWFUpload.speed.formatBPS(bps) -- outputs string formatted in the best units (Gbps, Mbps, Kbps, bps)
18
+ - SWFUpload.speed.formatTime(seconds) -- outputs string formatted in the best units (x Hr y M z S)
19
+ - SWFUpload.speed.formatSize(bytes) -- outputs string formatted in the best units (w GB x MB y KB z B )
20
+ - SWFUpload.speed.formatPercent(percent) -- outputs string formatted with a percent sign (x.xx %)
21
+ - SWFUpload.speed.formatUnits(baseNumber, divisionArray, unitLabelArray, fractionalBoolean)
22
+ - Formats a number using the division array to determine how to apply the labels in the Label Array
23
+ - factionalBoolean indicates whether the number should be returned as a single fractional number with a unit (speed)
24
+ or as several numbers labeled with units (time)
25
+ */
26
+
27
+ var SWFUpload;
28
+ if (typeof(SWFUpload) === "function") {
29
+ SWFUpload.speed = {};
30
+
31
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
32
+ return function (userSettings) {
33
+ if (typeof(oldInitSettings) === "function") {
34
+ oldInitSettings.call(this, userSettings);
35
+ }
36
+
37
+ this.ensureDefault = function (settingName, defaultValue) {
38
+ this.settings[settingName] = (userSettings[settingName] == undefined) ? defaultValue : userSettings[settingName];
39
+ };
40
+
41
+ // List used to keep the speed stats for the files we are tracking
42
+ this.fileSpeedStats = {};
43
+ this.speedSettings = {};
44
+
45
+ this.ensureDefault("moving_average_history_size", "10");
46
+
47
+ this.speedSettings.user_file_queued_handler = this.settings.file_queued_handler;
48
+ this.speedSettings.user_file_queue_error_handler = this.settings.file_queue_error_handler;
49
+ this.speedSettings.user_upload_start_handler = this.settings.upload_start_handler;
50
+ this.speedSettings.user_upload_error_handler = this.settings.upload_error_handler;
51
+ this.speedSettings.user_upload_progress_handler = this.settings.upload_progress_handler;
52
+ this.speedSettings.user_upload_success_handler = this.settings.upload_success_handler;
53
+ this.speedSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
54
+
55
+ this.settings.file_queued_handler = SWFUpload.speed.fileQueuedHandler;
56
+ this.settings.file_queue_error_handler = SWFUpload.speed.fileQueueErrorHandler;
57
+ this.settings.upload_start_handler = SWFUpload.speed.uploadStartHandler;
58
+ this.settings.upload_error_handler = SWFUpload.speed.uploadErrorHandler;
59
+ this.settings.upload_progress_handler = SWFUpload.speed.uploadProgressHandler;
60
+ this.settings.upload_success_handler = SWFUpload.speed.uploadSuccessHandler;
61
+ this.settings.upload_complete_handler = SWFUpload.speed.uploadCompleteHandler;
62
+
63
+ delete this.ensureDefault;
64
+ };
65
+ })(SWFUpload.prototype.initSettings);
66
+
67
+
68
+ SWFUpload.speed.fileQueuedHandler = function (file) {
69
+ if (typeof this.speedSettings.user_file_queued_handler === "function") {
70
+ file = SWFUpload.speed.extendFile(file);
71
+
72
+ return this.speedSettings.user_file_queued_handler.call(this, file);
73
+ }
74
+ };
75
+
76
+ SWFUpload.speed.fileQueueErrorHandler = function (file, errorCode, message) {
77
+ if (typeof this.speedSettings.user_file_queue_error_handler === "function") {
78
+ file = SWFUpload.speed.extendFile(file);
79
+
80
+ return this.speedSettings.user_file_queue_error_handler.call(this, file, errorCode, message);
81
+ }
82
+ };
83
+
84
+ SWFUpload.speed.uploadStartHandler = function (file) {
85
+ if (typeof this.speedSettings.user_upload_start_handler === "function") {
86
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
87
+ return this.speedSettings.user_upload_start_handler.call(this, file);
88
+ }
89
+ };
90
+
91
+ SWFUpload.speed.uploadErrorHandler = function (file, errorCode, message) {
92
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
93
+ SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
94
+
95
+ if (typeof this.speedSettings.user_upload_error_handler === "function") {
96
+ return this.speedSettings.user_upload_error_handler.call(this, file, errorCode, message);
97
+ }
98
+ };
99
+ SWFUpload.speed.uploadProgressHandler = function (file, bytesComplete, bytesTotal) {
100
+ this.updateTracking(file, bytesComplete);
101
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
102
+
103
+ if (typeof this.speedSettings.user_upload_progress_handler === "function") {
104
+ return this.speedSettings.user_upload_progress_handler.call(this, file, bytesComplete, bytesTotal);
105
+ }
106
+ };
107
+
108
+ SWFUpload.speed.uploadSuccessHandler = function (file, serverData) {
109
+ if (typeof this.speedSettings.user_upload_success_handler === "function") {
110
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
111
+ return this.speedSettings.user_upload_success_handler.call(this, file, serverData);
112
+ }
113
+ };
114
+ SWFUpload.speed.uploadCompleteHandler = function (file) {
115
+ file = SWFUpload.speed.extendFile(file, this.fileSpeedStats);
116
+ SWFUpload.speed.removeTracking(file, this.fileSpeedStats);
117
+
118
+ if (typeof this.speedSettings.user_upload_complete_handler === "function") {
119
+ return this.speedSettings.user_upload_complete_handler.call(this, file);
120
+ }
121
+ };
122
+
123
+ // Private: extends the file object with the speed plugin values
124
+ SWFUpload.speed.extendFile = function (file, trackingList) {
125
+ var tracking;
126
+
127
+ if (!file) {
128
+ return file;
129
+ }
130
+
131
+ if (trackingList) {
132
+ tracking = trackingList[file.id];
133
+ }
134
+
135
+ if (tracking) {
136
+ file.currentSpeed = tracking.currentSpeed;
137
+ file.averageSpeed = tracking.averageSpeed;
138
+ file.movingAverageSpeed = tracking.movingAverageSpeed;
139
+ file.timeRemaining = tracking.timeRemaining;
140
+ file.timeElapsed = tracking.timeElapsed;
141
+ file.percentUploaded = tracking.percentUploaded;
142
+ file.sizeUploaded = tracking.bytesUploaded;
143
+
144
+ } else {
145
+ file.currentSpeed = 0;
146
+ file.averageSpeed = 0;
147
+ file.movingAverageSpeed = 0;
148
+ file.timeRemaining = 0;
149
+ file.timeElapsed = 0;
150
+ file.percentUploaded = 0;
151
+ file.sizeUploaded = 0;
152
+ }
153
+
154
+ return file;
155
+ };
156
+
157
+ // Private: Updates the speed tracking object, or creates it if necessary
158
+ SWFUpload.prototype.updateTracking = function (file, bytesUploaded) {
159
+ var tracking = this.fileSpeedStats[file.id];
160
+ if (!tracking) {
161
+ this.fileSpeedStats[file.id] = tracking = {};
162
+ }
163
+
164
+ // Sanity check inputs
165
+ bytesUploaded = bytesUploaded || tracking.bytesUploaded || 0;
166
+ if (bytesUploaded < 0) {
167
+ bytesUploaded = 0;
168
+ }
169
+ if (bytesUploaded > file.size) {
170
+ bytesUploaded = file.size;
171
+ }
172
+
173
+ var tickTime = (new Date()).getTime();
174
+ if (!tracking.startTime) {
175
+ tracking.startTime = (new Date()).getTime();
176
+ tracking.lastTime = tracking.startTime;
177
+ tracking.currentSpeed = 0;
178
+ tracking.averageSpeed = 0;
179
+ tracking.movingAverageSpeed = 0;
180
+ tracking.movingAverageHistory = [];
181
+ tracking.timeRemaining = 0;
182
+ tracking.timeElapsed = 0;
183
+ tracking.percentUploaded = bytesUploaded / file.size;
184
+ tracking.bytesUploaded = bytesUploaded;
185
+ } else if (tracking.startTime > tickTime) {
186
+ this.debug("When backwards in time");
187
+ } else {
188
+ // Get time and deltas
189
+ var now = (new Date()).getTime();
190
+ var lastTime = tracking.lastTime;
191
+ var deltaTime = now - lastTime;
192
+ var deltaBytes = bytesUploaded - tracking.bytesUploaded;
193
+
194
+ if (deltaBytes === 0 || deltaTime === 0) {
195
+ return tracking;
196
+ }
197
+
198
+ // Update tracking object
199
+ tracking.lastTime = now;
200
+ tracking.bytesUploaded = bytesUploaded;
201
+
202
+ // Calculate speeds
203
+ tracking.currentSpeed = (deltaBytes * 8 ) / (deltaTime / 1000);
204
+ tracking.averageSpeed = (tracking.bytesUploaded * 8) / ((now - tracking.startTime) / 1000);
205
+
206
+ // Calculate moving average
207
+ tracking.movingAverageHistory.push(tracking.currentSpeed);
208
+ if (tracking.movingAverageHistory.length > this.settings.moving_average_history_size) {
209
+ tracking.movingAverageHistory.shift();
210
+ }
211
+
212
+ tracking.movingAverageSpeed = SWFUpload.speed.calculateMovingAverage(tracking.movingAverageHistory);
213
+
214
+ // Update times
215
+ tracking.timeRemaining = (file.size - tracking.bytesUploaded) * 8 / tracking.movingAverageSpeed;
216
+ tracking.timeElapsed = (now - tracking.startTime) / 1000;
217
+
218
+ // Update percent
219
+ tracking.percentUploaded = (tracking.bytesUploaded / file.size * 100);
220
+ }
221
+
222
+ return tracking;
223
+ };
224
+ SWFUpload.speed.removeTracking = function (file, trackingList) {
225
+ try {
226
+ trackingList[file.id] = null;
227
+ delete trackingList[file.id];
228
+ } catch (ex) {
229
+ }
230
+ };
231
+
232
+ SWFUpload.speed.formatUnits = function (baseNumber, unitDivisors, unitLabels, singleFractional) {
233
+ var i, unit, unitDivisor, unitLabel;
234
+
235
+ if (baseNumber === 0) {
236
+ return "0 " + unitLabels[unitLabels.length - 1];
237
+ }
238
+
239
+ if (singleFractional) {
240
+ unit = baseNumber;
241
+ unitLabel = unitLabels.length >= unitDivisors.length ? unitLabels[unitDivisors.length - 1] : "";
242
+ for (i = 0; i < unitDivisors.length; i++) {
243
+ if (baseNumber >= unitDivisors[i]) {
244
+ unit = (baseNumber / unitDivisors[i]).toFixed(2);
245
+ unitLabel = unitLabels.length >= i ? " " + unitLabels[i] : "";
246
+ break;
247
+ }
248
+ }
249
+
250
+ return unit + unitLabel;
251
+ } else {
252
+ var formattedStrings = [];
253
+ var remainder = baseNumber;
254
+
255
+ for (i = 0; i < unitDivisors.length; i++) {
256
+ unitDivisor = unitDivisors[i];
257
+ unitLabel = unitLabels.length > i ? " " + unitLabels[i] : "";
258
+
259
+ unit = remainder / unitDivisor;
260
+ if (i < unitDivisors.length -1) {
261
+ unit = Math.floor(unit);
262
+ } else {
263
+ unit = unit.toFixed(2);
264
+ }
265
+ if (unit > 0) {
266
+ remainder = remainder % unitDivisor;
267
+
268
+ formattedStrings.push(unit + unitLabel);
269
+ }
270
+ }
271
+
272
+ return formattedStrings.join(" ");
273
+ }
274
+ };
275
+
276
+ SWFUpload.speed.formatBPS = function (baseNumber) {
277
+ var bpsUnits = [1073741824, 1048576, 1024, 1], bpsUnitLabels = ["Gbps", "Mbps", "Kbps", "bps"];
278
+ return SWFUpload.speed.formatUnits(baseNumber, bpsUnits, bpsUnitLabels, true);
279
+
280
+ };
281
+ SWFUpload.speed.formatTime = function (baseNumber) {
282
+ var timeUnits = [86400, 3600, 60, 1], timeUnitLabels = ["d", "h", "m", "s"];
283
+ return SWFUpload.speed.formatUnits(baseNumber, timeUnits, timeUnitLabels, false);
284
+
285
+ };
286
+ SWFUpload.speed.formatBytes = function (baseNumber) {
287
+ var sizeUnits = [1073741824, 1048576, 1024, 1], sizeUnitLabels = ["GB", "MB", "KB", "bytes"];
288
+ return SWFUpload.speed.formatUnits(baseNumber, sizeUnits, sizeUnitLabels, true);
289
+
290
+ };
291
+ SWFUpload.speed.formatPercent = function (baseNumber) {
292
+ return baseNumber.toFixed(2) + " %";
293
+ };
294
+
295
+ SWFUpload.speed.calculateMovingAverage = function (history) {
296
+ var vals = [], size, sum = 0.0, mean = 0.0, varianceTemp = 0.0, variance = 0.0, standardDev = 0.0;
297
+ var i;
298
+ var mSum = 0, mCount = 0;
299
+
300
+ size = history.length;
301
+
302
+ // Check for sufficient data
303
+ if (size >= 8) {
304
+ // Clone the array and Calculate sum of the values
305
+ for (i = 0; i < size; i++) {
306
+ vals[i] = history[i];
307
+ sum += vals[i];
308
+ }
309
+
310
+ mean = sum / size;
311
+
312
+ // Calculate variance for the set
313
+ for (i = 0; i < size; i++) {
314
+ varianceTemp += Math.pow((vals[i] - mean), 2);
315
+ }
316
+
317
+ variance = varianceTemp / size;
318
+ standardDev = Math.sqrt(variance);
319
+
320
+ //Standardize the Data
321
+ for (i = 0; i < size; i++) {
322
+ vals[i] = (vals[i] - mean) / standardDev;
323
+ }
324
+
325
+ // Calculate the average excluding outliers
326
+ var deviationRange = 2.0;
327
+ for (i = 0; i < size; i++) {
328
+
329
+ if (vals[i] <= deviationRange && vals[i] >= -deviationRange) {
330
+ mCount++;
331
+ mSum += history[i];
332
+ }
333
+ }
334
+
335
+ } else {
336
+ // Calculate the average (not enough data points to remove outliers)
337
+ mCount = size;
338
+ for (i = 0; i < size; i++) {
339
+ mSum += history[i];
340
+ }
341
+ }
342
+
343
+ return mSum / mCount;
344
+ };
345
+
346
+ }