rails_kindeditor-plus 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +6 -0
  4. data/README.md +523 -0
  5. data/Rakefile +2 -0
  6. data/app/assets/javascripts/kindeditor.js +1 -0
  7. data/app/controllers/kindeditor/assets_controller.rb +126 -0
  8. data/app/uploaders/kindeditor/asset_uploader.rb +91 -0
  9. data/app/uploaders/kindeditor/file_uploader.rb +10 -0
  10. data/app/uploaders/kindeditor/flash_uploader.rb +10 -0
  11. data/app/uploaders/kindeditor/image_uploader.rb +10 -0
  12. data/app/uploaders/kindeditor/media_uploader.rb +10 -0
  13. data/config/routes.rb +6 -0
  14. data/lib/generators/rails_kindeditor/install/USAGE +10 -0
  15. data/lib/generators/rails_kindeditor/install/install_generator.rb +23 -0
  16. data/lib/generators/rails_kindeditor/install/templates/application.js +17 -0
  17. data/lib/generators/rails_kindeditor/install/templates/rails_kindeditor.rb +29 -0
  18. data/lib/generators/rails_kindeditor/migration/USAGE +14 -0
  19. data/lib/generators/rails_kindeditor/migration/migration_generator.rb +36 -0
  20. data/lib/generators/rails_kindeditor/migration/templates/migration/migration.rb +17 -0
  21. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/asset.rb +14 -0
  22. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/file.rb +3 -0
  23. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/flash.rb +3 -0
  24. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/image.rb +3 -0
  25. data/lib/generators/rails_kindeditor/migration/templates/models/active_record/kindeditor/media.rb +3 -0
  26. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/asset.rb +27 -0
  27. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/file.rb +3 -0
  28. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/flash.rb +3 -0
  29. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/image.rb +3 -0
  30. data/lib/generators/rails_kindeditor/migration/templates/models/mongoid/kindeditor/media.rb +3 -0
  31. data/lib/rails_kindeditor.rb +61 -0
  32. data/lib/rails_kindeditor/active_record.rb +14 -0
  33. data/lib/rails_kindeditor/engine.rb +34 -0
  34. data/lib/rails_kindeditor/formtastic.rb +12 -0
  35. data/lib/rails_kindeditor/helper.rb +96 -0
  36. data/lib/rails_kindeditor/simple_form.rb +11 -0
  37. data/lib/rails_kindeditor/version.rb +4 -0
  38. data/lib/tasks/assets.rake +9 -0
  39. data/rails_kindeditor-plus.gemspec +24 -0
  40. data/screenshots/rails_kindeditor.png +0 -0
  41. data/screenshots/simple_mode.png +0 -0
  42. data/vendor/assets/javascripts/kindeditor/kindeditor.js +5963 -0
  43. data/vendor/assets/javascripts/kindeditor/lang/ar.js +233 -0
  44. data/vendor/assets/javascripts/kindeditor/lang/en.js +232 -0
  45. data/vendor/assets/javascripts/kindeditor/lang/ko.js +237 -0
  46. data/vendor/assets/javascripts/kindeditor/lang/zh_CN.js +237 -0
  47. data/vendor/assets/javascripts/kindeditor/lang/zh_TW.js +235 -0
  48. data/vendor/assets/javascripts/kindeditor/plugins/anchor/anchor.js +46 -0
  49. data/vendor/assets/javascripts/kindeditor/plugins/autoheight/autoheight.js +54 -0
  50. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/baidumap.js +93 -0
  51. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/index.html +83 -0
  52. data/vendor/assets/javascripts/kindeditor/plugins/baidumap/map.html +43 -0
  53. data/vendor/assets/javascripts/kindeditor/plugins/clearhtml/clearhtml.js +29 -0
  54. data/vendor/assets/javascripts/kindeditor/plugins/code/code.js +62 -0
  55. data/vendor/assets/javascripts/kindeditor/plugins/code/prettify.css +13 -0
  56. data/vendor/assets/javascripts/kindeditor/plugins/code/prettify.js +28 -0
  57. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/emoticons.js +129 -0
  58. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/0.gif +0 -0
  59. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/1.gif +0 -0
  60. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/10.gif +0 -0
  61. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/100.gif +0 -0
  62. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/101.gif +0 -0
  63. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/102.gif +0 -0
  64. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/103.gif +0 -0
  65. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/104.gif +0 -0
  66. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/105.gif +0 -0
  67. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/106.gif +0 -0
  68. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/107.gif +0 -0
  69. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/108.gif +0 -0
  70. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/109.gif +0 -0
  71. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/11.gif +0 -0
  72. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/110.gif +0 -0
  73. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/111.gif +0 -0
  74. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/112.gif +0 -0
  75. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/113.gif +0 -0
  76. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/114.gif +0 -0
  77. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/115.gif +0 -0
  78. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/116.gif +0 -0
  79. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/117.gif +0 -0
  80. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/118.gif +0 -0
  81. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/119.gif +0 -0
  82. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/12.gif +0 -0
  83. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/120.gif +0 -0
  84. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/121.gif +0 -0
  85. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/122.gif +0 -0
  86. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/123.gif +0 -0
  87. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/124.gif +0 -0
  88. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/125.gif +0 -0
  89. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/126.gif +0 -0
  90. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/127.gif +0 -0
  91. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/128.gif +0 -0
  92. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/129.gif +0 -0
  93. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/13.gif +0 -0
  94. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/130.gif +0 -0
  95. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/131.gif +0 -0
  96. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/132.gif +0 -0
  97. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/133.gif +0 -0
  98. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/134.gif +0 -0
  99. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/14.gif +0 -0
  100. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/15.gif +0 -0
  101. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/16.gif +0 -0
  102. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/17.gif +0 -0
  103. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/18.gif +0 -0
  104. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/19.gif +0 -0
  105. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/2.gif +0 -0
  106. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/20.gif +0 -0
  107. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/21.gif +0 -0
  108. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/22.gif +0 -0
  109. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/23.gif +0 -0
  110. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/24.gif +0 -0
  111. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/25.gif +0 -0
  112. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/26.gif +0 -0
  113. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/27.gif +0 -0
  114. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/28.gif +0 -0
  115. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/29.gif +0 -0
  116. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/3.gif +0 -0
  117. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/30.gif +0 -0
  118. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/31.gif +0 -0
  119. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/32.gif +0 -0
  120. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/33.gif +0 -0
  121. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/34.gif +0 -0
  122. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/35.gif +0 -0
  123. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/36.gif +0 -0
  124. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/37.gif +0 -0
  125. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/38.gif +0 -0
  126. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/39.gif +0 -0
  127. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/4.gif +0 -0
  128. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/40.gif +0 -0
  129. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/41.gif +0 -0
  130. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/42.gif +0 -0
  131. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/43.gif +0 -0
  132. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/44.gif +0 -0
  133. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/45.gif +0 -0
  134. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/46.gif +0 -0
  135. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/47.gif +0 -0
  136. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/48.gif +0 -0
  137. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/49.gif +0 -0
  138. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/5.gif +0 -0
  139. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/50.gif +0 -0
  140. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/51.gif +0 -0
  141. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/52.gif +0 -0
  142. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/53.gif +0 -0
  143. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/54.gif +0 -0
  144. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/55.gif +0 -0
  145. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/56.gif +0 -0
  146. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/57.gif +0 -0
  147. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/58.gif +0 -0
  148. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/59.gif +0 -0
  149. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/6.gif +0 -0
  150. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/60.gif +0 -0
  151. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/61.gif +0 -0
  152. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/62.gif +0 -0
  153. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/63.gif +0 -0
  154. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/64.gif +0 -0
  155. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/65.gif +0 -0
  156. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/66.gif +0 -0
  157. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/67.gif +0 -0
  158. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/68.gif +0 -0
  159. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/69.gif +0 -0
  160. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/7.gif +0 -0
  161. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/70.gif +0 -0
  162. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/71.gif +0 -0
  163. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/72.gif +0 -0
  164. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/73.gif +0 -0
  165. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/74.gif +0 -0
  166. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/75.gif +0 -0
  167. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/76.gif +0 -0
  168. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/77.gif +0 -0
  169. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/78.gif +0 -0
  170. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/79.gif +0 -0
  171. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/8.gif +0 -0
  172. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/80.gif +0 -0
  173. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/81.gif +0 -0
  174. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/82.gif +0 -0
  175. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/83.gif +0 -0
  176. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/84.gif +0 -0
  177. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/85.gif +0 -0
  178. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/86.gif +0 -0
  179. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/87.gif +0 -0
  180. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/88.gif +0 -0
  181. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/89.gif +0 -0
  182. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/9.gif +0 -0
  183. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/90.gif +0 -0
  184. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/91.gif +0 -0
  185. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/92.gif +0 -0
  186. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/93.gif +0 -0
  187. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/94.gif +0 -0
  188. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/95.gif +0 -0
  189. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/96.gif +0 -0
  190. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/97.gif +0 -0
  191. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/98.gif +0 -0
  192. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/99.gif +0 -0
  193. data/vendor/assets/javascripts/kindeditor/plugins/emoticons/images/static.gif +0 -0
  194. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/filemanager.js +189 -0
  195. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/file-16.gif +0 -0
  196. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/file-64.gif +0 -0
  197. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/folder-16.gif +0 -0
  198. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/folder-64.gif +0 -0
  199. data/vendor/assets/javascripts/kindeditor/plugins/filemanager/images/go-up.gif +0 -0
  200. data/vendor/assets/javascripts/kindeditor/plugins/flash/flash.js +161 -0
  201. data/vendor/assets/javascripts/kindeditor/plugins/image/image.js +328 -0
  202. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_left.gif +0 -0
  203. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_right.gif +0 -0
  204. data/vendor/assets/javascripts/kindeditor/plugins/image/images/align_top.gif +0 -0
  205. data/vendor/assets/javascripts/kindeditor/plugins/image/images/refresh.png +0 -0
  206. data/vendor/assets/javascripts/kindeditor/plugins/insertfile/insertfile.js +144 -0
  207. data/vendor/assets/javascripts/kindeditor/plugins/lineheight/lineheight.js +38 -0
  208. data/vendor/assets/javascripts/kindeditor/plugins/link/link.js +66 -0
  209. data/vendor/assets/javascripts/kindeditor/plugins/map/map.html +57 -0
  210. data/vendor/assets/javascripts/kindeditor/plugins/map/map.js +137 -0
  211. data/vendor/assets/javascripts/kindeditor/plugins/media/media.js +170 -0
  212. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/image.png +0 -0
  213. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/select-files-en.png +0 -0
  214. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/select-files-zh_CN.png +0 -0
  215. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/images/swfupload.swf +0 -0
  216. data/vendor/assets/javascripts/kindeditor/plugins/multiimage/multiimage.js +1384 -0
  217. data/vendor/assets/javascripts/kindeditor/plugins/pagebreak/pagebreak.js +27 -0
  218. data/vendor/assets/javascripts/kindeditor/plugins/plainpaste/plainpaste.js +41 -0
  219. data/vendor/assets/javascripts/kindeditor/plugins/preview/preview.js +33 -0
  220. data/vendor/assets/javascripts/kindeditor/plugins/quickformat/quickformat.js +81 -0
  221. data/vendor/assets/javascripts/kindeditor/plugins/table/table.js +712 -0
  222. data/vendor/assets/javascripts/kindeditor/plugins/template/html/1.html +14 -0
  223. data/vendor/assets/javascripts/kindeditor/plugins/template/html/2.html +42 -0
  224. data/vendor/assets/javascripts/kindeditor/plugins/template/html/3.html +36 -0
  225. data/vendor/assets/javascripts/kindeditor/plugins/template/template.js +58 -0
  226. data/vendor/assets/javascripts/kindeditor/plugins/wordpaste/wordpaste.js +51 -0
  227. data/vendor/assets/javascripts/kindeditor/themes/common/anchor.gif +0 -0
  228. data/vendor/assets/javascripts/kindeditor/themes/common/blank.gif +0 -0
  229. data/vendor/assets/javascripts/kindeditor/themes/common/flash.gif +0 -0
  230. data/vendor/assets/javascripts/kindeditor/themes/common/loading.gif +0 -0
  231. data/vendor/assets/javascripts/kindeditor/themes/common/media.gif +0 -0
  232. data/vendor/assets/javascripts/kindeditor/themes/common/rm.gif +0 -0
  233. data/vendor/assets/javascripts/kindeditor/themes/default/background.png +0 -0
  234. data/vendor/assets/javascripts/kindeditor/themes/default/default.css +1149 -0
  235. data/vendor/assets/javascripts/kindeditor/themes/default/default.png +0 -0
  236. data/vendor/assets/javascripts/kindeditor/themes/qq/editor.gif +0 -0
  237. data/vendor/assets/javascripts/kindeditor/themes/qq/qq.css +143 -0
  238. data/vendor/assets/javascripts/kindeditor/themes/simple/simple.css +100 -0
  239. metadata +309 -0
