wordimage.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ///import core
  2. ///commands 本地图片引导上传
  3. ///commandsName WordImage
  4. ///commandsTitle 本地图片引导上传
  5. ///commandsDialog dialogs\wordimage
  6. UE.plugin.register("wordimage", function() {
  7. var me = this,
  8. images = [];
  9. return {
  10. commands: {
  11. wordimage: {
  12. execCommand: function() {
  13. var images = domUtils.getElementsByTagName(me.body, "img");
  14. var urlList = [];
  15. for (var i = 0, ci; (ci = images[i++]); ) {
  16. var url = ci.getAttribute("word_img");
  17. url && urlList.push(url);
  18. }
  19. return urlList;
  20. },
  21. queryCommandState: function() {
  22. images = domUtils.getElementsByTagName(me.body, "img");
  23. for (var i = 0, ci; (ci = images[i++]); ) {
  24. if (ci.getAttribute("word_img")) {
  25. return 1;
  26. }
  27. }
  28. return -1;
  29. },
  30. notNeedUndo: true
  31. }
  32. },
  33. inputRule: function(root) {
  34. utils.each(root.getNodesByTagName("img"), function(img) {
  35. var attrs = img.attrs,
  36. flag = parseInt(attrs.width) < 128 || parseInt(attrs.height) < 43,
  37. opt = me.options,
  38. src = opt.UEDITOR_HOME_URL + "themes/default/images/spacer.gif";
  39. if (attrs["src"] && /^(?:(file:\/+))/.test(attrs["src"])) {
  40. img.setAttr({
  41. width: attrs.width,
  42. height: attrs.height,
  43. alt: attrs.alt,
  44. word_img: attrs.src,
  45. src: src,
  46. style:
  47. "background:url(" +
  48. (flag
  49. ? opt.themePath + opt.theme + "/images/word.gif"
  50. : opt.langPath + opt.lang + "/images/localimage.png") +
  51. ") no-repeat center center;border:1px solid #ddd"
  52. });
  53. }
  54. });
  55. }
  56. };
  57. });