ueditor-rails 1.2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +49 -0
  5. data/Rakefile +1 -0
  6. data/app/assets/javascripts/ueditor.js +3 -0
  7. data/lib/tasks/ueditor.rake +12 -0
  8. data/lib/ueditor-rails.rb +1 -0
  9. data/lib/ueditor/rails.rb +9 -0
  10. data/lib/ueditor/rails/engine.rb +20 -0
  11. data/lib/ueditor/rails/version.rb +6 -0
  12. data/ueditor-rails.gemspec +20 -0
  13. data/vendor/assets/javascripts/ueditor/.DS_Store +0 -0
  14. data/vendor/assets/javascripts/ueditor/dialogs/.DS_Store +0 -0
  15. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.css +43 -0
  16. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.html +54 -0
  17. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.js +186 -0
  18. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/0.gif +0 -0
  19. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/bface.gif +0 -0
  20. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/cface.gif +0 -0
  21. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/fface.gif +0 -0
  22. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/jxface2.gif +0 -0
  23. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/neweditor-tab-bg.png +0 -0
  24. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/tface.gif +0 -0
  25. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/wface.gif +0 -0
  26. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/yface.gif +0 -0
  27. data/vendor/assets/javascripts/ueditor/dialogs/image/image.css +69 -0
  28. data/vendor/assets/javascripts/ueditor/dialogs/image/image.html +204 -0
  29. data/vendor/assets/javascripts/ueditor/dialogs/image/image.js +712 -0
  30. data/vendor/assets/javascripts/ueditor/dialogs/image/imageUploader.swf +0 -0
  31. data/vendor/assets/javascripts/ueditor/dialogs/image/images/center_focus.jpg +0 -0
  32. data/vendor/assets/javascripts/ueditor/dialogs/image/images/left_focus.jpg +0 -0
  33. data/vendor/assets/javascripts/ueditor/dialogs/image/images/none_focus.jpg +0 -0
  34. data/vendor/assets/javascripts/ueditor/dialogs/image/images/right_focus.jpg +0 -0
  35. data/vendor/assets/javascripts/ueditor/dialogs/internal.js +79 -0
  36. data/vendor/assets/javascripts/ueditor/dialogs/tangram.js +1238 -0
  37. data/vendor/assets/javascripts/ueditor/dialogs/video/images/center_focus.jpg +0 -0
  38. data/vendor/assets/javascripts/ueditor/dialogs/video/images/left_focus.jpg +0 -0
  39. data/vendor/assets/javascripts/ueditor/dialogs/video/images/none_focus.jpg +0 -0
  40. data/vendor/assets/javascripts/ueditor/dialogs/video/images/right_focus.jpg +0 -0
  41. data/vendor/assets/javascripts/ueditor/dialogs/video/video.css +59 -0
  42. data/vendor/assets/javascripts/ueditor/dialogs/video/video.html +67 -0
  43. data/vendor/assets/javascripts/ueditor/dialogs/video/video.js +402 -0
  44. data/vendor/assets/javascripts/ueditor/editor_all.js +12437 -0
  45. data/vendor/assets/javascripts/ueditor/editor_all_min.js +1 -0
  46. data/vendor/assets/javascripts/ueditor/editor_config.js +209 -0
  47. data/vendor/assets/javascripts/ueditor/index.html +146 -0
  48. data/vendor/assets/javascripts/ueditor/lang/en/en.js +528 -0
  49. data/vendor/assets/javascripts/ueditor/lang/en/images/addimage.png +0 -0
  50. data/vendor/assets/javascripts/ueditor/lang/en/images/alldeletebtnhoverskin.png +0 -0
  51. data/vendor/assets/javascripts/ueditor/lang/en/images/alldeletebtnupskin.png +0 -0
  52. data/vendor/assets/javascripts/ueditor/lang/en/images/background.png +0 -0
  53. data/vendor/assets/javascripts/ueditor/lang/en/images/button.png +0 -0
  54. data/vendor/assets/javascripts/ueditor/lang/en/images/copy.png +0 -0
  55. data/vendor/assets/javascripts/ueditor/lang/en/images/deletedisable.png +0 -0
  56. data/vendor/assets/javascripts/ueditor/lang/en/images/deleteenable.png +0 -0
  57. data/vendor/assets/javascripts/ueditor/lang/en/images/imglabel.png +0 -0
  58. data/vendor/assets/javascripts/ueditor/lang/en/images/listbackground.png +0 -0
  59. data/vendor/assets/javascripts/ueditor/lang/en/images/localimage.png +0 -0
  60. data/vendor/assets/javascripts/ueditor/lang/en/images/music.png +0 -0
  61. data/vendor/assets/javascripts/ueditor/lang/en/images/rotateleftdisable.png +0 -0
  62. data/vendor/assets/javascripts/ueditor/lang/en/images/rotateleftenable.png +0 -0
  63. data/vendor/assets/javascripts/ueditor/lang/en/images/rotaterightdisable.png +0 -0
  64. data/vendor/assets/javascripts/ueditor/lang/en/images/rotaterightenable.png +0 -0
  65. data/vendor/assets/javascripts/ueditor/lang/en/images/upload.png +0 -0
  66. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/copy.png +0 -0
  67. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/imglabel.png +0 -0
  68. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/localimage.png +0 -0
  69. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/music.png +0 -0
  70. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/upload.png +0 -0
  71. data/vendor/assets/javascripts/ueditor/lang/zh-cn/zh-cn.js +492 -0
  72. data/vendor/assets/javascripts/ueditor/php/.DS_Store +0 -0
  73. data/vendor/assets/javascripts/ueditor/php/Uploader.class.php +198 -0
  74. data/vendor/assets/javascripts/ueditor/php/fileUp.php +43 -0
  75. data/vendor/assets/javascripts/ueditor/php/getContent.php +21 -0
  76. data/vendor/assets/javascripts/ueditor/php/getMovie.php +13 -0
  77. data/vendor/assets/javascripts/ueditor/php/getRemoteImage.php +100 -0
  78. data/vendor/assets/javascripts/ueditor/php/imageManager.php +56 -0
  79. data/vendor/assets/javascripts/ueditor/php/imageUp.php +48 -0
  80. data/vendor/assets/javascripts/ueditor/php/scrawlUp.php +60 -0
  81. data/vendor/assets/javascripts/ueditor/themes/.DS_Store +0 -0
  82. data/vendor/assets/javascripts/ueditor/themes/default/.DS_Store +0 -0
  83. data/vendor/assets/javascripts/ueditor/themes/default/css/ueditor.css +1582 -0
  84. data/vendor/assets/javascripts/ueditor/themes/default/dialogbase.css +100 -0
  85. data/vendor/assets/javascripts/ueditor/themes/default/images/.DS_Store +0 -0
  86. data/vendor/assets/javascripts/ueditor/themes/default/images/anchor.gif +0 -0
  87. data/vendor/assets/javascripts/ueditor/themes/default/images/arrow.png +0 -0
  88. data/vendor/assets/javascripts/ueditor/themes/default/images/button-bg.gif +0 -0
  89. data/vendor/assets/javascripts/ueditor/themes/default/images/cancelbutton.gif +0 -0
  90. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_h.gif +0 -0
  91. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_h.png +0 -0
  92. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_v.gif +0 -0
  93. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_v.png +0 -0
  94. data/vendor/assets/javascripts/ueditor/themes/default/images/dialog-title-bg.png +0 -0
  95. data/vendor/assets/javascripts/ueditor/themes/default/images/filescan.png +0 -0
  96. data/vendor/assets/javascripts/ueditor/themes/default/images/highlighted.gif +0 -0
  97. data/vendor/assets/javascripts/ueditor/themes/default/images/icons-all.gif +0 -0
  98. data/vendor/assets/javascripts/ueditor/themes/default/images/icons.gif +0 -0
  99. data/vendor/assets/javascripts/ueditor/themes/default/images/icons.png +0 -0
  100. data/vendor/assets/javascripts/ueditor/themes/default/images/lock.gif +0 -0
  101. data/vendor/assets/javascripts/ueditor/themes/default/images/neweditor-tab-bg.png +0 -0
  102. data/vendor/assets/javascripts/ueditor/themes/default/images/pagebreak.gif +0 -0
  103. data/vendor/assets/javascripts/ueditor/themes/default/images/scale.png +0 -0
  104. data/vendor/assets/javascripts/ueditor/themes/default/images/spacer.gif +0 -0
  105. data/vendor/assets/javascripts/ueditor/themes/default/images/sparator_v.png +0 -0
  106. data/vendor/assets/javascripts/ueditor/themes/default/images/toolbar_bg.png +0 -0
  107. data/vendor/assets/javascripts/ueditor/themes/default/images/unhighlighted.gif +0 -0
  108. data/vendor/assets/javascripts/ueditor/themes/default/images/upload.png +0 -0
  109. data/vendor/assets/javascripts/ueditor/themes/default/images/videologo.gif +0 -0
  110. data/vendor/assets/javascripts/ueditor/themes/default/images/word.gif +0 -0
  111. data/vendor/assets/javascripts/ueditor/themes/default/images/wordpaste.png +0 -0
  112. data/vendor/assets/javascripts/ueditor/themes/iframe.css +1 -0
  113. data/vendor/assets/javascripts/ueditor/uparse.js +358 -0
  114. metadata +159 -0
