1ab1b9841ca1e7c8eebe231196403fe381a379f4.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * Created by JetBrains PhpStorm.
  3. * User: taoqili
  4. * Date: 12-1-30
  5. * Time: 下午12:50
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. //editor.execCommand("wordimage","word_img");
  9. var wordImage = {};
  10. //(function(){
  11. var g = baidu.g,
  12. flashObj,flashContainer;
  13. wordImage.init = function(opt, callbacks) {
  14. showLocalPath("localPath");
  15. //createCopyButton("clipboard","localPath");
  16. createFlashUploader(opt, callbacks);
  17. addUploadListener();
  18. addOkListener();
  19. };
  20. function hideFlash(){
  21. flashObj = null;
  22. flashContainer.innerHTML = "";
  23. }
  24. function addOkListener() {
  25. dialog.onok = function() {
  26. if (!imageUrls.length) return;
  27. var images = domUtils.getElementsByTagName(editor.document,"img");
  28. for (var i = 0,img; img = images[i++];) {
  29. var src = img.getAttribute("word_img");
  30. if (!src) continue;
  31. for (var j = 0,url; url = imageUrls[j++];) {
  32. if (src.indexOf(url.original.replace(" ","")) != -1) {
  33. img.src = editor.options.wordImagePath + url.url;
  34. img.setAttribute("_src", editor.options.wordImagePath + url.url); //同时修改"_src"属性
  35. img.setAttribute("title",url.title);
  36. parent.baidu.editor.dom.domUtils.removeAttributes(img, ["word_img","style","width","height"]);
  37. editor.fireEvent("selectionchange");
  38. break;
  39. }
  40. }
  41. }
  42. hideFlash();
  43. };
  44. dialog.oncancel = function(){
  45. hideFlash();
  46. }
  47. }
  48. /**
  49. * 绑定开始上传事件
  50. */
  51. function addUploadListener() {
  52. g("upload").onclick = function () {
  53. flashObj.upload();
  54. this.style.display = "none";
  55. };
  56. }
  57. function showLocalPath(id) {
  58. //单张编辑
  59. var img = editor.selection.getRange().getClosedNode();
  60. if(editor.word_img.length==1 || img && img.tagName == 'IMG'){
  61. g(id).value = editor.word_img[0];
  62. return;
  63. }
  64. var path = editor.word_img[0];
  65. var leftSlashIndex = path.lastIndexOf("/")||0, //不同版本的doc和浏览器都可能影响到这个符号,故直接判断两种
  66. rightSlashIndex = path.lastIndexOf("\\")||0,
  67. separater = leftSlashIndex > rightSlashIndex ? "/":"\\" ;
  68. path = path.substring(0, path.lastIndexOf(separater)+1);
  69. g(id).value = path;
  70. }
  71. function createFlashUploader(opt, callbacks) {
  72. //由于lang.flashI18n是静态属性,不可以直接进行修改,否则会影响到后续内容
  73. var i18n = utils.extend({},lang.flashI18n);
  74. //处理图片资源地址的编码,补全等问题
  75. for(var i in i18n){
  76. if(!(i in {"lang":1,"uploadingTF":1,"imageTF":1,"textEncoding":1}) && i18n[i]){
  77. i18n[i] = encodeURIComponent(editor.options.langPath + editor.options.lang + "/images/" + i18n[i]);
  78. }
  79. }
  80. opt = utils.extend(opt,i18n,false);
  81. var option = {
  82. createOptions:{
  83. id:'flash',
  84. url:opt.flashUrl,
  85. width:opt.width,
  86. height:opt.height,
  87. errorMessage:lang.flashError,
  88. wmode:browser.safari ? 'transparent' : 'window',
  89. ver:'10.0.0',
  90. vars:opt,
  91. container:opt.container
  92. }
  93. };
  94. option = extendProperty(callbacks, option);
  95. flashObj = new baidu.flash.imageUploader(option);
  96. flashContainer = $G(opt.container);
  97. }
  98. function extendProperty(fromObj, toObj) {
  99. for (var i in fromObj) {
  100. if (!toObj[i]) {
  101. toObj[i] = fromObj[i];
  102. }
  103. }
  104. return toObj;
  105. }
  106. //})();
  107. function getPasteData(id) {
  108. baidu.g("msg").innerHTML = lang.copySuccess + "</br>";
  109. setTimeout(function() {
  110. baidu.g("msg").innerHTML = "";
  111. }, 5000);
  112. return baidu.g(id).value;
  113. }
  114. function createCopyButton(id, dataFrom) {
  115. baidu.swf.create({
  116. id:"copyFlash",
  117. url:"fClipboard_ueditor.swf",
  118. width:"58",
  119. height:"25",
  120. errorMessage:"",
  121. bgColor:"#CBCBCB",
  122. wmode:"transparent",
  123. ver:"10.0.0",
  124. vars:{
  125. tid:dataFrom
  126. }
  127. }, id
  128. );
  129. var clipboard = baidu.swf.getMovie("copyFlash");
  130. var clipinterval = setInterval(function() {
  131. if (clipboard && clipboard.flashInit) {
  132. clearInterval(clipinterval);
  133. clipboard.setHandCursor(true);
  134. clipboard.setContentFuncName("getPasteData");
  135. //clipboard.setMEFuncName("mouseEventHandler");
  136. }
  137. }, 500);
  138. }
  139. createCopyButton("clipboard", "localPath");