Skip to content

Instantly share code, notes, and snippets.

@Sharifur
Created March 20, 2023 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sharifur/9eb95a3ae0c3848fc3a7ca2c658461ba to your computer and use it in GitHub Desktop.
Save Sharifur/9eb95a3ae0c3848fc3a7ca2c658461ba to your computer and use it in GitHub Desktop.
//js function to change iframe markup into a shortcode
function iFrameFilterInSummernote(contents){
let rawContents = contents;
let matches = rawContents.match(/<iframe(.+)<\/iframe>/);
let ifamemarkup = Array.isArray(matches) ? matches[0] : '';
let srcMatches = ifamemarkup.match(/src="(.*?)"/);
let ifameSrc = Array.isArray(srcMatches) ? srcMatches[0] : '';
return rawContents.replace(/<iframe(.+)<\/iframe>/, '{iframe} {vsrc}="'+ifameSrc.replace('src="','')+'{/iframe}');
}
//php to render shotcode into iframe for frontend
function iFrameFilterInSummernoteAndRender($content){
return str_replace(['{iframe}','{vsrc}','{/iframe}'],['<iframe','src',' frameborder="0" height="360" width="640"></iframe>'],$content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment