diff --git a/cms/static/js/spec/utils/handle_iframe_binding_spec.js b/cms/static/js/spec/utils/handle_iframe_binding_spec.js index 2375d08083..04dd27d183 100644 --- a/cms/static/js/spec/utils/handle_iframe_binding_spec.js +++ b/cms/static/js/spec/utils/handle_iframe_binding_spec.js @@ -12,6 +12,15 @@ function ($, _, IframeBinding) { iframe_html += ''; doc.body.innerHTML = iframe_html; + var verify_no_modification = function (src) { + iframe_html = ''; + doc.body.innerHTML = iframe_html; + + IframeBinding.iframeBinding(doc); + + expect($(doc).find("iframe")[0].src).toEqual(src); + }; + it("modifies src url of DOM iframe and embed elements when iframeBinding function is executed", function () { expect($(doc).find("iframe")[0].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw"); expect($(doc).find("iframe")[1].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw?allowFullScreen=false"); @@ -35,12 +44,11 @@ function ($, _, IframeBinding) { }); it("does not modify src url of DOM iframe if it is empty", function () { - iframe_html = ''; - doc.body.innerHTML = iframe_html; + verify_no_modification(""); + }); - IframeBinding.iframeBinding(doc); - - expect($(doc).find("iframe")[0].src).toEqual(""); + it("does nothing on tinymce iframe", function () { + verify_no_modification("javascript:"); }); }); }); diff --git a/cms/static/js/utils/handle_iframe_binding.js b/cms/static/js/utils/handle_iframe_binding.js index e106d01ae5..cb13272e9a 100644 --- a/cms/static/js/utils/handle_iframe_binding.js +++ b/cms/static/js/utils/handle_iframe_binding.js @@ -29,7 +29,10 @@ define(["jquery"], function($) { $(this).attr('src', newString + '?' + wmode + '&' + oldString); } } - else { + // The TinyMCE editor is hosted in an iframe, and before the iframe is + // removed we execute this code. To avoid throwing an error when setting the + // attr, check that the source doesn't start with the value specified by TinyMCE ('javascript:""'). + else if (ifr_source.lastIndexOf("javascript:", 0) !== 0) { $(this).attr('src', ifr_source + '?' + wmode); } }