Keep correct size of embed video in TinyMce

戏子无情 提交于 2019-12-13 03:42:32

问题


I want to add embed media in TinyMce with media plugin. When I add an embed video for example with specific size value, when I save the post, the width is not correct. The following HTML is created:

<iframe src="//www.youtube.com/embed/XlpTLDulFe8" width="100" height="100" allowfullscreen="allowfullscreen"></iframe>

But infortunatly, i've the folowing CSS (mdl CSS) that overload my width-size:

iframe {
    display: block;
    width: 100%;
    border: none;
}

I want to use instead a max-width:100%; for keep iFrame width if it isn't superior to 100%

How can I disable the width property for iFrame created by TinyMce ? I've tried to get the HtmlElement for remove property and set another but without success.


回答1:


I found a solution to my problem, this isn't the clever one but this still works well. I apply the css property to the parent <p> of the <iframe> (all iframe are put in <p> tag)

I use the following function

public correctWidthIframe(html: string) {
    let regex = /<p[^>]*>(<iframe*[^>]+(width=*[^height]*height="[0-9]*")[^>]*><\/iframe><\/p>)/g;
    return html.replace(regex, (match, p1, p2) => {
        let dimension = p2.match(/[0-9]+/g);
        let style: string = '<p style="max-width:'+dimension.shift()+'px;">'; // only width is wrong
        return style + p1;
    });
}

I use this function when i want to create and modify message that contain embedVideo.



来源:https://stackoverflow.com/questions/47697833/keep-correct-size-of-embed-video-in-tinymce

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