2
votes

I want to target specific iframes using a class attribute in order to set the width with CSS.

The iframes are google maps embeds like this one:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.uk/?ie=UTF8&amp;t=m&amp;ll=52.8382,-2.327815&amp;spn=4.646012,9.338379&amp;z=6&amp;output=embed"></iframe>

They are copied and pasted into the HTML source editor of tinyMCE. I need to apply a class attribute to the iframe but it is striped out when clicking update on the source editor.

I've tried using valid_elements and extended_valid_elements in the config but neither work for iframe[class].

I'm running version 3.4.3. I downloaded 3.5.7 and the it seems to have the same problem. The behaviour is also exhibited on the demo on the tinyMCE website (http://www.tinymce.com/tryit/full.php) despite the docs for valid_elements stating that the class attribute is supported (http://www.tinymce.com/wiki.php/Configuration:valid_elements).

Here is the full config:

tinyMCE.init({
    // General options
    mode : "specific_textareas",
    editor_selector : "formInputWysiwyg",
    theme : "advanced",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,wordcount,advlist",

    // Theme options
    theme_advanced_buttons1 : "bold,italic,strikethrough,formatselect,styleselect,undo,redo,|,code,|,fullscreen,",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,search,replace,|,bullist,numlist,|,blockquote,nonbreaking,|,charmap,media,|,link,unlink,anchor,image",
    theme_advanced_buttons3 : "",
    theme_advanced_buttons4 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    width : "500",
    height : "600",
    apply_source_formatting : true,
    remove_linebreaks: true,
    theme_advanced_blockformats : "p,blockquote,h1,h2,h3,h4,h5,h6",
    forced_root_block : false,
    plugin_preview_width : "1050",
    plugin_preview_height : "800",
    convert_urls : false,
    extended_valid_elements : "figure,figcaption",

    // Skin options
    skin : "o2k7",
    skin_variant : "silver",

    // Example content CSS (should be your site CSS)
    content_css : "/admin/includes/css/tinymce.css",

    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "lists/template_list.js",
    external_link_list_url : "lists/link_list.js",
    external_image_list_url : "lists/image_list.js",
    media_external_list_url : "lists/media_list.js",

    // Style formats
    style_formats : [
        {title : 'Google Maps', selector : 'iframe', classes : 'google-maps-embed'},
        {title : 'Intro', selector : 'p', classes : 'intro'},
        {title : 'News Image', selector : 'img', classes : 'news-image'}
    ],
});
3
can you create a tinymce fiddle: fiddle.tinymce.com ? - Thariama
Here is a fiddle which shows the issue: fiddle.tinymce.com/nscaab/9 - Yabsley
+1 for the fiddle, i am able to see your problem, but playing around and allowing class attributes to iframes does not seem to work using valid_elements eighter - Thariama

3 Answers

2
votes

In \tinymce\jscripts\tiny_mce\plugins\media\editor_plugin_src.js, I've fixed this issue by removing the "class" from the rootAttributes in line 12 and then minifying using jscompress.com and replaced the contents of the editor_plugin.js file (in the same folder).

Changed:

 var rootAttributes = tinymce.explode('id,name,width,height,style,align,class,hspace,vspace,bgcolor,type')

To:

 var rootAttributes = tinymce.explode('id,name,width,height,style,align,hspace,vspace,bgcolor,type')

It's still an issue in 3.5.8, and have submitted it as a bug.

1
votes

Have you got the 'media' plugin enabled? I'm seeing a similar problem, and I wonder whether the media plugin is interfering with the normal operation of the editor on HTML elements. I tried creating a style_formats option to manipulate the iframe, but without any luck.

0
votes

For those who experience the media plugin conflict, but still need the media plugin, you can set the following option during tinymce initialization to remove the conflict:

media_live_embeds: false

Tested in tinymce v4.6.1