wordimage.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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':'background:url(' + ( flag ? opt.themePath + opt.theme + '/images/word.gif' : opt.langPath + opt.lang + '/images/localimage.png') + ') no-repeat center center;border:1px solid #ddd'
  47. })
  48. }
  49. })
  50. }
  51. }
  52. });