Commit 9bf6fc17 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Robert Lyon
Browse files

Bug 1875785: replace target attr in links: wait for the block to load

Whether an external <a> link has target=_blank or not we should open them in external tab/window to differentiate mahara site from external content

check https://bugs.launchpad.net/mahara/+bug/1802205

behatnotneeded

Change-Id: I371a9f63132ae49eedd7543b682fe80602130117
(cherry picked from commit 9f6a3896)
parent 07f27e56
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -1112,7 +1112,19 @@ Number.isInteger = Number.isInteger || function(value) {
 * Replace target=_blank with JS opener for security reasons
 */
jQuery(function($) {
    $("a").each(function() {
    replaceTarget();
    jQuery(window).on('blocksloaded', {}, function() {
        var element = '.grid-stack';
        replaceTarget(element);
    });
});

function replaceTarget(element) {
    var selector = 'a';
    if (element) {
        selector = element + ' ' + selector;
    }
    $(selector).each(function() {
        var url = $(this).attr('href');
        if (typeof url !== typeof undefined && url !== false) {
            if ($(this).attr('target') == '_blank' || (url.match("^http") && !url.match(config.wwwroot) && $(this).attr('target') != '_self')) {
@@ -1130,7 +1142,7 @@ jQuery(function($) {
            }
        }
    });
});
}

/**
 * Custom handling for the navigation accessibility