人人商城

plugin.min.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. tinymce.PluginManager.add('image', function(editor) {
  2. function handleImageDialog() {
  3. var dom = editor.dom;
  4. var imgElm = editor.selection.getNode();
  5. require(['util'], function(u){
  6. var v = '';
  7. if (imgElm && imgElm.tagName.toLowerCase() == 'img') {
  8. v = imgElm.src;
  9. }
  10. u.image(v, function(val){
  11. data = {
  12. src: val.url,
  13. alt: val.filename,
  14. title: val.filename
  15. };
  16. if (!data["class"]) {
  17. delete data["class"];
  18. }
  19. if (!imgElm || imgElm.tagName.toLowerCase() != 'img') {
  20. data.id = '__mcenew';
  21. editor.focus();
  22. editor.selection.setContent(dom.createHTML('img', data));
  23. imgElm = dom.get('__mcenew');
  24. dom.setAttrib(imgElm, 'id', null);
  25. } else {
  26. dom.setAttribs(imgElm, data);
  27. }
  28. },'', {direct: true, multi : false} );
  29. });
  30. }
  31. editor.addButton('image', {
  32. icon: 'image',
  33. tooltip: 'Insert/edit image',
  34. onclick: handleImageDialog,
  35. stateSelector: 'img:not([data-mce-object],[data-mce-placeholder])'
  36. });
  37. editor.addMenuItem('image', {
  38. icon: 'image',
  39. text: 'Insert image',
  40. onclick: handleImageDialog,
  41. context: 'insert',
  42. prependToContext: true
  43. });
  44. });