From 8b90de19ec6ec29a5098139b47d5c802ae7a1e08 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Mon, 21 Oct 2013 17:18:07 +0200 Subject: [PATCH] OO-825: refactor the method which change the target of wiki content jQuery pure --- src/main/webapp/static/js/openolat/wiki.js | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/webapp/static/js/openolat/wiki.js b/src/main/webapp/static/js/openolat/wiki.js index ba0cccfcd3e..2753a5bdb6c 100644 --- a/src/main/webapp/static/js/openolat/wiki.js +++ b/src/main/webapp/static/js/openolat/wiki.js @@ -10,22 +10,20 @@ if (clientPC.indexOf('opera') != -1) { } function changeAnchorTargets(id) { - var div = document.getElementById(id); - var anchors = div.getElementsByTagName('a'); - for (var i=0; i < anchors.length; i++){ - var anchor = jQuery(anchors[i]); + jQuery('a', jQuery('#' + id)).each(function(index, el) { + var anchor = jQuery(el); var openInNewWindow = false; //set interwiki and externallink link to open in new window - if (anchor.attr("class")) { - if (anchor.attr("class") == "externallink") { - if(anchor.attr("href").indexOf("mailto:") != -1) { - anchor.attr("class", "b_link_mailto"); - openInNewWindow = false; - } else { - openInNewWindow = true; - } + if (anchor.hasClass("externallink")) { + if(anchor.attr("href").indexOf("mailto:") != -1) { + anchor.addClass("b_link_mailto"); + openInNewWindow = false; + } else { + openInNewWindow = true; } - if (anchor.attr("class") == "interwiki") openInNewWindow = true; + } + if (anchor.hasClass("interwiki")) { + openInNewWindow = true; } //open media links in new window, but only if file exists if (anchor.attr("title")) { @@ -36,16 +34,18 @@ function changeAnchorTargets(id) { if (href.indexOf(":1/") != -1) { var pre = href.substr(0, href.indexOf(":1/")); var post = href.substr(href.indexOf(":1/")+3, href.length); - anchor.setAttribute("href", pre+":0/"+post); + anchor.attr("href", pre+":0/"+post); } } else if (anchor.attr("class") == "edit" && anchor.attr("title").indexOf("Media:") != -1) { //media file not found href = href.substr(0, href.indexOf("Edit:topic")); href = href+"Upload"; - anchor.setAttribute("href", href); + anchor.attr("href", href); } } - if (openInNewWindow) anchor.target = "_blank"; - } + if (openInNewWindow) { + anchor.attr('target',"_blank"); + } + }); } -- GitLab