
/* ----- dcexternallinkinnewwindow.js ----- */
/* This function open a link in a new window and disable *
 * the standard link behaviour by return false. */
/*************
** This does not work : the source link is not disabled by returning false.
function dcOpenLinkInNewWindow(event) {
    if (!event) var event = window.event; // IE compatibility

    // Check if the event came from a link element.
    if (!(this.tagName && (this.tagName == 'A' || this.tagName == 'a'))) {
        return true;
    }

    window.open(this.href, "");

    // Cancel the standard link behaviour by returning false
    return false;
}
*/

/* This function register the dcOpenLinkInNewWindow function *
 * on click events of external links at page load. */
function dcActivateOpenLinkInNewWindow() {
    if (!W3CDOM) {return false;}

    var externalLinks = cssQuery('span.link-external > a');
    for (var i=0; i < externalLinks.length; i++) {
        var externalLink = externalLinks[i];

        // Set the target for external links.
        externalLinks[i].setAttribute('target', '_blank');

        // Maybe a cleaner way to do this without the target attribute.
        //registerEventListener(externalLink, 'click', dcOpenLinkInNewWindow)
    }

    return true;
}

registerPloneFunction(dcActivateOpenLinkInNewWindow);



