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,51 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title></title>
5
+ <style type="text/css">
6
+ .section {
7
+ text-align: center;
8
+ margin-top: 10px;
9
+ }
10
+
11
+ .section input {
12
+ margin-left: 5px;
13
+ width: 70px;
14
+ }
15
+ </style>
16
+ </head>
17
+ <body>
18
+ <div class="section">
19
+ <span><var id="lang_tdBkColor"></var></span>
20
+ <input type="text" id="J_tone"/>
21
+ </div>
22
+ <%= javascript_include_tag 'ueditor/dialogs/internal.js' %>
23
+ <script type="text/javascript">
24
+ var tone = $G("J_tone"),
25
+ colorPiker = new UE.ui.ColorPicker({
26
+ editor: editor
27
+ }),
28
+ colorPop = new UE.ui.Popup({
29
+ editor: editor,
30
+ content: colorPiker
31
+ });
32
+ domUtils.on(tone, "click", function () {
33
+ colorPop.showAnchor(tone);
34
+ });
35
+ domUtils.on(document, 'mousedown', function () {
36
+ colorPop.hide();
37
+ });
38
+ colorPiker.addListener("pickcolor", function () {
39
+ tone.value = arguments[1];
40
+ colorPop.hide();
41
+ });
42
+ colorPiker.addListener("picknocolor", function () {
43
+ tone.value = "";
44
+ colorPop.hide();
45
+ });
46
+ dialog.onok = function () {
47
+ editor.execCommand("edittd", tone.value);
48
+ };
49
+ </script>
50
+ </body>
51
+ </html>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>表格删除提示</title>
5
+ <style type="text/css">
6
+ .section {
7
+ width: 200px;
8
+ margin: 10px auto 0;
9
+ font-size: 14px;
10
+ }
11
+
12
+ .item {
13
+ text-align: center;
14
+ }
15
+ </style>
16
+ </head>
17
+ <body>
18
+ <div class="section">
19
+ <div class="item">
20
+ <label><input type="radio" id="J_delRow" name="cmd" checked/><var id="lang_delRow"></var></label>
21
+ </div>
22
+ <div class="item">
23
+ <label><input type="radio" id="J_delCol" name="cmd"/><var id="lang_delCol"></var></label>
24
+ </div>
25
+ </div>
26
+ <%= javascript_include_tag 'ueditor/dialogs/internal.js' %>
27
+ <script type="text/javascript">
28
+ dialog.onok = function () {
29
+ $G("J_delRow").checked ? editor.execCommand("deleterow") : editor.execCommand("deletecol");
30
+ };
31
+ </script>
32
+ </body>
33
+ </html>
@@ -0,0 +1,1238 @@
1
+ // Copyright (c) 2009, Baidu Inc. All rights reserved.
2
+ //
3
+ // Licensed under the BSD License
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http:// tangram.baidu.com/license.html
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS-IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ /**
15
+ * @namespace T Tangram七巧板
16
+ * @name T
17
+ * @version 1.6.0
18
+ */
19
+
20
+ /**
21
+ * 声明baidu包
22
+ * @author: allstar, erik, meizz, berg
23
+ */
24
+ var T,
25
+ baidu = T = baidu || {version: "1.5.0"};
26
+ baidu.guid = "$BAIDU$";
27
+ baidu.$$ = window[baidu.guid] = window[baidu.guid] || {global:{}};
28
+
29
+ /**
30
+ * 使用flash资源封装的一些功能
31
+ * @namespace baidu.flash
32
+ */
33
+ baidu.flash = baidu.flash || {};
34
+
35
+ /**
36
+ * 操作dom的方法
37
+ * @namespace baidu.dom
38
+ */
39
+ baidu.dom = baidu.dom || {};
40
+
41
+
42
+ /**
43
+ * 从文档中获取指定的DOM元素
44
+ * @name baidu.dom.g
45
+ * @function
46
+ * @grammar baidu.dom.g(id)
47
+ * @param {string|HTMLElement} id 元素的id或DOM元素.
48
+ * @shortcut g,T.G
49
+ * @meta standard
50
+ * @see baidu.dom.q
51
+ *
52
+ * @return {HTMLElement|null} 获取的元素,查找不到时返回null,如果参数不合法,直接返回参数.
53
+ */
54
+ baidu.dom.g = function(id) {
55
+ if (!id) return null;
56
+ if ('string' == typeof id || id instanceof String) {
57
+ return document.getElementById(id);
58
+ } else if (id.nodeName && (id.nodeType == 1 || id.nodeType == 9)) {
59
+ return id;
60
+ }
61
+ return null;
62
+ };
63
+ baidu.g = baidu.G = baidu.dom.g;
64
+
65
+
66
+ /**
67
+ * 操作数组的方法
68
+ * @namespace baidu.array
69
+ */
70
+
71
+ baidu.array = baidu.array || {};
72
+
73
+
74
+ /**
75
+ * 遍历数组中所有元素
76
+ * @name baidu.array.each
77
+ * @function
78
+ * @grammar baidu.array.each(source, iterator[, thisObject])
79
+ * @param {Array} source 需要遍历的数组
80
+ * @param {Function} iterator 对每个数组元素进行调用的函数,该函数有两个参数,第一个为数组元素,第二个为数组索引值,function (item, index)。
81
+ * @param {Object} [thisObject] 函数调用时的this指针,如果没有此参数,默认是当前遍历的数组
82
+ * @remark
83
+ * each方法不支持对Object的遍历,对Object的遍历使用baidu.object.each 。
84
+ * @shortcut each
85
+ * @meta standard
86
+ *
87
+ * @returns {Array} 遍历的数组
88
+ */
89
+
90
+ baidu.each = baidu.array.forEach = baidu.array.each = function (source, iterator, thisObject) {
91
+ var returnValue, item, i, len = source.length;
92
+
93
+ if ('function' == typeof iterator) {
94
+ for (i = 0; i < len; i++) {
95
+ item = source[i];
96
+ returnValue = iterator.call(thisObject || source, item, i);
97
+
98
+ if (returnValue === false) {
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ return source;
104
+ };
105
+
106
+ /**
107
+ * 对语言层面的封装,包括类型判断、模块扩展、继承基类以及对象自定义事件的支持。
108
+ * @namespace baidu.lang
109
+ */
110
+ baidu.lang = baidu.lang || {};
111
+
112
+
113
+ /**
114
+ * 判断目标参数是否为function或Function实例
115
+ * @name baidu.lang.isFunction
116
+ * @function
117
+ * @grammar baidu.lang.isFunction(source)
118
+ * @param {Any} source 目标参数
119
+ * @version 1.2
120
+ * @see baidu.lang.isString,baidu.lang.isObject,baidu.lang.isNumber,baidu.lang.isArray,baidu.lang.isElement,baidu.lang.isBoolean,baidu.lang.isDate
121
+ * @meta standard
122
+ * @returns {boolean} 类型判断结果
123
+ */
124
+ baidu.lang.isFunction = function (source) {
125
+ return '[object Function]' == Object.prototype.toString.call(source);
126
+ };
127
+
128
+ /**
129
+ * 判断目标参数是否string类型或String对象
130
+ * @name baidu.lang.isString
131
+ * @function
132
+ * @grammar baidu.lang.isString(source)
133
+ * @param {Any} source 目标参数
134
+ * @shortcut isString
135
+ * @meta standard
136
+ * @see baidu.lang.isObject,baidu.lang.isNumber,baidu.lang.isArray,baidu.lang.isElement,baidu.lang.isBoolean,baidu.lang.isDate
137
+ *
138
+ * @returns {boolean} 类型判断结果
139
+ */
140
+ baidu.lang.isString = function (source) {
141
+ return '[object String]' == Object.prototype.toString.call(source);
142
+ };
143
+ baidu.isString = baidu.lang.isString;
144
+
145
+
146
+ /**
147
+ * 判断浏览器类型和特性的属性
148
+ * @namespace baidu.browser
149
+ */
150
+ baidu.browser = baidu.browser || {};
151
+
152
+
153
+ /**
154
+ * 判断是否为opera浏览器
155
+ * @property opera opera版本号
156
+ * @grammar baidu.browser.opera
157
+ * @meta standard
158
+ * @see baidu.browser.ie,baidu.browser.firefox,baidu.browser.safari,baidu.browser.chrome
159
+ * @returns {Number} opera版本号
160
+ */
161
+
162
+ /**
163
+ * opera 从10开始不是用opera后面的字符串进行版本的判断
164
+ * 在Browser identification最后添加Version + 数字进行版本标识
165
+ * opera后面的数字保持在9.80不变
166
+ */
167
+ baidu.browser.opera = /opera(\/| )(\d+(\.\d+)?)(.+?(version\/(\d+(\.\d+)?)))?/i.test(navigator.userAgent) ? + ( RegExp["\x246"] || RegExp["\x242"] ) : undefined;
168
+
169
+
170
+ /**
171
+ * 在目标元素的指定位置插入HTML代码
172
+ * @name baidu.dom.insertHTML
173
+ * @function
174
+ * @grammar baidu.dom.insertHTML(element, position, html)
175
+ * @param {HTMLElement|string} element 目标元素或目标元素的id
176
+ * @param {string} position 插入html的位置信息,取值为beforeBegin,afterBegin,beforeEnd,afterEnd
177
+ * @param {string} html 要插入的html
178
+ * @remark
179
+ *
180
+ * 对于position参数,大小写不敏感<br>
181
+ * 参数的意思:beforeBegin&lt;span&gt;afterBegin this is span! beforeEnd&lt;/span&gt; afterEnd <br />
182
+ * 此外,如果使用本函数插入带有script标签的HTML字符串,script标签对应的脚本将不会被执行。
183
+ *
184
+ * @shortcut insertHTML
185
+ * @meta standard
186
+ *
187
+ * @returns {HTMLElement} 目标元素
188
+ */
189
+ baidu.dom.insertHTML = function (element, position, html) {
190
+ element = baidu.dom.g(element);
191
+ var range,begin;
192
+ if (element.insertAdjacentHTML && !baidu.browser.opera) {
193
+ element.insertAdjacentHTML(position, html);
194
+ } else {
195
+ range = element.ownerDocument.createRange();
196
+ position = position.toUpperCase();
197
+ if (position == 'AFTERBEGIN' || position == 'BEFOREEND') {
198
+ range.selectNodeContents(element);
199
+ range.collapse(position == 'AFTERBEGIN');
200
+ } else {
201
+ begin = position == 'BEFOREBEGIN';
202
+ range[begin ? 'setStartBefore' : 'setEndAfter'](element);
203
+ range.collapse(begin);
204
+ }
205
+ range.insertNode(range.createContextualFragment(html));
206
+ }
207
+ return element;
208
+ };
209
+
210
+ baidu.insertHTML = baidu.dom.insertHTML;
211
+
212
+ /**
213
+ * 操作flash对象的方法,包括创建flash对象、获取flash对象以及判断flash插件的版本号
214
+ * @namespace baidu.swf
215
+ */
216
+ baidu.swf = baidu.swf || {};
217
+
218
+
219
+ /**
220
+ * 浏览器支持的flash插件版本
221
+ * @property version 浏览器支持的flash插件版本
222
+ * @grammar baidu.swf.version
223
+ * @return {String} 版本号
224
+ * @meta standard
225
+ */
226
+ baidu.swf.version = (function () {
227
+ var n = navigator;
228
+ if (n.plugins && n.mimeTypes.length) {
229
+ var plugin = n.plugins["Shockwave Flash"];
230
+ if (plugin && plugin.description) {
231
+ return plugin.description
232
+ .replace(/([a-zA-Z]|\s)+/, "")
233
+ .replace(/(\s)+r/, ".") + ".0";
234
+ }
235
+ } else if (window.ActiveXObject && !window.opera) {
236
+ for (var i = 12; i >= 2; i--) {
237
+ try {
238
+ var c = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.' + i);
239
+ if (c) {
240
+ var version = c.GetVariable("$version");
241
+ return version.replace(/WIN/g,'').replace(/,/g,'.');
242
+ }
243
+ } catch(e) {}
244
+ }
245
+ }
246
+ })();
247
+
248
+ /**
249
+ * 操作字符串的方法
250
+ * @namespace baidu.string
251
+ */
252
+ baidu.string = baidu.string || {};
253
+
254
+
255
+ /**
256
+ * 对目标字符串进行html编码
257
+ * @name baidu.string.encodeHTML
258
+ * @function
259
+ * @grammar baidu.string.encodeHTML(source)
260
+ * @param {string} source 目标字符串
261
+ * @remark
262
+ * 编码字符有5个:&<>"'
263
+ * @shortcut encodeHTML
264
+ * @meta standard
265
+ * @see baidu.string.decodeHTML
266
+ *
267
+ * @returns {string} html编码后的字符串
268
+ */
269
+ baidu.string.encodeHTML = function (source) {
270
+ return String(source)
271
+ .replace(/&/g,'&amp;')
272
+ .replace(/</g,'&lt;')
273
+ .replace(/>/g,'&gt;')
274
+ .replace(/"/g, "&quot;")
275
+ .replace(/'/g, "&#39;");
276
+ };
277
+
278
+ baidu.encodeHTML = baidu.string.encodeHTML;
279
+
280
+ /**
281
+ * 创建flash对象的html字符串
282
+ * @name baidu.swf.createHTML
283
+ * @function
284
+ * @grammar baidu.swf.createHTML(options)
285
+ *
286
+ * @param {Object} options 创建flash的选项参数
287
+ * @param {string} options.id 要创建的flash的标识
288
+ * @param {string} options.url flash文件的url
289
+ * @param {String} options.errorMessage 未安装flash player或flash player版本号过低时的提示
290
+ * @param {string} options.ver 最低需要的flash player版本号
291
+ * @param {string} options.width flash的宽度
292
+ * @param {string} options.height flash的高度
293
+ * @param {string} options.align flash的对齐方式,允许值:middle/left/right/top/bottom
294
+ * @param {string} options.base 设置用于解析swf文件中的所有相对路径语句的基本目录或URL
295
+ * @param {string} options.bgcolor swf文件的背景色
296
+ * @param {string} options.salign 设置缩放的swf文件在由width和height设置定义的区域内的位置。允许值:l/r/t/b/tl/tr/bl/br
297
+ * @param {boolean} options.menu 是否显示右键菜单,允许值:true/false
298
+ * @param {boolean} options.loop 播放到最后一帧时是否重新播放,允许值: true/false
299
+ * @param {boolean} options.play flash是否在浏览器加载时就开始播放。允许值:true/false
300
+ * @param {string} options.quality 设置flash播放的画质,允许值:low/medium/high/autolow/autohigh/best
301
+ * @param {string} options.scale 设置flash内容如何缩放来适应设置的宽高。允许值:showall/noborder/exactfit
302
+ * @param {string} options.wmode 设置flash的显示模式。允许值:window/opaque/transparent
303
+ * @param {string} options.allowscriptaccess 设置flash与页面的通信权限。允许值:always/never/sameDomain
304
+ * @param {string} options.allownetworking 设置swf文件中允许使用的网络API。允许值:all/internal/none
305
+ * @param {boolean} options.allowfullscreen 是否允许flash全屏。允许值:true/false
306
+ * @param {boolean} options.seamlesstabbing 允许设置执行无缝跳格,从而使用户能跳出flash应用程序。该参数只能在安装Flash7及更高版本的Windows中使用。允许值:true/false
307
+ * @param {boolean} options.devicefont 设置静态文本对象是否以设备字体呈现。允许值:true/false
308
+ * @param {boolean} options.swliveconnect 第一次加载flash时浏览器是否应启动Java。允许值:true/false
309
+ * @param {Object} options.vars 要传递给flash的参数,支持JSON或string类型。
310
+ *
311
+ * @see baidu.swf.create
312
+ * @meta standard
313
+ * @returns {string} flash对象的html字符串
314
+ */
315
+ baidu.swf.createHTML = function (options) {
316
+ options = options || {};
317
+ var version = baidu.swf.version,
318
+ needVersion = options['ver'] || '6.0.0',
319
+ vUnit1, vUnit2, i, k, len, item, tmpOpt = {},
320
+ encodeHTML = baidu.string.encodeHTML;
321
+ for (k in options) {
322
+ tmpOpt[k] = options[k];
323
+ }
324
+ options = tmpOpt;
325
+ if (version) {
326
+ version = version.split('.');
327
+ needVersion = needVersion.split('.');
328
+ for (i = 0; i < 3; i++) {
329
+ vUnit1 = parseInt(version[i], 10);
330
+ vUnit2 = parseInt(needVersion[i], 10);
331
+ if (vUnit2 < vUnit1) {
332
+ break;
333
+ } else if (vUnit2 > vUnit1) {
334
+ return '';
335
+ }
336
+ }
337
+ } else {
338
+ return '';
339
+ }
340
+
341
+ var vars = options['vars'],
342
+ objProperties = ['classid', 'codebase', 'id', 'width', 'height', 'align'];
343
+ options['align'] = options['align'] || 'middle';
344
+ options['classid'] = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
345
+ options['codebase'] = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0';
346
+ options['movie'] = options['url'] || '';
347
+ delete options['vars'];
348
+ delete options['url'];
349
+ if ('string' == typeof vars) {
350
+ options['flashvars'] = vars;
351
+ } else {
352
+ var fvars = [];
353
+ for (k in vars) {
354
+ item = vars[k];
355
+ fvars.push(k + "=" + encodeURIComponent(item));
356
+ }
357
+ options['flashvars'] = fvars.join('&');
358
+ }
359
+ var str = ['<object '];
360
+ for (i = 0, len = objProperties.length; i < len; i++) {
361
+ item = objProperties[i];
362
+ str.push(' ', item, '="', encodeHTML(options[item]), '"');
363
+ }
364
+ str.push('>');
365
+ var params = {
366
+ 'wmode' : 1,
367
+ 'scale' : 1,
368
+ 'quality' : 1,
369
+ 'play' : 1,
370
+ 'loop' : 1,
371
+ 'menu' : 1,
372
+ 'salign' : 1,
373
+ 'bgcolor' : 1,
374
+ 'base' : 1,
375
+ 'allowscriptaccess' : 1,
376
+ 'allownetworking' : 1,
377
+ 'allowfullscreen' : 1,
378
+ 'seamlesstabbing' : 1,
379
+ 'devicefont' : 1,
380
+ 'swliveconnect' : 1,
381
+ 'flashvars' : 1,
382
+ 'movie' : 1
383
+ };
384
+
385
+ for (k in options) {
386
+ item = options[k];
387
+ k = k.toLowerCase();
388
+ if (params[k] && (item || item === false || item === 0)) {
389
+ str.push('<param name="' + k + '" value="' + encodeHTML(item) + '" />');
390
+ }
391
+ }
392
+ options['src'] = options['movie'];
393
+ options['name'] = options['id'];
394
+ delete options['id'];
395
+ delete options['movie'];
396
+ delete options['classid'];
397
+ delete options['codebase'];
398
+ options['type'] = 'application/x-shockwave-flash';
399
+ options['pluginspage'] = 'http://www.macromedia.com/go/getflashplayer';
400
+ str.push('<embed');
401
+ var salign;
402
+ for (k in options) {
403
+ item = options[k];
404
+ if (item || item === false || item === 0) {
405
+ if ((new RegExp("^salign\x24", "i")).test(k)) {
406
+ salign = item;
407
+ continue;
408
+ }
409
+
410
+ str.push(' ', k, '="', encodeHTML(item), '"');
411
+ }
412
+ }
413
+
414
+ if (salign) {
415
+ str.push(' salign="', encodeHTML(salign), '"');
416
+ }
417
+ str.push('></embed></object>');
418
+
419
+ return str.join('');
420
+ };
421
+
422
+
423
+ /**
424
+ * 在页面中创建一个flash对象
425
+ * @name baidu.swf.create
426
+ * @function
427
+ * @grammar baidu.swf.create(options[, container])
428
+ *
429
+ * @param {Object} options 创建flash的选项参数
430
+ * @param {string} options.id 要创建的flash的标识
431
+ * @param {string} options.url flash文件的url
432
+ * @param {String} options.errorMessage 未安装flash player或flash player版本号过低时的提示
433
+ * @param {string} options.ver 最低需要的flash player版本号
434
+ * @param {string} options.width flash的宽度
435
+ * @param {string} options.height flash的高度
436
+ * @param {string} options.align flash的对齐方式,允许值:middle/left/right/top/bottom
437
+ * @param {string} options.base 设置用于解析swf文件中的所有相对路径语句的基本目录或URL
438
+ * @param {string} options.bgcolor swf文件的背景色
439
+ * @param {string} options.salign 设置缩放的swf文件在由width和height设置定义的区域内的位置。允许值:l/r/t/b/tl/tr/bl/br
440
+ * @param {boolean} options.menu 是否显示右键菜单,允许值:true/false
441
+ * @param {boolean} options.loop 播放到最后一帧时是否重新播放,允许值: true/false
442
+ * @param {boolean} options.play flash是否在浏览器加载时就开始播放。允许值:true/false
443
+ * @param {string} options.quality 设置flash播放的画质,允许值:low/medium/high/autolow/autohigh/best
444
+ * @param {string} options.scale 设置flash内容如何缩放来适应设置的宽高。允许值:showall/noborder/exactfit
445
+ * @param {string} options.wmode 设置flash的显示模式。允许值:window/opaque/transparent
446
+ * @param {string} options.allowscriptaccess 设置flash与页面的通信权限。允许值:always/never/sameDomain
447
+ * @param {string} options.allownetworking 设置swf文件中允许使用的网络API。允许值:all/internal/none
448
+ * @param {boolean} options.allowfullscreen 是否允许flash全屏。允许值:true/false
449
+ * @param {boolean} options.seamlesstabbing 允许设置执行无缝跳格,从而使用户能跳出flash应用程序。该参数只能在安装Flash7及更高版本的Windows中使用。允许值:true/false
450
+ * @param {boolean} options.devicefont 设置静态文本对象是否以设备字体呈现。允许值:true/false
451
+ * @param {boolean} options.swliveconnect 第一次加载flash时浏览器是否应启动Java。允许值:true/false
452
+ * @param {Object} options.vars 要传递给flash的参数,支持JSON或string类型。
453
+ *
454
+ * @param {HTMLElement|string} [container] flash对象的父容器元素,不传递该参数时在当前代码位置创建flash对象。
455
+ * @meta standard
456
+ * @see baidu.swf.createHTML,baidu.swf.getMovie
457
+ */
458
+ baidu.swf.create = function (options, target) {
459
+ options = options || {};
460
+ var html = baidu.swf.createHTML(options)
461
+ || options['errorMessage']
462
+ || '';
463
+
464
+ if (target && 'string' == typeof target) {
465
+ target = document.getElementById(target);
466
+ }
467
+ baidu.dom.insertHTML( target || document.body ,'beforeEnd',html );
468
+ };
469
+ /**
470
+ * 判断是否为ie浏览器
471
+ * @name baidu.browser.ie
472
+ * @field
473
+ * @grammar baidu.browser.ie
474
+ * @returns {Number} IE版本号
475
+ */
476
+ baidu.browser.ie = baidu.ie = /msie (\d+\.\d+)/i.test(navigator.userAgent) ? (document.documentMode || + RegExp['\x241']) : undefined;
477
+
478
+ /**
479
+ * 移除数组中的项
480
+ * @name baidu.array.remove
481
+ * @function
482
+ * @grammar baidu.array.remove(source, match)
483
+ * @param {Array} source 需要移除项的数组
484
+ * @param {Any} match 要移除的项
485
+ * @meta standard
486
+ * @see baidu.array.removeAt
487
+ *
488
+ * @returns {Array} 移除后的数组
489
+ */
490
+ baidu.array.remove = function (source, match) {
491
+ var len = source.length;
492
+
493
+ while (len--) {
494
+ if (len in source && source[len] === match) {
495
+ source.splice(len, 1);
496
+ }
497
+ }
498
+ return source;
499
+ };
500
+
501
+ /**
502
+ * 判断目标参数是否Array对象
503
+ * @name baidu.lang.isArray
504
+ * @function
505
+ * @grammar baidu.lang.isArray(source)
506
+ * @param {Any} source 目标参数
507
+ * @meta standard
508
+ * @see baidu.lang.isString,baidu.lang.isObject,baidu.lang.isNumber,baidu.lang.isElement,baidu.lang.isBoolean,baidu.lang.isDate
509
+ *
510
+ * @returns {boolean} 类型判断结果
511
+ */
512
+ baidu.lang.isArray = function (source) {
513
+ return '[object Array]' == Object.prototype.toString.call(source);
514
+ };
515
+
516
+
517
+
518
+ /**
519
+ * 将一个变量转换成array
520
+ * @name baidu.lang.toArray
521
+ * @function
522
+ * @grammar baidu.lang.toArray(source)
523
+ * @param {mix} source 需要转换成array的变量
524
+ * @version 1.3
525
+ * @meta standard
526
+ * @returns {array} 转换后的array
527
+ */
528
+ baidu.lang.toArray = function (source) {
529
+ if (source === null || source === undefined)
530
+ return [];
531
+ if (baidu.lang.isArray(source))
532
+ return source;
533
+ if (typeof source.length !== 'number' || typeof source === 'string' || baidu.lang.isFunction(source)) {
534
+ return [source];
535
+ }
536
+ if (source.item) {
537
+ var l = source.length, array = new Array(l);
538
+ while (l--)
539
+ array[l] = source[l];
540
+ return array;
541
+ }
542
+
543
+ return [].slice.call(source);
544
+ };
545
+
546
+ /**
547
+ * 获得flash对象的实例
548
+ * @name baidu.swf.getMovie
549
+ * @function
550
+ * @grammar baidu.swf.getMovie(name)
551
+ * @param {string} name flash对象的名称
552
+ * @see baidu.swf.create
553
+ * @meta standard
554
+ * @returns {HTMLElement} flash对象的实例
555
+ */
556
+ baidu.swf.getMovie = function (name) {
557
+ var movie = document[name], ret;
558
+ return baidu.browser.ie == 9 ?
559
+ movie && movie.length ?
560
+ (ret = baidu.array.remove(baidu.lang.toArray(movie),function(item){
561
+ return item.tagName.toLowerCase() != "embed";
562
+ })).length == 1 ? ret[0] : ret
563
+ : movie
564
+ : movie || window[name];
565
+ };
566
+
567
+
568
+ baidu.flash._Base = (function(){
569
+
570
+ var prefix = 'bd__flash__';
571
+
572
+ /**
573
+ * 创建一个随机的字符串
574
+ * @private
575
+ * @return {String}
576
+ */
577
+ function _createString(){
578
+ return prefix + Math.floor(Math.random() * 2147483648).toString(36);
579
+ };
580
+
581
+ /**
582
+ * 检查flash状态
583
+ * @private
584
+ * @param {Object} target flash对象
585
+ * @return {Boolean}
586
+ */
587
+ function _checkReady(target){
588
+ if(typeof target !== 'undefined' && typeof target.flashInit !== 'undefined' && target.flashInit()){
589
+ return true;
590
+ }else{
591
+ return false;
592
+ }
593
+ };
594
+
595
+ /**
596
+ * 调用之前进行压栈的函数
597
+ * @private
598
+ * @param {Array} callQueue 调用队列
599
+ * @param {Object} target flash对象
600
+ * @return {Null}
601
+ */
602
+ function _callFn(callQueue, target){
603
+ var result = null;
604
+
605
+ callQueue = callQueue.reverse();
606
+ baidu.each(callQueue, function(item){
607
+ result = target.call(item.fnName, item.params);
608
+ item.callBack(result);
609
+ });
610
+ };
611
+
612
+ /**
613
+ * 为传入的匿名函数创建函数名
614
+ * @private
615
+ * @param {String|Function} fun 传入的匿名函数或者函数名
616
+ * @return {String}
617
+ */
618
+ function _createFunName(fun){
619
+ var name = '';
620
+
621
+ if(baidu.lang.isFunction(fun)){
622
+ name = _createString();
623
+ window[name] = function(){
624
+ fun.apply(window, arguments);
625
+ };
626
+
627
+ return name;
628
+ }else if(baidu.lang.isString){
629
+ return fun;
630
+ }
631
+ };
632
+
633
+ /**
634
+ * 绘制flash
635
+ * @private
636
+ * @param {Object} options 创建参数
637
+ * @return {Object}
638
+ */
639
+ function _render(options){
640
+ if(!options.id){
641
+ options.id = _createString();
642
+ }
643
+
644
+ var container = options.container || '';
645
+ delete(options.container);
646
+
647
+ baidu.swf.create(options, container);
648
+
649
+ return baidu.swf.getMovie(options.id);
650
+ };
651
+
652
+ return function(options, callBack){
653
+ var me = this,
654
+ autoRender = (typeof options.autoRender !== 'undefined' ? options.autoRender : true),
655
+ createOptions = options.createOptions || {},
656
+ target = null,
657
+ isReady = false,
658
+ callQueue = [],
659
+ timeHandle = null,
660
+ callBack = callBack || [];
661
+
662
+ /**
663
+ * 将flash文件绘制到页面上
664
+ * @public
665
+ * @return {Null}
666
+ */
667
+ me.render = function(){
668
+ target = _render(createOptions);
669
+
670
+ if(callBack.length > 0){
671
+ baidu.each(callBack, function(funName, index){
672
+ callBack[index] = _createFunName(options[funName] || new Function());
673
+ });
674
+ }
675
+ me.call('setJSFuncName', [callBack]);
676
+ };
677
+
678
+ /**
679
+ * 返回flash状态
680
+ * @return {Boolean}
681
+ */
682
+ me.isReady = function(){
683
+ return isReady;
684
+ };
685
+
686
+ /**
687
+ * 调用flash接口的统一入口
688
+ * @param {String} fnName 调用的函数名
689
+ * @param {Array} params 传入的参数组成的数组,若不许要参数,需传入空数组
690
+ * @param {Function} [callBack] 异步调用后将返回值作为参数的调用回调函数,如无返回值,可以不传入此参数
691
+ * @return {Null}
692
+ */
693
+ me.call = function(fnName, params, callBack){
694
+ if(!fnName) return null;
695
+ callBack = callBack || new Function();
696
+
697
+ var result = null;
698
+
699
+ if(isReady){
700
+ result = target.call(fnName, params);
701
+ callBack(result);
702
+ }else{
703
+ callQueue.push({
704
+ fnName: fnName,
705
+ params: params,
706
+ callBack: callBack
707
+ });
708
+
709
+ (!timeHandle) && (timeHandle = setInterval(_check, 200));
710
+ }
711
+ };
712
+
713
+ /**
714
+ * 为传入的匿名函数创建函数名
715
+ * @public
716
+ * @param {String|Function} fun 传入的匿名函数或者函数名
717
+ * @return {String}
718
+ */
719
+ me.createFunName = function(fun){
720
+ return _createFunName(fun);
721
+ };
722
+
723
+ /**
724
+ * 检查flash是否ready, 并进行调用
725
+ * @private
726
+ * @return {Null}
727
+ */
728
+ function _check(){
729
+ if(_checkReady(target)){
730
+ clearInterval(timeHandle);
731
+ timeHandle = null;
732
+ _call();
733
+
734
+ isReady = true;
735
+ }
736
+ };
737
+
738
+ /**
739
+ * 调用之前进行压栈的函数
740
+ * @private
741
+ * @return {Null}
742
+ */
743
+ function _call(){
744
+ _callFn(callQueue, target);
745
+ callQueue = [];
746
+ }
747
+
748
+ autoRender && me.render();
749
+ };
750
+ })();
751
+
752
+
753
+
754
+ /**
755
+ * 创建flash based imageUploader
756
+ * @class
757
+ * @grammar baidu.flash.imageUploader(options)
758
+ * @param {Object} createOptions 创建flash时需要的参数,请参照baidu.swf.create文档
759
+ * @config {Object} vars 创建imageUploader时所需要的参数
760
+ * @config {Number} vars.gridWidth 每一个预览图片所占的宽度,应该为flash寛的整除
761
+ * @config {Number} vars.gridHeight 每一个预览图片所占的高度,应该为flash高的整除
762
+ * @config {Number} vars.picWidth 单张预览图片的宽度
763
+ * @config {Number} vars.picHeight 单张预览图片的高度
764
+ * @config {String} vars.uploadDataFieldName POST请求中图片数据的key,默认值'picdata'
765
+ * @config {String} vars.picDescFieldName POST请求中图片描述的key,默认值'picDesc'
766
+ * @config {Number} vars.maxSize 文件的最大体积,单位'MB'
767
+ * @config {Number} vars.compressSize 上传前如果图片体积超过该值,会先压缩
768
+ * @config {Number} vars.maxNum:32 最大上传多少个文件
769
+ * @config {Number} vars.compressLength 能接受的最大边长,超过该值会等比压缩
770
+ * @config {String} vars.url 上传的url地址
771
+ * @config {Number} vars.mode mode == 0时,是使用滚动条,mode == 1时,拉伸flash, 默认值为0
772
+ * @see baidu.swf.createHTML
773
+ * @param {String} backgroundUrl 背景图片路径
774
+ * @param {String} listBacgroundkUrl 布局控件背景
775
+ * @param {String} buttonUrl 按钮图片不背景
776
+ * @param {String|Function} selectFileCallback 选择文件的回调
777
+ * @param {String|Function} exceedFileCallback文件超出限制的最大体积时的回调
778
+ * @param {String|Function} deleteFileCallback 删除文件的回调
779
+ * @param {String|Function} startUploadCallback 开始上传某个文件时的回调
780
+ * @param {String|Function} uploadCompleteCallback 某个文件上传完成的回调
781
+ * @param {String|Function} uploadErrorCallback 某个文件上传失败的回调
782
+ * @param {String|Function} allCompleteCallback 全部上传完成时的回调
783
+ * @param {String|Function} changeFlashHeight 改变Flash的高度,mode==1的时候才有用
784
+ */
785
+ baidu.flash.imageUploader = baidu.flash.imageUploader || function(options){
786
+
787
+ var me = this,
788
+ options = options || {},
789
+ _flash = new baidu.flash._Base(options, [
790
+ 'selectFileCallback',
791
+ 'exceedFileCallback',
792
+ 'deleteFileCallback',
793
+ 'startUploadCallback',
794
+ 'uploadCompleteCallback',
795
+ 'uploadErrorCallback',
796
+ 'allCompleteCallback',
797
+ 'changeFlashHeight'
798
+ ]);
799
+ /**
800
+ * 开始或回复上传图片
801
+ * @public
802
+ * @return {Null}
803
+ */
804
+ me.upload = function(){
805
+ _flash.call('upload');
806
+ };
807
+
808
+ /**
809
+ * 暂停上传图片
810
+ * @public
811
+ * @return {Null}
812
+ */
813
+ me.pause = function(){
814
+ _flash.call('pause');
815
+ };
816
+ me.addCustomizedParams = function(index,obj){
817
+ _flash.call('addCustomizedParams',[index,obj]);
818
+ }
819
+ };
820
+
821
+ /**
822
+ * 操作原生对象的方法
823
+ * @namespace baidu.object
824
+ */
825
+ baidu.object = baidu.object || {};
826
+
827
+
828
+ /**
829
+ * 将源对象的所有属性拷贝到目标对象中
830
+ * @author erik
831
+ * @name baidu.object.extend
832
+ * @function
833
+ * @grammar baidu.object.extend(target, source)
834
+ * @param {Object} target 目标对象
835
+ * @param {Object} source 源对象
836
+ * @see baidu.array.merge
837
+ * @remark
838
+ *
839
+ 1.目标对象中,与源对象key相同的成员将会被覆盖。<br>
840
+ 2.源对象的prototype成员不会拷贝。
841
+
842
+ * @shortcut extend
843
+ * @meta standard
844
+ *
845
+ * @returns {Object} 目标对象
846
+ */
847
+ baidu.extend =
848
+ baidu.object.extend = function (target, source) {
849
+ for (var p in source) {
850
+ if (source.hasOwnProperty(p)) {
851
+ target[p] = source[p];
852
+ }
853
+ }
854
+
855
+ return target;
856
+ };
857
+
858
+
859
+
860
+
861
+
862
+ /**
863
+ * 创建flash based fileUploader
864
+ * @class
865
+ * @grammar baidu.flash.fileUploader(options)
866
+ * @param {Object} options
867
+ * @config {Object} createOptions 创建flash时需要的参数,请参照baidu.swf.create文档
868
+ * @config {String} createOptions.width
869
+ * @config {String} createOptions.height
870
+ * @config {Number} maxNum 最大可选文件数
871
+ * @config {Function|String} selectFile
872
+ * @config {Function|String} exceedMaxSize
873
+ * @config {Function|String} deleteFile
874
+ * @config {Function|String} uploadStart
875
+ * @config {Function|String} uploadComplete
876
+ * @config {Function|String} uploadError
877
+ * @config {Function|String} uploadProgress
878
+ */
879
+ baidu.flash.fileUploader = baidu.flash.fileUploader || function(options){
880
+ var me = this,
881
+ options = options || {};
882
+
883
+ options.createOptions = baidu.extend({
884
+ wmod: 'transparent'
885
+ },options.createOptions || {});
886
+
887
+ var _flash = new baidu.flash._Base(options, [
888
+ 'selectFile',
889
+ 'exceedMaxSize',
890
+ 'deleteFile',
891
+ 'uploadStart',
892
+ 'uploadComplete',
893
+ 'uploadError',
894
+ 'uploadProgress'
895
+ ]);
896
+
897
+ _flash.call('setMaxNum', options.maxNum ? [options.maxNum] : [1]);
898
+
899
+ /**
900
+ * 设置当鼠标移动到flash上时,是否变成手型
901
+ * @public
902
+ * @param {Boolean} isCursor
903
+ * @return {Null}
904
+ */
905
+ me.setHandCursor = function(isCursor){
906
+ _flash.call('setHandCursor', [isCursor || false]);
907
+ };
908
+
909
+ /**
910
+ * 设置鼠标相应函数名
911
+ * @param {String|Function} fun
912
+ */
913
+ me.setMSFunName = function(fun){
914
+ _flash.call('setMSFunName',[_flash.createFunName(fun)]);
915
+ };
916
+
917
+ /**
918
+ * 执行上传操作
919
+ * @param {String} url 上传的url
920
+ * @param {String} fieldName 上传的表单字段名
921
+ * @param {Object} postData 键值对,上传的POST数据
922
+ * @param {Number|Array|null|-1} [index]上传的文件序列
923
+ * Int值上传该文件
924
+ * Array一次串行上传该序列文件
925
+ * -1/null上传所有文件
926
+ * @return {Null}
927
+ */
928
+ me.upload = function(url, fieldName, postData, index){
929
+
930
+ if(typeof url !== 'string' || typeof fieldName !== 'string') return null;
931
+ if(typeof index === 'undefined') index = -1;
932
+
933
+ _flash.call('upload', [url, fieldName, postData, index]);
934
+ };
935
+
936
+ /**
937
+ * 取消上传操作
938
+ * @public
939
+ * @param {Number|-1} index
940
+ */
941
+ me.cancel = function(index){
942
+ if(typeof index === 'undefined') index = -1;
943
+ _flash.call('cancel', [index]);
944
+ };
945
+
946
+ /**
947
+ * 删除文件
948
+ * @public
949
+ * @param {Number|Array} [index] 要删除的index,不传则全部删除
950
+ * @param {Function} callBack
951
+ * @param
952
+ * */
953
+ me.deleteFile = function(index, callBack){
954
+
955
+ var callBackAll = function(list){
956
+ callBack && callBack(list);
957
+ };
958
+
959
+ if(typeof index === 'undefined'){
960
+ _flash.call('deleteFilesAll', [], callBackAll);
961
+ return;
962
+ };
963
+
964
+ if(typeof index === 'Number') index = [index];
965
+ index.sort(function(a,b){
966
+ return b-a;
967
+ });
968
+ baidu.each(index, function(item){
969
+ _flash.call('deleteFileBy', item, callBackAll);
970
+ });
971
+ };
972
+
973
+ /**
974
+ * 添加文件类型,支持macType
975
+ * @public
976
+ * @param {Object|Array[Object]} type {description:String, extention:String}
977
+ * @return {Null};
978
+ */
979
+ me.addFileType = function(type){
980
+ var type = type || [[]];
981
+
982
+ if(type instanceof Array) type = [type];
983
+ else type = [[type]];
984
+ _flash.call('addFileTypes', type);
985
+ };
986
+
987
+ /**
988
+ * 设置文件类型,支持macType
989
+ * @public
990
+ * @param {Object|Array[Object]} type {description:String, extention:String}
991
+ * @return {Null};
992
+ */
993
+ me.setFileType = function(type){
994
+ var type = type || [[]];
995
+
996
+ if(type instanceof Array) type = [type];
997
+ else type = [[type]];
998
+ _flash.call('setFileTypes', type);
999
+ };
1000
+
1001
+ /**
1002
+ * 设置可选文件的数量限制
1003
+ * @public
1004
+ * @param {Number} num
1005
+ * @return {Null}
1006
+ */
1007
+ me.setMaxNum = function(num){
1008
+ _flash.call('setMaxNum', [num]);
1009
+ };
1010
+
1011
+ /**
1012
+ * 设置可选文件大小限制,以兆M为单位
1013
+ * @public
1014
+ * @param {Number} num,0为无限制
1015
+ * @return {Null}
1016
+ */
1017
+ me.setMaxSize = function(num){
1018
+ _flash.call('setMaxSize', [num]);
1019
+ };
1020
+
1021
+ /**
1022
+ * @public
1023
+ */
1024
+ me.getFileAll = function(callBack){
1025
+ _flash.call('getFileAll', [], callBack);
1026
+ };
1027
+
1028
+ /**
1029
+ * @public
1030
+ * @param {Number} index
1031
+ * @param {Function} [callBack]
1032
+ */
1033
+ me.getFileByIndex = function(index, callBack){
1034
+ _flash.call('getFileByIndex', [], callBack);
1035
+ };
1036
+
1037
+ /**
1038
+ * @public
1039
+ * @param {Number} index
1040
+ * @param {function} [callBack]
1041
+ */
1042
+ me.getStatusByIndex = function(index, callBack){
1043
+ _flash.call('getStatusByIndex', [], callBack);
1044
+ };
1045
+ };
1046
+
1047
+ /**
1048
+ * 使用动态script标签请求服务器资源,包括由服务器端的回调和浏览器端的回调
1049
+ * @namespace baidu.sio
1050
+ */
1051
+ baidu.sio = baidu.sio || {};
1052
+
1053
+ /**
1054
+ *
1055
+ * @param {HTMLElement} src script节点
1056
+ * @param {String} url script节点的地址
1057
+ * @param {String} [charset] 编码
1058
+ */
1059
+ baidu.sio._createScriptTag = function(scr, url, charset){
1060
+ scr.setAttribute('type', 'text/javascript');
1061
+ charset && scr.setAttribute('charset', charset);
1062
+ scr.setAttribute('src', url);
1063
+ document.getElementsByTagName('head')[0].appendChild(scr);
1064
+ };
1065
+
1066
+ /**
1067
+ * 删除script的属性,再删除script标签,以解决修复内存泄漏的问题
1068
+ *
1069
+ * @param {HTMLElement} src script节点
1070
+ */
1071
+ baidu.sio._removeScriptTag = function(scr){
1072
+ if (scr.clearAttributes) {
1073
+ scr.clearAttributes();
1074
+ } else {
1075
+ for (var attr in scr) {
1076
+ if (scr.hasOwnProperty(attr)) {
1077
+ delete scr[attr];
1078
+ }
1079
+ }
1080
+ }
1081
+ if(scr && scr.parentNode){
1082
+ scr.parentNode.removeChild(scr);
1083
+ }
1084
+ scr = null;
1085
+ };
1086
+
1087
+
1088
+ /**
1089
+ * 通过script标签加载数据,加载完成由浏览器端触发回调
1090
+ * @name baidu.sio.callByBrowser
1091
+ * @function
1092
+ * @grammar baidu.sio.callByBrowser(url, opt_callback, opt_options)
1093
+ * @param {string} url 加载数据的url
1094
+ * @param {Function|string} opt_callback 数据加载结束时调用的函数或函数名
1095
+ * @param {Object} opt_options 其他可选项
1096
+ * @config {String} [charset] script的字符集
1097
+ * @config {Integer} [timeOut] 超时时间,超过这个时间将不再响应本请求,并触发onfailure函数
1098
+ * @config {Function} [onfailure] timeOut设定后才生效,到达超时时间时触发本函数
1099
+ * @remark
1100
+ * 1、与callByServer不同,callback参数只支持Function类型,不支持string。
1101
+ * 2、如果请求了一个不存在的页面,callback函数在IE/opera下也会被调用,因此使用者需要在onsuccess函数中判断数据是否正确加载。
1102
+ * @meta standard
1103
+ * @see baidu.sio.callByServer
1104
+ */
1105
+ baidu.sio.callByBrowser = function (url, opt_callback, opt_options) {
1106
+ var scr = document.createElement("SCRIPT"),
1107
+ scriptLoaded = 0,
1108
+ options = opt_options || {},
1109
+ charset = options['charset'],
1110
+ callback = opt_callback || function(){},
1111
+ timeOut = options['timeOut'] || 0,
1112
+ timer;
1113
+ scr.onload = scr.onreadystatechange = function () {
1114
+ if (scriptLoaded) {
1115
+ return;
1116
+ }
1117
+
1118
+ var readyState = scr.readyState;
1119
+ if ('undefined' == typeof readyState
1120
+ || readyState == "loaded"
1121
+ || readyState == "complete") {
1122
+ scriptLoaded = 1;
1123
+ try {
1124
+ callback();
1125
+ clearTimeout(timer);
1126
+ } finally {
1127
+ scr.onload = scr.onreadystatechange = null;
1128
+ baidu.sio._removeScriptTag(scr);
1129
+ }
1130
+ }
1131
+ };
1132
+
1133
+ if( timeOut ){
1134
+ timer = setTimeout(function(){
1135
+ scr.onload = scr.onreadystatechange = null;
1136
+ baidu.sio._removeScriptTag(scr);
1137
+ options.onfailure && options.onfailure();
1138
+ }, timeOut);
1139
+ }
1140
+
1141
+ baidu.sio._createScriptTag(scr, url, charset);
1142
+ };
1143
+
1144
+ /**
1145
+ * 通过script标签加载数据,加载完成由服务器端触发回调
1146
+ * @name baidu.sio.callByServer
1147
+ * @function
1148
+ * @grammar baidu.sio.callByServer(url, callback[, opt_options])
1149
+ * @param {string} url 加载数据的url.
1150
+ * @param {Function|string} callback 服务器端调用的函数或函数名。如果没有指定本参数,将在URL中寻找options['queryField']做为callback的方法名.
1151
+ * @param {Object} opt_options 加载数据时的选项.
1152
+ * @config {string} [charset] script的字符集
1153
+ * @config {string} [queryField] 服务器端callback请求字段名,默认为callback
1154
+ * @config {Integer} [timeOut] 超时时间(单位:ms),超过这个时间将不再响应本请求,并触发onfailure函数
1155
+ * @config {Function} [onfailure] timeOut设定后才生效,到达超时时间时触发本函数
1156
+ * @remark
1157
+ * 如果url中已经包含key为“options['queryField']”的query项,将会被替换成callback中参数传递或自动生成的函数名。
1158
+ * @meta standard
1159
+ * @see baidu.sio.callByBrowser
1160
+ */
1161
+ baidu.sio.callByServer = /**@function*/function(url, callback, opt_options) {
1162
+ var scr = document.createElement('SCRIPT'),
1163
+ prefix = 'bd__cbs__',
1164
+ callbackName,
1165
+ callbackImpl,
1166
+ options = opt_options || {},
1167
+ charset = options['charset'],
1168
+ queryField = options['queryField'] || 'callback',
1169
+ timeOut = options['timeOut'] || 0,
1170
+ timer,
1171
+ reg = new RegExp('(\\?|&)' + queryField + '=([^&]*)'),
1172
+ matches;
1173
+
1174
+ if (baidu.lang.isFunction(callback)) {
1175
+ callbackName = prefix + Math.floor(Math.random() * 2147483648).toString(36);
1176
+ window[callbackName] = getCallBack(0);
1177
+ } else if(baidu.lang.isString(callback)){
1178
+ callbackName = callback;
1179
+ } else {
1180
+ if (matches = reg.exec(url)) {
1181
+ callbackName = matches[2];
1182
+ }
1183
+ }
1184
+
1185
+ if( timeOut ){
1186
+ timer = setTimeout(getCallBack(1), timeOut);
1187
+ }
1188
+ url = url.replace(reg, '\x241' + queryField + '=' + callbackName);
1189
+
1190
+ if (url.search(reg) < 0) {
1191
+ url += (url.indexOf('?') < 0 ? '?' : '&') + queryField + '=' + callbackName;
1192
+ }
1193
+ baidu.sio._createScriptTag(scr, url, charset);
1194
+
1195
+ /*
1196
+ * 返回一个函数,用于立即(挂在window上)或者超时(挂在setTimeout中)时执行
1197
+ */
1198
+ function getCallBack(onTimeOut){
1199
+ /*global callbackName, callback, scr, options;*/
1200
+ return function(){
1201
+ try {
1202
+ if( onTimeOut ){
1203
+ options.onfailure && options.onfailure();
1204
+ }else{
1205
+ callback.apply(window, arguments);
1206
+ clearTimeout(timer);
1207
+ }
1208
+ window[callbackName] = null;
1209
+ delete window[callbackName];
1210
+ } catch (exception) {
1211
+ } finally {
1212
+ baidu.sio._removeScriptTag(scr);
1213
+ }
1214
+ }
1215
+ }
1216
+ };
1217
+
1218
+ /**
1219
+ * 通过请求一个图片的方式令服务器存储一条日志
1220
+ * @function
1221
+ * @grammar baidu.sio.log(url)
1222
+ * @param {string} url 要发送的地址.
1223
+ * @author: int08h,leeight
1224
+ */
1225
+ baidu.sio.log = function(url) {
1226
+ var img = new Image(),
1227
+ key = 'tangram_sio_log_' + Math.floor(Math.random() *
1228
+ 2147483648).toString(36);
1229
+ window[key] = img;
1230
+
1231
+ img.onload = img.onerror = img.onabort = function() {
1232
+ img.onload = img.onerror = img.onabort = null;
1233
+
1234
+ window[key] = null;
1235
+ img = null;
1236
+ };
1237
+ img.src = url;
1238
+ };