@@ -0,0 +1,1384 @@
1
+ /*******************************************************************************
2
+ * KindEditor - WYSIWYG HTML Editor for Internet
3
+ * Copyright (C) 2006-2011 kindsoft.net
4
+ *
5
+ * @author Roddy <luolonghao@gmail.com>
6
+ * @site http://www.kindsoft.net/
7
+ * @licence http://www.kindsoft.net/license.php
8
+ *******************************************************************************/
9
+
10
+
11
+ (function(K) {
12
+
13
+ function KSWFUpload(options) {
14
+ this.init(options);
15
+ }
16
+ K.extend(KSWFUpload, {
17
+ init : function(options) {
18
+ var self = this;
19
+ options.afterError = options.afterError || function(str) {
20
+ alert(str);
21
+ };
22
+ self.options = options;
23
+ self.progressbars = {};
24
+ // template
25
+ self.div = K(options.container).html([
26
+ '<div class="ke-swfupload">',
27
+ '<div class="ke-swfupload-top">',
28
+ '<div class="ke-inline-block ke-swfupload-button">',
29
+ '<input type="button" value="Browse" />',
30
+ '</div>',
31
+ '<div class="ke-inline-block ke-swfupload-desc">' + options.uploadDesc + '</div>',
32
+ '<span class="ke-button-common ke-button-outer ke-swfupload-startupload">',
33
+ '<input type="button" class="ke-button-common ke-button" value="' + options.startButtonValue + '" />',
34
+ '</span>',
35
+ '</div>',
36
+ '<div class="ke-swfupload-body"></div>',
37
+ '</div>'
38
+ ].join(''));
39
+ self.bodyDiv = K('.ke-swfupload-body', self.div);
40
+
41
+ function showError(itemDiv, msg) {
42
+ K('.ke-status > div', itemDiv).hide();
43
+ K('.ke-message', itemDiv).addClass('ke-error').show().html(K.escape(msg));
44
+ }
45
+
46
+ var settings = {
47
+ debug : false,
48
+ upload_url : options.uploadUrl,
49
+ flash_url : options.flashUrl,
50
+ file_post_name : options.filePostName,
51
+ button_placeholder : K('.ke-swfupload-button > input', self.div)[0],
52
+ button_image_url: options.buttonImageUrl,
53
+ button_width: options.buttonWidth,
54
+ button_height: options.buttonHeight,
55
+ button_cursor : SWFUpload.CURSOR.HAND,
56
+ file_types : options.fileTypes,
57
+ file_types_description : options.fileTypesDesc,
58
+ file_upload_limit : options.fileUploadLimit,
59
+ file_size_limit : options.fileSizeLimit,
60
+ post_params : options.postParams,
61
+ file_queued_handler : function(file) {
62
+ file.url = self.options.fileIconUrl;
63
+ self.appendFile(file);
64
+ },
65
+ file_queue_error_handler : function(file, errorCode, message) {
66
+ var errorName = '';
67
+ switch (errorCode) {
68
+ case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
69
+ errorName = options.queueLimitExceeded;
70
+ break;
71
+ case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
72
+ errorName = options.fileExceedsSizeLimit;
73
+ break;
74
+ case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
75
+ errorName = options.zeroByteFile;
76
+ break;
77
+ case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
78
+ errorName = options.invalidFiletype;
79
+ break;
80
+ default:
81
+ errorName = options.unknownError;
82
+ break;
83
+ }
84
+ K.DEBUG && alert(errorName);
85
+ },
86
+ upload_start_handler : function(file) {
87
+ var self = this;
88
+ var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv);
89
+ K('.ke-status > div', itemDiv).hide();
90
+ K('.ke-progressbar', itemDiv).show();
91
+ },
92
+ upload_progress_handler : function(file, bytesLoaded, bytesTotal) {
93
+ var percent = Math.round(bytesLoaded * 100 / bytesTotal);
94
+ var progressbar = self.progressbars[file.id];
95
+ progressbar.bar.css('width', Math.round(percent * 80 / 100) + 'px');
96
+ progressbar.percent.html(percent + '%');
97
+ },
98
+ upload_error_handler : function(file, errorCode, message) {
99
+ if (file && file.filestatus == SWFUpload.FILE_STATUS.ERROR) {
100
+ var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
101
+ showError(itemDiv, self.options.errorMessage);
102
+ }
103
+ },
104
+ upload_success_handler : function(file, serverData) {
105
+ var itemDiv = K('div[data-id="' + file.id + '"]', self.bodyDiv).eq(0);
106
+ var data = {};
107
+ try {
108
+ data = K.json(serverData);
109
+ } catch (e) {
110
+ self.options.afterError.call(this, '<!doctype html><html>' + serverData + '</html>');
111
+ }
112
+ if (data.error !== 0) {
113
+ showError(itemDiv, K.DEBUG ? data.message : self.options.errorMessage);
114
+ return;
115
+ }
116
+ file.url = data.url;
117
+ K('.ke-img', itemDiv).attr('src', file.url).attr('data-status', file.filestatus).data('data', data);
118
+ K('.ke-status > div', itemDiv).hide();
119
+ }
120
+ };
121
+ self.swfu = new SWFUpload(settings);
122
+
123
+ K('.ke-swfupload-startupload input', self.div).click(function() {
124
+ self.swfu.startUpload();
125
+ });
126
+ },
127
+ getUrlList : function() {
128
+ var list = [];
129
+ K('.ke-img', self.bodyDiv).each(function() {
130
+ var img = K(this);
131
+ var status = img.attr('data-status');
132
+ if (status == SWFUpload.FILE_STATUS.COMPLETE) {
133
+ list.push(img.data('data'));
134
+ }
135
+ });
136
+ return list;
137
+ },
138
+ removeFile : function(fileId) {
139
+ var self = this;
140
+ self.swfu.cancelUpload(fileId);
141
+ var itemDiv = K('div[data-id="' + fileId + '"]', self.bodyDiv);
142
+ K('.ke-photo', itemDiv).unbind();
143
+ K('.ke-delete', itemDiv).unbind();
144
+ itemDiv.remove();
145
+ },
146
+ removeFiles : function() {
147
+ var self = this;
148
+ K('.ke-item', self.bodyDiv).each(function() {
149
+ self.removeFile(K(this).attr('data-id'));
150
+ });
151
+ },
152
+ appendFile : function(file) {
153
+ var self = this;
154
+ var itemDiv = K('<div class="ke-inline-block ke-item" data-id="' + file.id + '"></div>');
155
+ self.bodyDiv.append(itemDiv);
156
+ var photoDiv = K('<div class="ke-inline-block ke-photo"></div>')
157
+ .mouseover(function(e) {
158
+ K(this).addClass('ke-on');
159
+ })
160
+ .mouseout(function(e) {
161
+ K(this).removeClass('ke-on');
162
+ });
163
+ itemDiv.append(photoDiv);
164
+
165
+ var img = K('<img src="' + file.url + '" class="ke-img" data-status="' + file.filestatus + '" width="80" height="80" alt="' + file.name + '" />');
166
+ photoDiv.append(img);
167
+ K('<span class="ke-delete"></span>').appendTo(photoDiv).click(function() {
168
+ self.removeFile(file.id);
169
+ });
170
+ var statusDiv = K('<div class="ke-status"></div>').appendTo(photoDiv);
171
+ // progressbar
172
+ K(['<div class="ke-progressbar">',
173
+ '<div class="ke-progressbar-bar"><div class="ke-progressbar-bar-inner"></div></div>',
174
+ '<div class="ke-progressbar-percent">0%</div></div>'].join('')).hide().appendTo(statusDiv);
175
+ // message
176
+ K('<div class="ke-message">' + self.options.pendingMessage + '</div>').appendTo(statusDiv);
177
+
178
+ itemDiv.append('<div class="ke-name">' + file.name + '</div>');
179
+
180
+ self.progressbars[file.id] = {
181
+ bar : K('.ke-progressbar-bar-inner', photoDiv),
182
+ percent : K('.ke-progressbar-percent', photoDiv)
183
+ };
184
+ },
185
+ remove : function() {
186
+ this.removeFiles();
187
+ this.swfu.destroy();
188
+ this.div.html('');
189
+ }
190
+ });
191
+
192
+ K.swfupload = function(element, options) {
193
+ return new KSWFUpload(element, options);
194
+ };
195
+
196
+ })(KindEditor);
197
+
198
+ KindEditor.plugin('multiimage', function(K) {
199
+ var self = this, name = 'multiimage',
200
+ formatUploadUrl = K.undef(self.formatUploadUrl, true),
201
+ uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
202
+ imgPath = self.pluginsPath + 'multiimage/images/',
203
+ imageSizeLimit = K.undef(self.imageSizeLimit, '1MB'),
204
+ imageFileTypes = K.undef(self.imageFileTypes, '*.jpg;*.gif;*.png'),
205
+ imageUploadLimit = K.undef(self.imageUploadLimit, 20),
206
+ filePostName = K.undef(self.filePostName, 'imgFile'),
207
+ lang = self.lang(name + '.');
208
+
209
+ self.plugin.multiImageDialog = function(options) {
210
+ var clickFn = options.clickFn,
211
+ uploadDesc = K.tmpl(lang.uploadDesc, {uploadLimit : imageUploadLimit, sizeLimit : imageSizeLimit});
212
+ var html = [
213
+ '<div style="padding:20px;">',
214
+ '<div class="swfupload">',
215
+ '</div>',
216
+ '</div>'
217
+ ].join('');
218
+ var dialog = self.createDialog({
219
+ name : name,
220
+ width : 650,
221
+ height : 510,
222
+ title : self.lang(name),
223
+ body : html,
224
+ previewBtn : {
225
+ name : lang.insertAll,
226
+ click : function(e) {
227
+ clickFn.call(self, swfupload.getUrlList());
228
+ }
229
+ },
230
+ yesBtn : {
231
+ name : lang.clearAll,
232
+ click : function(e) {
233
+ swfupload.removeFiles();
234
+ }
235
+ },
236
+ beforeRemove : function() {
237
+ // IE9 bugfix: https://github.com/kindsoft/kindeditor/issues/72
238
+ if (!K.IE || K.V <= 8) {
239
+ swfupload.remove();
240
+ }
241
+ }
242
+ }),
243
+ div = dialog.div;
244
+
245
+ var swfupload = K.swfupload({
246
+ container : K('.swfupload', div),
247
+ buttonImageUrl : imgPath + (self.langType == 'zh_CN' ? 'select-files-zh_CN.png' : 'select-files-en.png'),
248
+ buttonWidth : self.langType == 'zh_CN' ? 72 : 88,
249
+ buttonHeight : 23,
250
+ fileIconUrl : imgPath + 'image.png',
251
+ uploadDesc : uploadDesc,
252
+ startButtonValue : lang.startUpload,
253
+ uploadUrl : K.addParam(uploadJson, 'dir=image'),
254
+ flashUrl : imgPath + 'swfupload.swf',
255
+ filePostName : filePostName,
256
+ fileTypes : '*.jpg;*.jpeg;*.gif;*.png;*.bmp',
257
+ fileTypesDesc : 'Image Files',
258
+ fileUploadLimit : imageUploadLimit,
259
+ fileSizeLimit : imageSizeLimit,
260
+ postParams : K.undef(self.extraFileUploadParams, {}),
261
+ queueLimitExceeded : lang.queueLimitExceeded,
262
+ fileExceedsSizeLimit : lang.fileExceedsSizeLimit,
263
+ zeroByteFile : lang.zeroByteFile,
264
+ invalidFiletype : lang.invalidFiletype,
265
+ unknownError : lang.unknownError,
266
+ pendingMessage : lang.pending,
267
+ errorMessage : lang.uploadError,
268
+ afterError : function(html) {
269
+ self.errorDialog(html);
270
+ }
271
+ });
272
+
273
+ return dialog;
274
+ };
275
+ self.clickToolbar(name, function() {
276
+ self.plugin.multiImageDialog({
277
+ clickFn : function (urlList) {
278
+ if (urlList.length === 0) {
279
+ return;
280
+ }
281
+ K.each(urlList, function(i, data) {
282
+ if (self.afterUpload) {
283
+ self.afterUpload.call(self, data.url, data, 'multiimage');
284
+ }
285
+ self.exec('insertimage', data.url, data.title, data.width, data.height, data.border, data.align);
286
+ });
287
+ // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
288
+ setTimeout(function() {
289
+ self.hideDialog().focus();
290
+ }, 0);
291
+ }
292
+ });
293
+ });
294
+ });
295
+
296
+
297
+ /**
298
+ * SWFUpload: http://www.swfupload.org, http://swfupload.googlecode.com
299
+ *
300
+ * mmSWFUpload 1.0: Flash upload dialog - http://profandesign.se/swfupload/, http://www.vinterwebb.se/
301
+ *
302
+ * SWFUpload is (c) 2006-2007 Lars Huring, Olov Nilz閚 and Mammon Media and is released under the MIT License:
303
+ * http://www.opensource.org/licenses/mit-license.php
304
+ *
305
+ * SWFUpload 2 is (c) 2007-2008 Jake Roberts and is released under the MIT License:
306
+ * http://www.opensource.org/licenses/mit-license.php
307
+ *
308
+ */
309
+
310
+
311
+ /* ******************* */
312
+ /* Constructor & Init */
313
+ /* ******************* */
314
+
315
+ (function() {
316
+
317
+ window.SWFUpload = function (settings) {
318
+ this.initSWFUpload(settings);
319
+ };
320
+
321
+ SWFUpload.prototype.initSWFUpload = function (settings) {
322
+ try {
323
+ this.customSettings = {}; // A container where developers can place their own settings associated with this instance.
324
+ this.settings = settings;
325
+ this.eventQueue = [];
326
+ this.movieName = "KindEditor_SWFUpload_" + SWFUpload.movieCount++;
327
+ this.movieElement = null;
328
+
329
+
330
+ // Setup global control tracking
331
+ SWFUpload.instances[this.movieName] = this;
332
+
333
+ // Load the settings. Load the Flash movie.
334
+ this.initSettings();
335
+ this.loadFlash();
336
+ this.displayDebugInfo();
337
+ } catch (ex) {
338
+ delete SWFUpload.instances[this.movieName];
339
+ throw ex;
340
+ }
341
+ };
342
+
343
+ /* *************** */
344
+ /* Static Members */
345
+ /* *************** */
346
+ SWFUpload.instances = {};
347
+ SWFUpload.movieCount = 0;
348
+ SWFUpload.version = "2.2.0 2009-03-25";
349
+ SWFUpload.QUEUE_ERROR = {
350
+ QUEUE_LIMIT_EXCEEDED : -100,
351
+ FILE_EXCEEDS_SIZE_LIMIT : -110,
352
+ ZERO_BYTE_FILE : -120,
353
+ INVALID_FILETYPE : -130
354
+ };
355
+ SWFUpload.UPLOAD_ERROR = {
356
+ HTTP_ERROR : -200,
357
+ MISSING_UPLOAD_URL : -210,
358
+ IO_ERROR : -220,
359
+ SECURITY_ERROR : -230,
360
+ UPLOAD_LIMIT_EXCEEDED : -240,
361
+ UPLOAD_FAILED : -250,
362
+ SPECIFIED_FILE_ID_NOT_FOUND : -260,
363
+ FILE_VALIDATION_FAILED : -270,
364
+ FILE_CANCELLED : -280,
365
+ UPLOAD_STOPPED : -290
366
+ };
367
+ SWFUpload.FILE_STATUS = {
368
+ QUEUED : -1,
369
+ IN_PROGRESS : -2,
370
+ ERROR : -3,
371
+ COMPLETE : -4,
372
+ CANCELLED : -5
373
+ };
374
+ SWFUpload.BUTTON_ACTION = {
375
+ SELECT_FILE : -100,
376
+ SELECT_FILES : -110,
377
+ START_UPLOAD : -120
378
+ };
379
+ SWFUpload.CURSOR = {
380
+ ARROW : -1,
381
+ HAND : -2
382
+ };
383
+ SWFUpload.WINDOW_MODE = {
384
+ WINDOW : "window",
385
+ TRANSPARENT : "transparent",
386
+ OPAQUE : "opaque"
387
+ };
388
+
389
+ // Private: takes a URL, determines if it is relative and converts to an absolute URL
390
+ // using the current site. Only processes the URL if it can, otherwise returns the URL untouched
391
+ SWFUpload.completeURL = function(url) {
392
+ if (typeof(url) !== "string" || url.match(/^https?:\/\//i) || url.match(/^\//)) {
393
+ return url;
394
+ }
395
+
396
+ var currentURL = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : "");
397
+
398
+ var indexSlash = window.location.pathname.lastIndexOf("/");
399
+ if (indexSlash <= 0) {
400
+ path = "/";
401
+ } else {
402
+ path = window.location.pathname.substr(0, indexSlash) + "/";
403
+ }
404
+
405
+ return /*currentURL +*/ path + url;
406
+
407
+ };
408
+
409
+
410
+ /* ******************** */
411
+ /* Instance Members */
412
+ /* ******************** */
413
+
414
+ // Private: initSettings ensures that all the
415
+ // settings are set, getting a default value if one was not assigned.
416
+ SWFUpload.prototype.initSettings = function () {
417
+ this.ensureDefault = function (settingName, defaultValue) {
418
+ this.settings[settingName] = (this.settings[settingName] == undefined) ? defaultValue : this.settings[settingName];
419
+ };
420
+
421
+ // Upload backend settings
422
+ this.ensureDefault("upload_url", "");
423
+ this.ensureDefault("preserve_relative_urls", false);
424
+ this.ensureDefault("file_post_name", "Filedata");
425
+ this.ensureDefault("post_params", {});
426
+ this.ensureDefault("use_query_string", false);
427
+ this.ensureDefault("requeue_on_error", false);
428
+ this.ensureDefault("http_success", []);
429
+ this.ensureDefault("assume_success_timeout", 0);
430
+
431
+ // File Settings
432
+ this.ensureDefault("file_types", "*.*");
433
+ this.ensureDefault("file_types_description", "All Files");
434
+ this.ensureDefault("file_size_limit", 0); // Default zero means "unlimited"
435
+ this.ensureDefault("file_upload_limit", 0);
436
+ this.ensureDefault("file_queue_limit", 0);
437
+
438
+ // Flash Settings
439
+ this.ensureDefault("flash_url", "swfupload.swf");
440
+ this.ensureDefault("prevent_swf_caching", true);
441
+
442
+ // Button Settings
443
+ this.ensureDefault("button_image_url", "");
444
+ this.ensureDefault("button_width", 1);
445
+ this.ensureDefault("button_height", 1);
446
+ this.ensureDefault("button_text", "");
447
+ this.ensureDefault("button_text_style", "color: #000000; font-size: 16pt;");
448
+ this.ensureDefault("button_text_top_padding", 0);
449
+ this.ensureDefault("button_text_left_padding", 0);
450
+ this.ensureDefault("button_action", SWFUpload.BUTTON_ACTION.SELECT_FILES);
451
+ this.ensureDefault("button_disabled", false);
452
+ this.ensureDefault("button_placeholder_id", "");
453
+ this.ensureDefault("button_placeholder", null);
454
+ this.ensureDefault("button_cursor", SWFUpload.CURSOR.ARROW);
455
+ this.ensureDefault("button_window_mode", SWFUpload.WINDOW_MODE.WINDOW);
456
+
457
+ // Debug Settings
458
+ this.ensureDefault("debug", false);
459
+ this.settings.debug_enabled = this.settings.debug; // Here to maintain v2 API
460
+
461
+ // Event Handlers
462
+ this.settings.return_upload_start_handler = this.returnUploadStart;
463
+ this.ensureDefault("swfupload_loaded_handler", null);
464
+ this.ensureDefault("file_dialog_start_handler", null);
465
+ this.ensureDefault("file_queued_handler", null);
466
+ this.ensureDefault("file_queue_error_handler", null);
467
+ this.ensureDefault("file_dialog_complete_handler", null);
468
+
469
+ this.ensureDefault("upload_start_handler", null);
470
+ this.ensureDefault("upload_progress_handler", null);
471
+ this.ensureDefault("upload_error_handler", null);
472
+ this.ensureDefault("upload_success_handler", null);
473
+ this.ensureDefault("upload_complete_handler", null);
474
+
475
+ this.ensureDefault("debug_handler", this.debugMessage);
476
+
477
+ this.ensureDefault("custom_settings", {});
478
+
479
+ // Other settings
480
+ this.customSettings = this.settings.custom_settings;
481
+
482
+ // Update the flash url if needed
483
+ if (!!this.settings.prevent_swf_caching) {
484
+ this.settings.flash_url = this.settings.flash_url + (this.settings.flash_url.indexOf("?") < 0 ? "?" : "&") + "preventswfcaching=" + new Date().getTime();
485
+ }
486
+
487
+ if (!this.settings.preserve_relative_urls) {
488
+ //this.settings.flash_url = SWFUpload.completeURL(this.settings.flash_url); // Don't need to do this one since flash doesn't look at it
489
+ this.settings.upload_url = SWFUpload.completeURL(this.settings.upload_url);
490
+ this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_image_url);
491
+ }
492
+
493
+ delete this.ensureDefault;
494
+ };
495
+
496
+ // Private: loadFlash replaces the button_placeholder element with the flash movie.
497
+ SWFUpload.prototype.loadFlash = function () {
498
+ var targetElement, tempParent;
499
+
500
+ // Make sure an element with the ID we are going to use doesn't already exist
501
+ if (document.getElementById(this.movieName) !== null) {
502
+ throw "ID " + this.movieName + " is already in use. The Flash Object could not be added";
503
+ }
504
+
505
+ // Get the element where we will be placing the flash movie
506
+ targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
507
+
508
+ if (targetElement == undefined) {
509
+ throw "Could not find the placeholder element: " + this.settings.button_placeholder_id;
510
+ }
511
+
512
+ // Append the container and load the flash
513
+ tempParent = document.createElement("div");
514
+ tempParent.innerHTML = this.getFlashHTML(); // Using innerHTML is non-standard but the only sensible way to dynamically add Flash in IE (and maybe other browsers)
515
+ targetElement.parentNode.replaceChild(tempParent.firstChild, targetElement);
516
+
517
+ // Fix IE Flash/Form bug
518
+ if (window[this.movieName] == undefined) {
519
+ window[this.movieName] = this.getMovieElement();
520
+ }
521
+
522
+ };
523
+
524
+ // Private: getFlashHTML generates the object tag needed to embed the flash in to the document
525
+ SWFUpload.prototype.getFlashHTML = function () {
526
+ // Flash Satay object syntax: http://www.alistapart.com/articles/flashsatay
527
+ // Fix bug for IE9
528
+ // http://www.kindsoft.net/view.php?bbsid=7&postid=5825&pagenum=1
529
+ var classid = '';
530
+ if (KindEditor.IE && KindEditor.V > 8) {
531
+ classid = ' classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
532
+ }
533
+ return ['<object id="', this.movieName, '"' + classid + ' type="application/x-shockwave-flash" data="', this.settings.flash_url, '" width="', this.settings.button_width, '" height="', this.settings.button_height, '" class="swfupload">',
534
+ '<param name="wmode" value="', this.settings.button_window_mode, '" />',
535
+ '<param name="movie" value="', this.settings.flash_url, '" />',
536
+ '<param name="quality" value="high" />',
537
+ '<param name="menu" value="false" />',
538
+ '<param name="allowScriptAccess" value="always" />',
539
+ '<param name="flashvars" value="' + this.getFlashVars() + '" />',
540
+ '</object>'].join("");
541
+ };
542
+
543
+ // Private: getFlashVars builds the parameter string that will be passed
544
+ // to flash in the flashvars param.
545
+ SWFUpload.prototype.getFlashVars = function () {
546
+ // Build a string from the post param object
547
+ var paramString = this.buildParamString();
548
+ var httpSuccessString = this.settings.http_success.join(",");
549
+
550
+ // Build the parameter string
551
+ return ["movieName=", encodeURIComponent(this.movieName),
552
+ "&amp;uploadURL=", encodeURIComponent(this.settings.upload_url),
553
+ "&amp;useQueryString=", encodeURIComponent(this.settings.use_query_string),
554
+ "&amp;requeueOnError=", encodeURIComponent(this.settings.requeue_on_error),
555
+ "&amp;httpSuccess=", encodeURIComponent(httpSuccessString),
556
+ "&amp;assumeSuccessTimeout=", encodeURIComponent(this.settings.assume_success_timeout),
557
+ "&amp;params=", encodeURIComponent(paramString),
558
+ "&amp;filePostName=", encodeURIComponent(this.settings.file_post_name),
559
+ "&amp;fileTypes=", encodeURIComponent(this.settings.file_types),
560
+ "&amp;fileTypesDescription=", encodeURIComponent(this.settings.file_types_description),
561
+ "&amp;fileSizeLimit=", encodeURIComponent(this.settings.file_size_limit),
562
+ "&amp;fileUploadLimit=", encodeURIComponent(this.settings.file_upload_limit),
563
+ "&amp;fileQueueLimit=", encodeURIComponent(this.settings.file_queue_limit),
564
+ "&amp;debugEnabled=", encodeURIComponent(this.settings.debug_enabled),
565
+ "&amp;buttonImageURL=", encodeURIComponent(this.settings.button_image_url),
566
+ "&amp;buttonWidth=", encodeURIComponent(this.settings.button_width),
567
+ "&amp;buttonHeight=", encodeURIComponent(this.settings.button_height),
568
+ "&amp;buttonText=", encodeURIComponent(this.settings.button_text),
569
+ "&amp;buttonTextTopPadding=", encodeURIComponent(this.settings.button_text_top_padding),
570
+ "&amp;buttonTextLeftPadding=", encodeURIComponent(this.settings.button_text_left_padding),
571
+ "&amp;buttonTextStyle=", encodeURIComponent(this.settings.button_text_style),
572
+ "&amp;buttonAction=", encodeURIComponent(this.settings.button_action),
573
+ "&amp;buttonDisabled=", encodeURIComponent(this.settings.button_disabled),
574
+ "&amp;buttonCursor=", encodeURIComponent(this.settings.button_cursor)
575
+ ].join("");
576
+ };
577
+
578
+ // Public: getMovieElement retrieves the DOM reference to the Flash element added by SWFUpload
579
+ // The element is cached after the first lookup
580
+ SWFUpload.prototype.getMovieElement = function () {
581
+ if (this.movieElement == undefined) {
582
+ this.movieElement = document.getElementById(this.movieName);
583
+ }
584
+
585
+ if (this.movieElement === null) {
586
+ throw "Could not find Flash element";
587
+ }
588
+
589
+ return this.movieElement;
590
+ };
591
+
592
+ // Private: buildParamString takes the name/value pairs in the post_params setting object
593
+ // and joins them up in to a string formatted "name=value&amp;name=value"
594
+ SWFUpload.prototype.buildParamString = function () {
595
+ var postParams = this.settings.post_params;
596
+ var paramStringPairs = [];
597
+
598
+ if (typeof(postParams) === "object") {
599
+ for (var name in postParams) {
600
+ if (postParams.hasOwnProperty(name)) {
601
+ paramStringPairs.push(encodeURIComponent(name.toString()) + "=" + encodeURIComponent(postParams[name].toString()));
602
+ }
603
+ }
604
+ }
605
+
606
+ return paramStringPairs.join("&amp;");
607
+ };
608
+
609
+ // Public: Used to remove a SWFUpload instance from the page. This method strives to remove
610
+ // all references to the SWF, and other objects so memory is properly freed.
611
+ // Returns true if everything was destroyed. Returns a false if a failure occurs leaving SWFUpload in an inconsistant state.
612
+ // Credits: Major improvements provided by steffen
613
+ SWFUpload.prototype.destroy = function () {
614
+ try {
615
+ // Make sure Flash is done before we try to remove it
616
+ this.cancelUpload(null, false);
617
+
618
+
619
+ // Remove the SWFUpload DOM nodes
620
+ var movieElement = null;
621
+ movieElement = this.getMovieElement();
622
+
623
+ if (movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
624
+ // Loop through all the movie's properties and remove all function references (DOM/JS IE 6/7 memory leak workaround)
625
+ for (var i in movieElement) {
626
+ try {
627
+ if (typeof(movieElement[i]) === "function") {
628
+ movieElement[i] = null;
629
+ }
630
+ } catch (ex1) {}
631
+ }
632
+
633
+ // Remove the Movie Element from the page
634
+ try {
635
+ movieElement.parentNode.removeChild(movieElement);
636
+ } catch (ex) {}
637
+ }
638
+
639
+ // Remove IE form fix reference
640
+ window[this.movieName] = null;
641
+
642
+ // Destroy other references
643
+ SWFUpload.instances[this.movieName] = null;
644
+ delete SWFUpload.instances[this.movieName];
645
+
646
+ this.movieElement = null;
647
+ this.settings = null;
648
+ this.customSettings = null;
649
+ this.eventQueue = null;
650
+ this.movieName = null;
651
+
652
+
653
+ return true;
654
+ } catch (ex2) {
655
+ return false;
656
+ }
657
+ };
658
+
659
+
660
+ // Public: displayDebugInfo prints out settings and configuration
661
+ // information about this SWFUpload instance.
662
+ // This function (and any references to it) can be deleted when placing
663
+ // SWFUpload in production.
664
+ SWFUpload.prototype.displayDebugInfo = function () {
665
+ this.debug(
666
+ [
667
+ "---SWFUpload Instance Info---\n",
668
+ "Version: ", SWFUpload.version, "\n",
669
+ "Movie Name: ", this.movieName, "\n",
670
+ "Settings:\n",
671
+ "\t", "upload_url: ", this.settings.upload_url, "\n",
672
+ "\t", "flash_url: ", this.settings.flash_url, "\n",
673
+ "\t", "use_query_string: ", this.settings.use_query_string.toString(), "\n",
674
+ "\t", "requeue_on_error: ", this.settings.requeue_on_error.toString(), "\n",
675
+ "\t", "http_success: ", this.settings.http_success.join(", "), "\n",
676
+ "\t", "assume_success_timeout: ", this.settings.assume_success_timeout, "\n",
677
+ "\t", "file_post_name: ", this.settings.file_post_name, "\n",
678
+ "\t", "post_params: ", this.settings.post_params.toString(), "\n",
679
+ "\t", "file_types: ", this.settings.file_types, "\n",
680
+ "\t", "file_types_description: ", this.settings.file_types_description, "\n",
681
+ "\t", "file_size_limit: ", this.settings.file_size_limit, "\n",
682
+ "\t", "file_upload_limit: ", this.settings.file_upload_limit, "\n",
683
+ "\t", "file_queue_limit: ", this.settings.file_queue_limit, "\n",
684
+ "\t", "debug: ", this.settings.debug.toString(), "\n",
685
+
686
+ "\t", "prevent_swf_caching: ", this.settings.prevent_swf_caching.toString(), "\n",
687
+
688
+ "\t", "button_placeholder_id: ", this.settings.button_placeholder_id.toString(), "\n",
689
+ "\t", "button_placeholder: ", (this.settings.button_placeholder ? "Set" : "Not Set"), "\n",
690
+ "\t", "button_image_url: ", this.settings.button_image_url.toString(), "\n",
691
+ "\t", "button_width: ", this.settings.button_width.toString(), "\n",
692
+ "\t", "button_height: ", this.settings.button_height.toString(), "\n",
693
+ "\t", "button_text: ", this.settings.button_text.toString(), "\n",
694
+ "\t", "button_text_style: ", this.settings.button_text_style.toString(), "\n",
695
+ "\t", "button_text_top_padding: ", this.settings.button_text_top_padding.toString(), "\n",
696
+ "\t", "button_text_left_padding: ", this.settings.button_text_left_padding.toString(), "\n",
697
+ "\t", "button_action: ", this.settings.button_action.toString(), "\n",
698
+ "\t", "button_disabled: ", this.settings.button_disabled.toString(), "\n",
699
+
700
+ "\t", "custom_settings: ", this.settings.custom_settings.toString(), "\n",
701
+ "Event Handlers:\n",
702
+ "\t", "swfupload_loaded_handler assigned: ", (typeof this.settings.swfupload_loaded_handler === "function").toString(), "\n",
703
+ "\t", "file_dialog_start_handler assigned: ", (typeof this.settings.file_dialog_start_handler === "function").toString(), "\n",
704
+ "\t", "file_queued_handler assigned: ", (typeof this.settings.file_queued_handler === "function").toString(), "\n",
705
+ "\t", "file_queue_error_handler assigned: ", (typeof this.settings.file_queue_error_handler === "function").toString(), "\n",
706
+ "\t", "upload_start_handler assigned: ", (typeof this.settings.upload_start_handler === "function").toString(), "\n",
707
+ "\t", "upload_progress_handler assigned: ", (typeof this.settings.upload_progress_handler === "function").toString(), "\n",
708
+ "\t", "upload_error_handler assigned: ", (typeof this.settings.upload_error_handler === "function").toString(), "\n",
709
+ "\t", "upload_success_handler assigned: ", (typeof this.settings.upload_success_handler === "function").toString(), "\n",
710
+ "\t", "upload_complete_handler assigned: ", (typeof this.settings.upload_complete_handler === "function").toString(), "\n",
711
+ "\t", "debug_handler assigned: ", (typeof this.settings.debug_handler === "function").toString(), "\n"
712
+ ].join("")
713
+ );
714
+ };
715
+
716
+ /* Note: addSetting and getSetting are no longer used by SWFUpload but are included
717
+ the maintain v2 API compatibility
718
+ */
719
+ // Public: (Deprecated) addSetting adds a setting value. If the value given is undefined or null then the default_value is used.
720
+ SWFUpload.prototype.addSetting = function (name, value, default_value) {
721
+ if (value == undefined) {
722
+ return (this.settings[name] = default_value);
723
+ } else {
724
+ return (this.settings[name] = value);
725
+ }
726
+ };
727
+
728
+ // Public: (Deprecated) getSetting gets a setting. Returns an empty string if the setting was not found.
729
+ SWFUpload.prototype.getSetting = function (name) {
730
+ if (this.settings[name] != undefined) {
731
+ return this.settings[name];
732
+ }
733
+
734
+ return "";
735
+ };
736
+
737
+
738
+
739
+ // Private: callFlash handles function calls made to the Flash element.
740
+ // Calls are made with a setTimeout for some functions to work around
741
+ // bugs in the ExternalInterface library.
742
+ SWFUpload.prototype.callFlash = function (functionName, argumentArray) {
743
+ argumentArray = argumentArray || [];
744
+
745
+ var movieElement = this.getMovieElement();
746
+ var returnValue, returnString;
747
+
748
+ // Flash's method if calling ExternalInterface methods (code adapted from MooTools).
749
+ try {
750
+ returnString = movieElement.CallFunction('<invoke name="' + functionName + '" returntype="javascript">' + __flash__argumentsToXML(argumentArray, 0) + '</invoke>');
751
+ returnValue = eval(returnString);
752
+ } catch (ex) {
753
+ throw "Call to " + functionName + " failed";
754
+ }
755
+
756
+ // Unescape file post param values
757
+ if (returnValue != undefined && typeof returnValue.post === "object") {
758
+ returnValue = this.unescapeFilePostParams(returnValue);
759
+ }
760
+
761
+ return returnValue;
762
+ };
763
+
764
+ /* *****************************
765
+ -- Flash control methods --
766
+ Your UI should use these
767
+ to operate SWFUpload
768
+ ***************************** */
769
+
770
+ // WARNING: this function does not work in Flash Player 10
771
+ // Public: selectFile causes a File Selection Dialog window to appear. This
772
+ // dialog only allows 1 file to be selected.
773
+ SWFUpload.prototype.selectFile = function () {
774
+ this.callFlash("SelectFile");
775
+ };
776
+
777
+ // WARNING: this function does not work in Flash Player 10
778
+ // Public: selectFiles causes a File Selection Dialog window to appear/ This
779
+ // dialog allows the user to select any number of files
780
+ // Flash Bug Warning: Flash limits the number of selectable files based on the combined length of the file names.
781
+ // If the selection name length is too long the dialog will fail in an unpredictable manner. There is no work-around
782
+ // for this bug.
783
+ SWFUpload.prototype.selectFiles = function () {
784
+ this.callFlash("SelectFiles");
785
+ };
786
+
787
+
788
+ // Public: startUpload starts uploading the first file in the queue unless
789
+ // the optional parameter 'fileID' specifies the ID
790
+ SWFUpload.prototype.startUpload = function (fileID) {
791
+ this.callFlash("StartUpload", [fileID]);
792
+ };
793
+
794
+ // Public: cancelUpload cancels any queued file. The fileID parameter may be the file ID or index.
795
+ // If you do not specify a fileID the current uploading file or first file in the queue is cancelled.
796
+ // If you do not want the uploadError event to trigger you can specify false for the triggerErrorEvent parameter.
797
+ SWFUpload.prototype.cancelUpload = function (fileID, triggerErrorEvent) {
798
+ if (triggerErrorEvent !== false) {
799
+ triggerErrorEvent = true;
800
+ }
801
+ this.callFlash("CancelUpload", [fileID, triggerErrorEvent]);
802
+ };
803
+
804
+ // Public: stopUpload stops the current upload and requeues the file at the beginning of the queue.
805
+ // If nothing is currently uploading then nothing happens.
806
+ SWFUpload.prototype.stopUpload = function () {
807
+ this.callFlash("StopUpload");
808
+ };
809
+
810
+ /* ************************
811
+ * Settings methods
812
+ * These methods change the SWFUpload settings.
813
+ * SWFUpload settings should not be changed directly on the settings object
814
+ * since many of the settings need to be passed to Flash in order to take
815
+ * effect.
816
+ * *********************** */
817
+
818
+ // Public: getStats gets the file statistics object.
819
+ SWFUpload.prototype.getStats = function () {
820
+ return this.callFlash("GetStats");
821
+ };
822
+
823
+ // Public: setStats changes the SWFUpload statistics. You shouldn't need to
824
+ // change the statistics but you can. Changing the statistics does not
825
+ // affect SWFUpload accept for the successful_uploads count which is used
826
+ // by the upload_limit setting to determine how many files the user may upload.
827
+ SWFUpload.prototype.setStats = function (statsObject) {
828
+ this.callFlash("SetStats", [statsObject]);
829
+ };
830
+
831
+ // Public: getFile retrieves a File object by ID or Index. If the file is
832
+ // not found then 'null' is returned.
833
+ SWFUpload.prototype.getFile = function (fileID) {
834
+ if (typeof(fileID) === "number") {
835
+ return this.callFlash("GetFileByIndex", [fileID]);
836
+ } else {
837
+ return this.callFlash("GetFile", [fileID]);
838
+ }
839
+ };
840
+
841
+ // Public: addFileParam sets a name/value pair that will be posted with the
842
+ // file specified by the Files ID. If the name already exists then the
843
+ // exiting value will be overwritten.
844
+ SWFUpload.prototype.addFileParam = function (fileID, name, value) {
845
+ return this.callFlash("AddFileParam", [fileID, name, value]);
846
+ };
847
+
848
+ // Public: removeFileParam removes a previously set (by addFileParam) name/value
849
+ // pair from the specified file.
850
+ SWFUpload.prototype.removeFileParam = function (fileID, name) {
851
+ this.callFlash("RemoveFileParam", [fileID, name]);
852
+ };
853
+
854
+ // Public: setUploadUrl changes the upload_url setting.
855
+ SWFUpload.prototype.setUploadURL = function (url) {
856
+ this.settings.upload_url = url.toString();
857
+ this.callFlash("SetUploadURL", [url]);
858
+ };
859
+
860
+ // Public: setPostParams changes the post_params setting
861
+ SWFUpload.prototype.setPostParams = function (paramsObject) {
862
+ this.settings.post_params = paramsObject;
863
+ this.callFlash("SetPostParams", [paramsObject]);
864
+ };
865
+
866
+ // Public: addPostParam adds post name/value pair. Each name can have only one value.
867
+ SWFUpload.prototype.addPostParam = function (name, value) {
868
+ this.settings.post_params[name] = value;
869
+ this.callFlash("SetPostParams", [this.settings.post_params]);
870
+ };
871
+
872
+ // Public: removePostParam deletes post name/value pair.
873
+ SWFUpload.prototype.removePostParam = function (name) {
874
+ delete this.settings.post_params[name];
875
+ this.callFlash("SetPostParams", [this.settings.post_params]);
876
+ };
877
+
878
+ // Public: setFileTypes changes the file_types setting and the file_types_description setting
879
+ SWFUpload.prototype.setFileTypes = function (types, description) {
880
+ this.settings.file_types = types;
881
+ this.settings.file_types_description = description;
882
+ this.callFlash("SetFileTypes", [types, description]);
883
+ };
884
+
885
+ // Public: setFileSizeLimit changes the file_size_limit setting
886
+ SWFUpload.prototype.setFileSizeLimit = function (fileSizeLimit) {
887
+ this.settings.file_size_limit = fileSizeLimit;
888
+ this.callFlash("SetFileSizeLimit", [fileSizeLimit]);
889
+ };
890
+
891
+ // Public: setFileUploadLimit changes the file_upload_limit setting
892
+ SWFUpload.prototype.setFileUploadLimit = function (fileUploadLimit) {
893
+ this.settings.file_upload_limit = fileUploadLimit;
894
+ this.callFlash("SetFileUploadLimit", [fileUploadLimit]);
895
+ };
896
+
897
+ // Public: setFileQueueLimit changes the file_queue_limit setting
898
+ SWFUpload.prototype.setFileQueueLimit = function (fileQueueLimit) {
899
+ this.settings.file_queue_limit = fileQueueLimit;
900
+ this.callFlash("SetFileQueueLimit", [fileQueueLimit]);
901
+ };
902
+
903
+ // Public: setFilePostName changes the file_post_name setting
904
+ SWFUpload.prototype.setFilePostName = function (filePostName) {
905
+ this.settings.file_post_name = filePostName;
906
+ this.callFlash("SetFilePostName", [filePostName]);
907
+ };
908
+
909
+ // Public: setUseQueryString changes the use_query_string setting
910
+ SWFUpload.prototype.setUseQueryString = function (useQueryString) {
911
+ this.settings.use_query_string = useQueryString;
912
+ this.callFlash("SetUseQueryString", [useQueryString]);
913
+ };
914
+
915
+ // Public: setRequeueOnError changes the requeue_on_error setting
916
+ SWFUpload.prototype.setRequeueOnError = function (requeueOnError) {
917
+ this.settings.requeue_on_error = requeueOnError;
918
+ this.callFlash("SetRequeueOnError", [requeueOnError]);
919
+ };
920
+
921
+ // Public: setHTTPSuccess changes the http_success setting
922
+ SWFUpload.prototype.setHTTPSuccess = function (http_status_codes) {
923
+ if (typeof http_status_codes === "string") {
924
+ http_status_codes = http_status_codes.replace(" ", "").split(",");
925
+ }
926
+
927
+ this.settings.http_success = http_status_codes;
928
+ this.callFlash("SetHTTPSuccess", [http_status_codes]);
929
+ };
930
+
931
+ // Public: setHTTPSuccess changes the http_success setting
932
+ SWFUpload.prototype.setAssumeSuccessTimeout = function (timeout_seconds) {
933
+ this.settings.assume_success_timeout = timeout_seconds;
934
+ this.callFlash("SetAssumeSuccessTimeout", [timeout_seconds]);
935
+ };
936
+
937
+ // Public: setDebugEnabled changes the debug_enabled setting
938
+ SWFUpload.prototype.setDebugEnabled = function (debugEnabled) {
939
+ this.settings.debug_enabled = debugEnabled;
940
+ this.callFlash("SetDebugEnabled", [debugEnabled]);
941
+ };
942
+
943
+ // Public: setButtonImageURL loads a button image sprite
944
+ SWFUpload.prototype.setButtonImageURL = function (buttonImageURL) {
945
+ if (buttonImageURL == undefined) {
946
+ buttonImageURL = "";
947
+ }
948
+
949
+ this.settings.button_image_url = buttonImageURL;
950
+ this.callFlash("SetButtonImageURL", [buttonImageURL]);
951
+ };
952
+
953
+ // Public: setButtonDimensions resizes the Flash Movie and button
954
+ SWFUpload.prototype.setButtonDimensions = function (width, height) {
955
+ this.settings.button_width = width;
956
+ this.settings.button_height = height;
957
+
958
+ var movie = this.getMovieElement();
959
+ if (movie != undefined) {
960
+ movie.style.width = width + "px";
961
+ movie.style.height = height + "px";
962
+ }
963
+
964
+ this.callFlash("SetButtonDimensions", [width, height]);
965
+ };
966
+ // Public: setButtonText Changes the text overlaid on the button
967
+ SWFUpload.prototype.setButtonText = function (html) {
968
+ this.settings.button_text = html;
969
+ this.callFlash("SetButtonText", [html]);
970
+ };
971
+ // Public: setButtonTextPadding changes the top and left padding of the text overlay
972
+ SWFUpload.prototype.setButtonTextPadding = function (left, top) {
973
+ this.settings.button_text_top_padding = top;
974
+ this.settings.button_text_left_padding = left;
975
+ this.callFlash("SetButtonTextPadding", [left, top]);
976
+ };
977
+
978
+ // Public: setButtonTextStyle changes the CSS used to style the HTML/Text overlaid on the button
979
+ SWFUpload.prototype.setButtonTextStyle = function (css) {
980
+ this.settings.button_text_style = css;
981
+ this.callFlash("SetButtonTextStyle", [css]);
982
+ };
983
+ // Public: setButtonDisabled disables/enables the button
984
+ SWFUpload.prototype.setButtonDisabled = function (isDisabled) {
985
+ this.settings.button_disabled = isDisabled;
986
+ this.callFlash("SetButtonDisabled", [isDisabled]);
987
+ };
988
+ // Public: setButtonAction sets the action that occurs when the button is clicked
989
+ SWFUpload.prototype.setButtonAction = function (buttonAction) {
990
+ this.settings.button_action = buttonAction;
991
+ this.callFlash("SetButtonAction", [buttonAction]);
992
+ };
993
+
994
+ // Public: setButtonCursor changes the mouse cursor displayed when hovering over the button
995
+ SWFUpload.prototype.setButtonCursor = function (cursor) {
996
+ this.settings.button_cursor = cursor;
997
+ this.callFlash("SetButtonCursor", [cursor]);
998
+ };
999
+
1000
+ /* *******************************
1001
+ Flash Event Interfaces
1002
+ These functions are used by Flash to trigger the various
1003
+ events.
1004
+
1005
+ All these functions a Private.
1006
+
1007
+ Because the ExternalInterface library is buggy the event calls
1008
+ are added to a queue and the queue then executed by a setTimeout.
1009
+ This ensures that events are executed in a determinate order and that
1010
+ the ExternalInterface bugs are avoided.
1011
+ ******************************* */
1012
+
1013
+ SWFUpload.prototype.queueEvent = function (handlerName, argumentArray) {
1014
+ // Warning: Don't call this.debug inside here or you'll create an infinite loop
1015
+
1016
+ if (argumentArray == undefined) {
1017
+ argumentArray = [];
1018
+ } else if (!(argumentArray instanceof Array)) {
1019
+ argumentArray = [argumentArray];
1020
+ }
1021
+
1022
+ var self = this;
1023
+ if (typeof this.settings[handlerName] === "function") {
1024
+ // Queue the event
1025
+ this.eventQueue.push(function () {
1026
+ this.settings[handlerName].apply(this, argumentArray);
1027
+ });
1028
+
1029
+ // Execute the next queued event
1030
+ setTimeout(function () {
1031
+ self.executeNextEvent();
1032
+ }, 0);
1033
+
1034
+ } else if (this.settings[handlerName] !== null) {
1035
+ throw "Event handler " + handlerName + " is unknown or is not a function";
1036
+ }
1037
+ };
1038
+
1039
+ // Private: Causes the next event in the queue to be executed. Since events are queued using a setTimeout
1040
+ // we must queue them in order to garentee that they are executed in order.
1041
+ SWFUpload.prototype.executeNextEvent = function () {
1042
+ // Warning: Don't call this.debug inside here or you'll create an infinite loop
1043
+
1044
+ var f = this.eventQueue ? this.eventQueue.shift() : null;
1045
+ if (typeof(f) === "function") {
1046
+ f.apply(this);
1047
+ }
1048
+ };
1049
+
1050
+ // Private: unescapeFileParams is part of a workaround for a flash bug where objects passed through ExternalInterface cannot have
1051
+ // properties that contain characters that are not valid for JavaScript identifiers. To work around this
1052
+ // the Flash Component escapes the parameter names and we must unescape again before passing them along.
1053
+ SWFUpload.prototype.unescapeFilePostParams = function (file) {
1054
+ var reg = /[$]([0-9a-f]{4})/i;
1055
+ var unescapedPost = {};
1056
+ var uk;
1057
+
1058
+ if (file != undefined) {
1059
+ for (var k in file.post) {
1060
+ if (file.post.hasOwnProperty(k)) {
1061
+ uk = k;
1062
+ var match;
1063
+ while ((match = reg.exec(uk)) !== null) {
1064
+ uk = uk.replace(match[0], String.fromCharCode(parseInt("0x" + match[1], 16)));
1065
+ }
1066
+ unescapedPost[uk] = file.post[k];
1067
+ }
1068
+ }
1069
+
1070
+ file.post = unescapedPost;
1071
+ }
1072
+
1073
+ return file;
1074
+ };
1075
+
1076
+ // Private: Called by Flash to see if JS can call in to Flash (test if External Interface is working)
1077
+ SWFUpload.prototype.testExternalInterface = function () {
1078
+ try {
1079
+ return this.callFlash("TestExternalInterface");
1080
+ } catch (ex) {
1081
+ return false;
1082
+ }
1083
+ };
1084
+
1085
+ // Private: This event is called by Flash when it has finished loading. Don't modify this.
1086
+ // Use the swfupload_loaded_handler event setting to execute custom code when SWFUpload has loaded.
1087
+ SWFUpload.prototype.flashReady = function () {
1088
+ // Check that the movie element is loaded correctly with its ExternalInterface methods defined
1089
+ var movieElement = this.getMovieElement();
1090
+
1091
+ if (!movieElement) {
1092
+ this.debug("Flash called back ready but the flash movie can't be found.");
1093
+ return;
1094
+ }
1095
+
1096
+ this.cleanUp(movieElement);
1097
+
1098
+ this.queueEvent("swfupload_loaded_handler");
1099
+ };
1100
+
1101
+ // Private: removes Flash added fuctions to the DOM node to prevent memory leaks in IE.
1102
+ // This function is called by Flash each time the ExternalInterface functions are created.
1103
+ SWFUpload.prototype.cleanUp = function (movieElement) {
1104
+ // Pro-actively unhook all the Flash functions
1105
+ try {
1106
+ if (this.movieElement && typeof(movieElement.CallFunction) === "unknown") { // We only want to do this in IE
1107
+ this.debug("Removing Flash functions hooks (this should only run in IE and should prevent memory leaks)");
1108
+ for (var key in movieElement) {
1109
+ try {
1110
+ if (typeof(movieElement[key]) === "function") {
1111
+ movieElement[key] = null;
1112
+ }
1113
+ } catch (ex) {
1114
+ }
1115
+ }
1116
+ }
1117
+ } catch (ex1) {
1118
+
1119
+ }
1120
+
1121
+ // Fix Flashes own cleanup code so if the SWFMovie was removed from the page
1122
+ // it doesn't display errors.
1123
+ window["__flash__removeCallback"] = function (instance, name) {
1124
+ try {
1125
+ if (instance) {
1126
+ instance[name] = null;
1127
+ }
1128
+ } catch (flashEx) {
1129
+
1130
+ }
1131
+ };
1132
+
1133
+ };
1134
+
1135
+
1136
+ /* This is a chance to do something before the browse window opens */
1137
+ SWFUpload.prototype.fileDialogStart = function () {
1138
+ this.queueEvent("file_dialog_start_handler");
1139
+ };
1140
+
1141
+
1142
+ /* Called when a file is successfully added to the queue. */
1143
+ SWFUpload.prototype.fileQueued = function (file) {
1144
+ file = this.unescapeFilePostParams(file);
1145
+ this.queueEvent("file_queued_handler", file);
1146
+ };
1147
+
1148
+
1149
+ /* Handle errors that occur when an attempt to queue a file fails. */
1150
+ SWFUpload.prototype.fileQueueError = function (file, errorCode, message) {
1151
+ file = this.unescapeFilePostParams(file);
1152
+ this.queueEvent("file_queue_error_handler", [file, errorCode, message]);
1153
+ };
1154
+
1155
+ /* Called after the file dialog has closed and the selected files have been queued.
1156
+ You could call startUpload here if you want the queued files to begin uploading immediately. */
1157
+ SWFUpload.prototype.fileDialogComplete = function (numFilesSelected, numFilesQueued, numFilesInQueue) {
1158
+ this.queueEvent("file_dialog_complete_handler", [numFilesSelected, numFilesQueued, numFilesInQueue]);
1159
+ };
1160
+
1161
+ SWFUpload.prototype.uploadStart = function (file) {
1162
+ file = this.unescapeFilePostParams(file);
1163
+ this.queueEvent("return_upload_start_handler", file);
1164
+ };
1165
+
1166
+ SWFUpload.prototype.returnUploadStart = function (file) {
1167
+ var returnValue;
1168
+ if (typeof this.settings.upload_start_handler === "function") {
1169
+ file = this.unescapeFilePostParams(file);
1170
+ returnValue = this.settings.upload_start_handler.call(this, file);
1171
+ } else if (this.settings.upload_start_handler != undefined) {
1172
+ throw "upload_start_handler must be a function";
1173
+ }
1174
+
1175
+ // Convert undefined to true so if nothing is returned from the upload_start_handler it is
1176
+ // interpretted as 'true'.
1177
+ if (returnValue === undefined) {
1178
+ returnValue = true;
1179
+ }
1180
+
1181
+ returnValue = !!returnValue;
1182
+
1183
+ this.callFlash("ReturnUploadStart", [returnValue]);
1184
+ };
1185
+
1186
+
1187
+
1188
+ SWFUpload.prototype.uploadProgress = function (file, bytesComplete, bytesTotal) {
1189
+ file = this.unescapeFilePostParams(file);
1190
+ this.queueEvent("upload_progress_handler", [file, bytesComplete, bytesTotal]);
1191
+ };
1192
+
1193
+ SWFUpload.prototype.uploadError = function (file, errorCode, message) {
1194
+ file = this.unescapeFilePostParams(file);
1195
+ this.queueEvent("upload_error_handler", [file, errorCode, message]);
1196
+ };
1197
+
1198
+ SWFUpload.prototype.uploadSuccess = function (file, serverData, responseReceived) {
1199
+ file = this.unescapeFilePostParams(file);
1200
+ this.queueEvent("upload_success_handler", [file, serverData, responseReceived]);
1201
+ };
1202
+
1203
+ SWFUpload.prototype.uploadComplete = function (file) {
1204
+ file = this.unescapeFilePostParams(file);
1205
+ this.queueEvent("upload_complete_handler", file);
1206
+ };
1207
+
1208
+ /* Called by SWFUpload JavaScript and Flash functions when debug is enabled. By default it writes messages to the
1209
+ internal debug console. You can override this event and have messages written where you want. */
1210
+ SWFUpload.prototype.debug = function (message) {
1211
+ this.queueEvent("debug_handler", message);
1212
+ };
1213
+
1214
+
1215
+ /* **********************************
1216
+ Debug Console
1217
+ The debug console is a self contained, in page location
1218
+ for debug message to be sent. The Debug Console adds
1219
+ itself to the body if necessary.
1220
+
1221
+ The console is automatically scrolled as messages appear.
1222
+
1223
+ If you are using your own debug handler or when you deploy to production and
1224
+ have debug disabled you can remove these functions to reduce the file size
1225
+ and complexity.
1226
+ ********************************** */
1227
+
1228
+ // Private: debugMessage is the default debug_handler. If you want to print debug messages
1229
+ // call the debug() function. When overriding the function your own function should
1230
+ // check to see if the debug setting is true before outputting debug information.
1231
+ SWFUpload.prototype.debugMessage = function (message) {
1232
+ if (this.settings.debug) {
1233
+ var exceptionMessage, exceptionValues = [];
1234
+
1235
+ // Check for an exception object and print it nicely
1236
+ if (typeof message === "object" && typeof message.name === "string" && typeof message.message === "string") {
1237
+ for (var key in message) {
1238
+ if (message.hasOwnProperty(key)) {
1239
+ exceptionValues.push(key + ": " + message[key]);
1240
+ }
1241
+ }
1242
+ exceptionMessage = exceptionValues.join("\n") || "";
1243
+ exceptionValues = exceptionMessage.split("\n");
1244
+ exceptionMessage = "EXCEPTION: " + exceptionValues.join("\nEXCEPTION: ");
1245
+ SWFUpload.Console.writeLine(exceptionMessage);
1246
+ } else {
1247
+ SWFUpload.Console.writeLine(message);
1248
+ }
1249
+ }
1250
+ };
1251
+
1252
+ SWFUpload.Console = {};
1253
+ SWFUpload.Console.writeLine = function (message) {
1254
+ var console, documentForm;
1255
+
1256
+ try {
1257
+ console = document.getElementById("SWFUpload_Console");
1258
+
1259
+ if (!console) {
1260
+ documentForm = document.createElement("form");
1261
+ document.getElementsByTagName("body")[0].appendChild(documentForm);
1262
+
1263
+ console = document.createElement("textarea");
1264
+ console.id = "SWFUpload_Console";
1265
+ console.style.fontFamily = "monospace";
1266
+ console.setAttribute("wrap", "off");
1267
+ console.wrap = "off";
1268
+ console.style.overflow = "auto";
1269
+ console.style.width = "700px";
1270
+ console.style.height = "350px";
1271
+ console.style.margin = "5px";
1272
+ documentForm.appendChild(console);
1273
+ }
1274
+
1275
+ console.value += message + "\n";
1276
+
1277
+ console.scrollTop = console.scrollHeight - console.clientHeight;
1278
+ } catch (ex) {
1279
+ alert("Exception: " + ex.name + " Message: " + ex.message);
1280
+ }
1281
+ };
1282
+
1283
+ })();
1284
+
1285
+ (function() {
1286
+ /*
1287
+ Queue Plug-in
1288
+
1289
+ Features:
1290
+ *Adds a cancelQueue() method for cancelling the entire queue.
1291
+ *All queued files are uploaded when startUpload() is called.
1292
+ *If false is returned from uploadComplete then the queue upload is stopped.
1293
+ If false is not returned (strict comparison) then the queue upload is continued.
1294
+ *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
1295
+ Set the event handler with the queue_complete_handler setting.
1296
+
1297
+ */
1298
+
1299
+ if (typeof(SWFUpload) === "function") {
1300
+ SWFUpload.queue = {};
1301
+
1302
+ SWFUpload.prototype.initSettings = (function (oldInitSettings) {
1303
+ return function () {
1304
+ if (typeof(oldInitSettings) === "function") {
1305
+ oldInitSettings.call(this);
1306
+ }
1307
+
1308
+ this.queueSettings = {};
1309
+
1310
+ this.queueSettings.queue_cancelled_flag = false;
1311
+ this.queueSettings.queue_upload_count = 0;
1312
+
1313
+ this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
1314
+ this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
1315
+ this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
1316
+ this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
1317
+
1318
+ this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
1319
+ };
1320
+ })(SWFUpload.prototype.initSettings);
1321
+
1322
+ SWFUpload.prototype.startUpload = function (fileID) {
1323
+ this.queueSettings.queue_cancelled_flag = false;
1324
+ this.callFlash("StartUpload", [fileID]);
1325
+ };
1326
+
1327
+ SWFUpload.prototype.cancelQueue = function () {
1328
+ this.queueSettings.queue_cancelled_flag = true;
1329
+ this.stopUpload();
1330
+
1331
+ var stats = this.getStats();
1332
+ while (stats.files_queued > 0) {
1333
+ this.cancelUpload();
1334
+ stats = this.getStats();
1335
+ }
1336
+ };
1337
+
1338
+ SWFUpload.queue.uploadStartHandler = function (file) {
1339
+ var returnValue;
1340
+ if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
1341
+ returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
1342
+ }
1343
+
1344
+ // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
1345
+ returnValue = (returnValue === false) ? false : true;
1346
+
1347
+ this.queueSettings.queue_cancelled_flag = !returnValue;
1348
+
1349
+ return returnValue;
1350
+ };
1351
+
1352
+ SWFUpload.queue.uploadCompleteHandler = function (file) {
1353
+ var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
1354
+ var continueUpload;
1355
+
1356
+ if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
1357
+ this.queueSettings.queue_upload_count++;
1358
+ }
1359
+
1360
+ if (typeof(user_upload_complete_handler) === "function") {
1361
+ continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
1362
+ } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
1363
+ // If the file was stopped and re-queued don't restart the upload
1364
+ continueUpload = false;
1365
+ } else {
1366
+ continueUpload = true;
1367
+ }
1368
+
1369
+ if (continueUpload) {
1370
+ var stats = this.getStats();
1371
+ if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
1372
+ this.startUpload();
1373
+ } else if (this.queueSettings.queue_cancelled_flag === false) {
1374
+ this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
1375
+ this.queueSettings.queue_upload_count = 0;
1376
+ } else {
1377
+ this.queueSettings.queue_cancelled_flag = false;
1378
+ this.queueSettings.queue_upload_count = 0;
1379
+ }
1380
+ }
1381
+ };
1382
+ }
1383
+
1384
+ })();