Add attributes to Insert Image dialogue of Umbraco RTE or Create Custom Data type

谁说我不能喝 提交于 2019-12-11 08:23:57

问题


How can I add attributes to the current Insert Image dialogue box on umbraco Richtext Editor?

What I really want is to let content editor choose images and set their class, and maybe choose if this is lightbox image or not. If user choose lighbox option, then a hyper link is added with some extra attributes, like data-rel. I even want to be able to modify the image url added by the content editor, if possible.

The output should look like this

<a href="/media/2813/DSC_2615.JPG" data-rel="prettyPhoto[gal-3-col]" >    
   <img src="http://domain.com/imageGen.ashx?
   image=%2fmedia%2f2813%2fDSC_2615.JPG&amp;width=420" alt="DSC_2615" title="DSC_2615" 
   class="alignright">
</a>

I found this very useful link http://forum.umbraco.org/yaf_postst8163_TinyMCE--insert-image-dialog.aspx which solve half of my issue, but I can't figure out how to continue


回答1:


Default umbraco tinymce add image interface is

<plugin loadOnFrontend="false">umbracoimg</plugin>

I was able to modify it to show additional field in the image selection interface, then render markup I want.

I edited \umbraco\plugins\tinymce3\insertImage.aspx, added my field there and some jquery logic:

<ui:PropertyPanel id="pp_desc" runat="server" Text="Description">
    <input type="text" id="title" style="width: 300px"/>
</ui:PropertyPanel>
...

Then if you are adding custom attributes, you might want to add them to \config\umbracoSettings.config

<!-- what attributes that are allowed in the editor on an img tag -->
<allowedAttributes>src,alt,title,border,class,style,align,id,name,onclick,usemap</allowedAttributes>

and \config\tinyMceConfig.config

<validElements>
<![CDATA[+a[id|style|rel|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|
ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],-strong/-b[class|style],-em/-i[class|style],
-strike[class|style],-u[class|style],#p[id|style|dir|class|align],-ol[class|reversed|start|style|type],-ul[class|style],-li[class|style],br[class],
img[id|dir|lang|longdesc|usemap|style|class|src|onmouseover|onmouseout|border|alt=|title|hspace|vspace|width|height|align|umbracoorgwidth|umbracoorgheight|onresize|onresizestart|onresizeend|rel],
-sub[style|class],-sup[style|class],-blockquote[dir|style|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|style|dir|id|lang|bgcolor|background|bordercolor],
-tr[id|lang|dir|class|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor],tbody[id|class],
thead[id|class],tfoot[id|class],#td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor|scope],
-th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|scope],caption[id|lang|dir|class|style],-div[id|dir|class|align|style],
-span[class|align|style],-pre[class|align|style],address[class|align|style],-h1[id|dir|class|align],-h2[id|dir|class|align],
-h3[id|dir|class|align],-h4[id|dir|class|align],-h5[id|dir|class|align],-h6[id|style|dir|class|align],hr[class|style],
dd[id|class|title|style|dir|lang],dl[id|class|title|style|dir|lang],dt[id|class|title|style|dir|lang],object[class|id|width|height|codebase|*],
param[name|value|_value|class],embed[type|width|height|src|class|*],map[name|class],area[shape|coords|href|alt|target|class],bdo[class],button[class],iframe[*],code[*]]]>
  </validElements>

Then I modified the .js that is in charge of rendering html that will be added to tinymce editor:

\umbraco_client\tinymce3\plugins\umbracoimg\js\image.js

ed.execCommand('mceInsertContent', false, '<div id="__dimps_width" class="img-with-text"><img id="__mce_tmp" /><p id="__dimps_desc">description</p></div>', { skip_undo: 1 });
ed.dom.setAttribs('__mce_tmp', args);
ed.dom.setAttrib('__mce_tmp', 'id', '');
ed.dom.setAttribs('__dimps_width', {style: 'width: ' + nl.width.value + 'px;'});
...

One important thing: everything is cached and bundled, so to make sure your changes was applied remove all files from \app_data\TEMP\ClientDependency\ and use new instance of incognito browser. You probably can disable it somewhere, but I just removed the cache.

There is no magic in Umbraco TinyMCE. Just a bunch of .aspx and .js code. Modify it to your needs.



来源:https://stackoverflow.com/questions/10081096/add-attributes-to-insert-image-dialogue-of-umbraco-rte-or-create-custom-data-typ

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!