Commit 769c7221 by zubiar-arbi

dont update iframe src attribute if it is empty

STUD-1136
parent 9075dcef
define( define(
[ [
"jquery", "underscore", "jquery", "underscore",
"js/utils/handle_iframe_binding", "js/utils/handle_iframe_binding"
], ],
function ($, _, IframeBinding) { function ($, _, IframeBinding) {
...@@ -33,5 +33,14 @@ function ($, _, IframeBinding) { ...@@ -33,5 +33,14 @@ function ($, _, IframeBinding) {
'<iframe src="http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent&amp;allowFullScreen=false" frameborder="0" height="350" width="618"></iframe>' + '<iframe src="http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent&amp;allowFullScreen=false" frameborder="0" height="350" width="618"></iframe>' +
'<embed wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/embed/NHd27UvY-lw" height="315" width="560">'); '<embed wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/embed/NHd27UvY-lw" height="315" width="560">');
}); });
it("does not modify src url of DOM iframe if it is empty", function () {
iframe_html = '<iframe width="618" height="350" src="" frameborder="0" allowfullscreen></iframe>';
doc.body.innerHTML = iframe_html;
IframeBinding.iframeBinding(doc);
expect($(doc).find("iframe")[0].src).toEqual("");
});
}); });
}); });
define(["jquery"], function($) { define(["jquery"], function($) {
var iframeBinding = function (e) { var iframeBinding = function (e) {
var target_element = null; var target_element = null;
if (typeof(e) == "undefined"){ if (typeof(e) === "undefined") {
target_element = $("iframe, embed"); target_element = $("iframe, embed");
} else { } else {
if (typeof(e.nodeName) != 'undefined'){ if (typeof(e.nodeName) !== 'undefined') {
target_element = $(e).find("iframe, embed"); target_element = $(e).find("iframe, embed");
} else{ } else {
target_element = e.$("iframe, embed"); target_element = e.$("iframe, embed");
} }
} }
...@@ -14,21 +14,27 @@ define(["jquery"], function($) { ...@@ -14,21 +14,27 @@ define(["jquery"], function($) {
}; };
var modifyTagContent = function (target_element) { var modifyTagContent = function (target_element) {
target_element.each(function(){ target_element.each(function() {
if ($(this).prop('tagName') == 'IFRAME'){ if ($(this).prop('tagName') === 'IFRAME') {
var ifr_source = $(this).attr('src'); var ifr_source = $(this).attr('src');
var wmode = "wmode=transparent";
if(ifr_source.indexOf('?') != -1) { // Modify iframe src only if it is not empty
var getQString = ifr_source.split('?'); if (ifr_source) {
if (getQString[1].search('wmode=transparent') == -1){ var wmode = "wmode=transparent";
var oldString = getQString[1]; if (ifr_source.indexOf('?') !== -1) {
var newString = getQString[0]; var getQString = ifr_source.split('?');
$(this).attr('src',newString+'?'+wmode+'&'+oldString); if (getQString[1].search('wmode=transparent') === -1) {
var oldString = getQString[1];
var newString = getQString[0];
$(this).attr('src', newString + '?' + wmode + '&' + oldString);
}
}
else {
$(this).attr('src', ifr_source + '?' + wmode);
} }
} }
else $(this).attr('src',ifr_source+'?'+wmode);
} }
else{ else {
$(this).attr('wmode', 'transparent'); $(this).attr('wmode', 'transparent');
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment