Skip to content

Commit 944079f

Browse files
committed
Tweaks to work with Mantis v2
1 parent d0eaed7 commit 944079f

File tree

4 files changed

+194
-181
lines changed

4 files changed

+194
-181
lines changed

IssuesDiff.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function register() {
1818

1919
$this->version = "1.0";
2020
$this->requires = array(
21-
"MantisCore" => "1.2.11",
21+
"MantisCore" => "2.5.0",
2222
);
2323

2424
$this->author = "Samir Aguiar";
@@ -28,25 +28,17 @@ public function register() {
2828

2929
public function hooks() {
3030
return array(
31-
"EVENT_MENU_ISSUE" => "get_menu_option",
3231
"EVENT_VIEW_BUG_DETAILS" => "inject_script"
3332
);
3433
}
3534

3635
public function inject_script() {
37-
$plugin_basename = plugin_get_current();
38-
$script_path = plugin_file_path('js/add_diff_view_link.js', $plugin_basename);
39-
$script_contents = file_get_contents($script_path);
40-
4136
$menu_title = plugin_lang_get("menu_title");
4237
$diff_page_url = plugin_page("bug_revision_diff_page", true);
4338

44-
$script = "(function() {" .
45-
"var linkText = '$menu_title';" .
46-
"var diffPageUrl = '$diff_page_url';" .
47-
$script_contents .
48-
"})();";
39+
echo '<a id="view-diff-anchor" data-base-href="'
40+
. $diff_page_url . '" style="display: none">' . $menu_title . '</a>';
4941

50-
echo "<script> $script </script>";
42+
echo '<script src="' . plugin_file('js/add_diff_view_link.js') . '"></script>';
5143
}
5244
}

files/css/diff_style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ form.diff-form input.diff-form-submit {
88
}
99

1010
.issue-diff-area {
11-
background-color: #E8E8E8;
11+
background-color: #F9F9F9;
1212
}
1313

1414
form.diff-form .issue-diff-separator {

files/js/add_diff_view_link.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,64 @@
1-
function appendAnchor(cellElement, bug_view_link) {
2-
var anchor = document.createElement("A");
3-
anchor.text = linkText;
4-
anchor.href = bug_view_link;
1+
(function() {
2+
var baseAnchor = document.getElementById("view-diff-anchor");
3+
var diffPageUrl = baseAnchor.getAttribute('data-base-href');
54

6-
cellElement.appendChild(getSplitter());
7-
cellElement.appendChild(anchor);
8-
}
5+
baseAnchor.removeAttribute('id');
6+
baseAnchor.removeAttribute('data-base-href');
97

10-
function getSplitter() {
11-
var span = document.createElement("SPAN");
12-
span.innerHTML = " | "
8+
function appendAnchor(cellElement, bug_view_link) {
9+
var anchor = $.clone(baseAnchor);
10+
anchor.href = bug_view_link;
11+
anchor.style.display = 'inline';
1312

14-
return span;
15-
}
13+
cellElement.appendChild(getSplitter());
14+
cellElement.appendChild(anchor);
15+
}
1616

17-
function getQueryString(url) {
18-
var questionMarkIndex = url.indexOf('?');
17+
function getSplitter() {
18+
var span = document.createElement("SPAN");
19+
span.innerHTML = " | "
1920

20-
if (questionMarkIndex === -1) return '';
21+
return span;
22+
}
2123

22-
var newUrl = url.slice(questionMarkIndex + 1).replace("#r", "&last=");
24+
function getQueryString(url) {
25+
var questionMarkIndex = url.indexOf('?');
2326

24-
return '&' + newUrl;
25-
}
27+
if (questionMarkIndex === -1) return '';
2628

27-
function addDiffViewLink() {
28-
var issueHistory = document.getElementById("history_open");
29+
var newUrl = url.slice(questionMarkIndex + 1).replace("#r", "&last=");
2930

30-
var rows = issueHistory.getElementsByTagName("tr");
31+
return '&' + newUrl;
32+
}
3133

32-
for (var i = 0; i < rows.length; i++) {
33-
var changeCell = rows[i].lastElementChild;
34+
function addDiffViewLink() {
35+
var issueHistory = $("#history tbody");
36+
var rows = issueHistory[0].getElementsByTagName("tr");
3437

35-
if (!changeCell) continue;
38+
for (var i = 0; i < rows.length; i++) {
39+
var changeCell = rows[i].lastElementChild;
3640

37-
var cellAnchor = changeCell.getElementsByTagName("a");
41+
if (!changeCell) continue;
3842

39-
if (!cellAnchor.length) continue;
43+
var cellAnchor = changeCell.getElementsByTagName("a");
4044

41-
var revisionUrl = cellAnchor[0].getAttribute("href");
45+
if (!cellAnchor.length) continue;
4246

43-
if (revisionUrl.indexOf("bug_revision_view_page") === -1) {
44-
continue;
45-
}
47+
var revisionUrl = cellAnchor[0].getAttribute("href");
4648

47-
var queryString = getQueryString(revisionUrl);
49+
if (revisionUrl.indexOf("bug_revision_view_page") === -1) {
50+
continue;
51+
}
4852

49-
appendAnchor(changeCell, diffPageUrl + queryString);
53+
var queryString = getQueryString(revisionUrl);
54+
55+
appendAnchor(changeCell, diffPageUrl + queryString);
56+
}
5057
}
51-
}
5258

53-
if (window.addEventListener){
54-
window.addEventListener('load', addDiffViewLink)
55-
} else{
56-
window.attachEvent('onload', addDiffViewLink)
57-
}
59+
if (window.addEventListener){
60+
window.addEventListener('load', addDiffViewLink)
61+
} else{
62+
window.attachEvent('onload', addDiffViewLink)
63+
}
64+
})();

0 commit comments

Comments
 (0)