@@ -0,0 +1,79 @@
1
+ (function () {
2
+ var parent = window.parent;
3
+ //dialog对象
4
+ dialog = parent.$EDITORUI[window.frameElement.id.replace( /_iframe$/, '' )];
5
+ //当前打开dialog的编辑器实例
6
+ editor = dialog.editor;
7
+
8
+ UE = parent.UE;
9
+
10
+ domUtils = UE.dom.domUtils;
11
+
12
+ utils = UE.utils;
13
+
14
+ browser = UE.browser;
15
+
16
+ ajax = UE.ajax;
17
+
18
+ $G = function ( id ) {
19
+ return document.getElementById( id )
20
+ };
21
+ //focus元素
22
+ $focus = function ( node ) {
23
+ setTimeout( function () {
24
+ if ( browser.ie ) {
25
+ var r = node.createTextRange();
26
+ r.collapse( false );
27
+ r.select();
28
+ } else {
29
+ node.focus()
30
+ }
31
+ }, 0 )
32
+ };
33
+ utils.loadFile(document,{
34
+ href:editor.options.themePath + editor.options.theme + "/dialogbase.css?cache="+Math.random(),
35
+ tag:"link",
36
+ type:"text/css",
37
+ rel:"stylesheet"
38
+ });
39
+ lang = editor.getLang(dialog.className.split( "-" )[2]);
40
+
41
+ domUtils.on(window,'load',function () {
42
+
43
+ var langImgPath = editor.options.langPath + editor.options.lang + "/images/";
44
+ //针对静态资源
45
+ for ( var i in lang.static ) {
46
+ var dom = $G( i );
47
+ if(!dom) continue;
48
+ var tagName = dom.tagName,
49
+ content = lang.static[i];
50
+ if(content.src){
51
+ //clone
52
+ content = utils.extend({},content,false);
53
+ content.src = langImgPath + content.src;
54
+ }
55
+ if(content.style){
56
+ content = utils.extend({},content,false);
57
+ content.style = content.style.replace(/url\s*\(/g,"url(" + langImgPath)
58
+ }
59
+ switch ( tagName.toLowerCase() ) {
60
+ case "var":
61
+ dom.parentNode.replaceChild( document.createTextNode( content ), dom );
62
+ break;
63
+ case "select":
64
+ var ops = dom.options;
65
+ for ( var j = 0, oj; oj = ops[j]; ) {
66
+ oj.innerHTML = content.options[j++];
67
+ }
68
+ for ( var p in content ) {
69
+ p != "options" && dom.setAttribute( p, content[p] );
70
+ }
71
+ break;
72
+ default :
73
+ domUtils.setAttributes( dom, content);
74
+ }
75
+ }
76
+ } );
77
+
78
+ })();
79
+
@@ -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
+ };