wordimage.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  6. <script type="text/javascript" src="../internal.js"></script>
  7. <style type="text/css">
  8. .wrapper {
  9. width: 600px;
  10. padding: 10px;
  11. height: 352px;
  12. overflow: hidden;
  13. position: relative;
  14. border-bottom: 1px solid #d7d7d7;
  15. }
  16. .localPath input {
  17. float: left;
  18. width: 350px;
  19. line-height: 20px;
  20. height: 20px;
  21. }
  22. #clipboard {
  23. float: left;
  24. width: 70px;
  25. height: 30px;
  26. }
  27. .description {
  28. color: #0066cc;
  29. margin-top: 2px;
  30. width: 450px;
  31. height: 45px;
  32. float: left;
  33. line-height: 22px;
  34. }
  35. #upload {
  36. width: 100px;
  37. height: 30px;
  38. float: right;
  39. margin: 10px 2px 0 0;
  40. cursor: pointer;
  41. }
  42. #msg {
  43. width: 140px;
  44. height: 30px;
  45. line-height: 25px;
  46. float: left;
  47. color: red;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div class="wrapper">
  53. <div class="localPath">
  54. <input id="localPath" type="text" readonly />
  55. <div id="clipboard"></div>
  56. <div id="msg"></div>
  57. </div>
  58. <div id="flashContainer"></div>
  59. <div>
  60. <div id="upload" style="display: none"><img id="uploadBtn" /></div>
  61. <div class="description">
  62. <span style="color: red">
  63. <var id="lang_resave"></var>
  64. :
  65. </span>
  66. <var id="lang_step"></var>
  67. </div>
  68. </div>
  69. </div>
  70. <script type="text/javascript" src="tangram.js"></script>
  71. <script type="text/javascript" src="wordimage.js"></script>
  72. <script type="text/javascript">
  73. editor.setOpt({
  74. wordImageFieldName: 'upfile',
  75. compressSide: 0,
  76. maxImageSideLength: 900,
  77. })
  78. //全局变量
  79. var imageUrls = [], //用于保存从服务器返回的图片信息数组
  80. selectedImageCount = 0, //当前已选择的但未上传的图片数量
  81. optImageUrl = editor.getActionUrl(editor.getOpt('imageActionName')),
  82. optImageFieldName = editor.getOpt('imageFieldName'),
  83. optImageCompressBorder = editor.getOpt('imageCompressEnable')
  84. ? editor.getOpt('imageCompressBorder')
  85. : null,
  86. maxSize = editor.getOpt('imageMaxSize') / 1024,
  87. extension = editor
  88. .getOpt('imageAllowFiles')
  89. .join(';')
  90. .replace(/\./g, '*.')
  91. /* 添加额外的GET参数 */
  92. var params =
  93. utils.serializeParam(editor.queryCommandValue('serverparam')) || '',
  94. urlWidthParams =
  95. optImageUrl + (optImageUrl.indexOf('?') == -1 ? '?' : '&') + params
  96. utils.domReady(function () {
  97. //创建Flash相关的参数集合
  98. var flashOptions = {
  99. container: 'flashContainer', //flash容器id
  100. url: urlWidthParams, // 上传处理页面的url地址
  101. ext: editor.queryCommandValue('serverParam') || {}, //可向服务器提交的自定义参数列表
  102. fileType:
  103. '{"description":"' +
  104. lang.fileType +
  105. '", "extension":"' +
  106. extension +
  107. '"}', //上传文件格式限制
  108. flashUrl: 'imageUploader.swf', //上传用的flash组件地址
  109. width: 600, //flash的宽度
  110. height: 272, //flash的高度
  111. gridWidth: 120, // 每一个预览图片所占的宽度
  112. gridHeight: 120, // 每一个预览图片所占的高度
  113. picWidth: 100, // 单张预览图片的宽度
  114. picHeight: 100, // 单张预览图片的高度
  115. uploadDataFieldName: optImageFieldName, // POST请求中图片数据的key
  116. picDescFieldName: 'pictitle', // POST请求中图片描述的key
  117. maxSize: maxSize, // 文件的最大体积,单位M
  118. compressSize: 1, // 上传前如果图片体积超过该值,会先压缩,单位M
  119. maxNum: 32, // 单次最大可上传多少个文件
  120. compressSide: 0, //等比压缩的基准,0为按照最长边,1为按照宽度,2为按照高度
  121. compressLength: optImageCompressBorder, //能接受的最大边长,超过该值Flash会自动等比压缩
  122. }
  123. //回调函数集合,支持传递函数名的字符串、函数句柄以及函数本身三种类型
  124. var callbacks = {
  125. selectFileCallback: function (selectFiles) {
  126. // 选择文件的回调
  127. selectedImageCount += selectFiles.length
  128. if (selectedImageCount) baidu.g('upload').style.display = ''
  129. dialog.buttons[0].setDisabled(true) //初始化时置灰确定按钮
  130. },
  131. deleteFileCallback: function (delFiles) {
  132. // 删除文件的回调
  133. selectedImageCount -= delFiles.length
  134. if (!selectedImageCount) {
  135. baidu.g('upload').style.display = 'none'
  136. dialog.buttons[0].setDisabled(false) //没有选择图片时重新点亮按钮
  137. }
  138. },
  139. uploadCompleteCallback: function (data) {
  140. // 单个文件上传完成的回调
  141. try {
  142. var info = eval('(' + data.info + ')')
  143. info && imageUrls.push(info)
  144. selectedImageCount--
  145. } catch (e) {}
  146. },
  147. uploadErrorCallback: function (data) {
  148. // 单个文件上传失败的回调,
  149. console && console.log(data)
  150. },
  151. allCompleteCallback: function () {
  152. // 全部上传完成时的回调
  153. dialog.buttons[0].setDisabled(false) //上传完毕后点亮按钮
  154. },
  155. //exceedFileCallback: 'exceedFileCallback', // 文件超出限制的最大体积时的回调
  156. //startUploadCallback: startUploadCallback // 开始上传某个文件时的回调
  157. }
  158. wordImage.init(flashOptions, callbacks)
  159. })
  160. </script>
  161. </body>
  162. </html>