wordimage.html 5.9 KB

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