Skip to content
Snippets Groups Projects
Commit 8b90de19 authored by srosse's avatar srosse
Browse files

OO-825: refactor the method which change the target of wiki content jQuery pure

parent 1635707e
No related branches found
No related tags found
No related merge requests found
...@@ -10,22 +10,20 @@ if (clientPC.indexOf('opera') != -1) { ...@@ -10,22 +10,20 @@ if (clientPC.indexOf('opera') != -1) {
} }
function changeAnchorTargets(id) { function changeAnchorTargets(id) {
var div = document.getElementById(id); jQuery('a', jQuery('#' + id)).each(function(index, el) {
var anchors = div.getElementsByTagName('a'); var anchor = jQuery(el);
for (var i=0; i < anchors.length; i++){
var anchor = jQuery(anchors[i]);
var openInNewWindow = false; var openInNewWindow = false;
//set interwiki and externallink link to open in new window //set interwiki and externallink link to open in new window
if (anchor.attr("class")) { if (anchor.hasClass("externallink")) {
if (anchor.attr("class") == "externallink") { if(anchor.attr("href").indexOf("mailto:") != -1) {
if(anchor.attr("href").indexOf("mailto:") != -1) { anchor.addClass("b_link_mailto");
anchor.attr("class", "b_link_mailto"); openInNewWindow = false;
openInNewWindow = false; } else {
} else { openInNewWindow = true;
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 //open media links in new window, but only if file exists
if (anchor.attr("title")) { if (anchor.attr("title")) {
...@@ -36,16 +34,18 @@ function changeAnchorTargets(id) { ...@@ -36,16 +34,18 @@ function changeAnchorTargets(id) {
if (href.indexOf(":1/") != -1) { if (href.indexOf(":1/") != -1) {
var pre = href.substr(0, href.indexOf(":1/")); var pre = href.substr(0, href.indexOf(":1/"));
var post = href.substr(href.indexOf(":1/")+3, href.length); 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 } 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.substr(0, href.indexOf("Edit:topic"));
href = href+"Upload"; href = href+"Upload";
anchor.setAttribute("href", href); anchor.attr("href", href);
} }
} }
if (openInNewWindow) anchor.target = "_blank"; if (openInNewWindow) {
} anchor.attr('target',"_blank");
}
});
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment