Skip to content

Commit 7ae7d63

Browse files
authored
Merge pull request #1292 from tulinkry/navigate
converting navigate window into the new window plugin
2 parents 05faff1 + 5540cd9 commit 7ae7d63

File tree

2 files changed

+101
-126
lines changed

2 files changed

+101
-126
lines changed

web/js/utils.js

+100-125
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@
10521052
}
10531053
this.$scopes.empty()
10541054
this.$scopes.html(this.buildLink(data.id, data.link))
1055+
this.$window.trigger('update')
10551056
}
10561057
}, options || {}), $.extend({
10571058
$scopes: $(),
@@ -1064,6 +1065,100 @@
10641065
$.scopesWindow = new ($.extend(scopesWindow, $.scopesWindow ? $.scopesWindow : {}));
10651066
})(window, document, jQuery, jQuery.window);
10661067

1068+
/**
1069+
* Navigate window plugin.
1070+
*
1071+
* @author Kryštof Tulinger
1072+
*/
1073+
(function (browserWindow, document, $, $window) {
1074+
if (!$window || typeof $window.create !== 'function') {
1075+
console.log("The navigateWindow plugin requires $.window plugin")
1076+
return;
1077+
}
1078+
1079+
var navigateWindow = function () {
1080+
this.init = function (options, context) {
1081+
return $.navigateWindow = $window.create($.extend({
1082+
title: 'Navigate Window',
1083+
draggable: false,
1084+
init: function ($window) {
1085+
return $window
1086+
.attr('id', 'navigate_win')
1087+
.addClass('navigate-window')
1088+
.addClass('diff_navigation_style')
1089+
.css({top: '150px', right: '20px'})
1090+
.css('max-width', this.options.max_width)
1091+
.append(this.$content)
1092+
},
1093+
load: function ($window) {
1094+
var that = this
1095+
$window.css('top', this.getTopOffset() + 10 + 'px')
1096+
if ($.scopesWindow && $.scopesWindow.initialized) {
1097+
$.scopesWindow.on('show', function () {
1098+
setTimeout(function () {
1099+
that.updatePosition($window)
1100+
}, 100);
1101+
}).on('hide', function () {
1102+
that.updatePosition($window);
1103+
}).on('update', function () {
1104+
that.updatePosition($window);
1105+
})
1106+
1107+
if ($.scopesWindow.is(':visible')) {
1108+
setTimeout(function () {
1109+
that.updatePosition($window)
1110+
}, 100);
1111+
}
1112+
}
1113+
1114+
$(browserWindow).resize(function () {
1115+
that.updatePosition($window)
1116+
})
1117+
},
1118+
update: function (data) {
1119+
var $ul;
1120+
this.$content.empty()
1121+
for (var i = 0; i < data.length; i++)
1122+
{
1123+
this.$content.append($('<h4>').text(data[i][0]))
1124+
if (data[i][2].length === 0)
1125+
continue;
1126+
this.$content.append($ul = $('<ul>'))
1127+
for (var j = 0; j < data[i][2].length; j ++)
1128+
$ul.append($('<li>').append(this.buildLink(data[i][2][j][1], data[i][2][j][0], data[i][1])));
1129+
}
1130+
1131+
}
1132+
}, options || {
1133+
max_height: 480,
1134+
max_width: 300,
1135+
}), $.extend({
1136+
$content: $('<div>'),
1137+
buildLink: function (href, name, c) {
1138+
return $('<a>').attr('href', '#' + href).attr('title', this.escapeHtml(name)).addClass(c).html(this.escapeHtml(name)).click(lnshow)
1139+
},
1140+
getTopOffset: function () {
1141+
return parseFloat($("#content").css('top'))
1142+
},
1143+
updatePosition: function ($w) {
1144+
var a = {}
1145+
a.top = $.scopesWindow.is(':visible') ? $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20 : this.getTopOffset() + 10,
1146+
a.height = Math.min(this.options.max_height, $(browserWindow).outerHeight() - a.top - ($w.outerHeight(true) - $w.height()) - 20)
1147+
1148+
if (a.height == $w.height() && a.top == this.getTopOffset())
1149+
return $w;
1150+
1151+
return $w.stop().animate(a)
1152+
},
1153+
escapeHtml: function (html) {
1154+
return html.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
1155+
}
1156+
}, context || {}));
1157+
}
1158+
}
1159+
$.navigateWindow = new ($.extend(navigateWindow, $.navigateWindow ? $.navigateWindow : {}));
1160+
})(window, document, jQuery, jQuery.window);
1161+
10671162
function init_scopes() {
10681163
$.scopesWindow.init();
10691164
$("#content").scroll(scope_on_scroll);
@@ -1512,132 +1607,12 @@ function toggle_annotations() {
15121607
* Initialize defaults for list.jsp
15131608
*/
15141609
function pageReadyList() {
1515-
document.sym_div_width = 240;
1516-
document.sym_div_height_max = 480;
1517-
document.sym_div_top = 100;
1518-
document.sym_div_left_margin = 40;
1519-
document.sym_div_height_margin = 40;
15201610
document.highlight_count = 0;
1521-
$(window).resize(function() {
1522-
if (document.sym_div_shown == 1) {
1523-
document.sym_div.style.left = get_sym_div_left() + "px";
1524-
document.sym_div.style.height = get_sym_div_height() + "px";
1525-
}
1526-
});
1527-
}
1528-
1529-
/* ------ Navigation window for definitions ------ */
1530-
/**
1531-
* Create the Navigation toggle link as well as its contents.
1532-
*/
1533-
function get_sym_list_contents() {
1534-
// var contents = "<input id=\"input_highlight\" name=\"input_highlight\"
1535-
// class=\"q\"/>";
1536-
// contents += "&nbsp;&nbsp;";
1537-
// contents += "<b><a href=\"#\" onclick=\"javascript:add_highlight();return
1538-
// false;\" title=\"Add highlight\">Highlight</a></b><br/>";
1539-
var contents =
1540-
"<a href=\"#\" onclick=\"javascript:lsttoggle();\">[Close]</a><br/>"
1541-
if (typeof get_sym_list != 'function') {
1542-
return contents;
1543-
}
1544-
1545-
var symbol_classes = get_sym_list();
1546-
for ( var i = 0; i < symbol_classes.length; i++) {
1547-
if (i > 0) {
1548-
contents += "<br/>";
1549-
}
1550-
var symbol_class = symbol_classes[i];
1551-
var class_name = symbol_class[1];
1552-
var symbols = symbol_class[2];
1553-
contents += "<b>" + symbol_class[0] + "</b><br/>";
1554-
1555-
for (var j = 0; j < symbols.length; j++) {
1556-
var symbol = symbols[j][0];
1557-
var line = symbols[j][1];
1558-
contents += "<a href=\"#" + line + "\" class=\"" + class_name + "\" onclick=\"lnshow(); return true;\">"
1559-
+ escape_html(symbol) + "</a><br/>";
1560-
}
1561-
}
1562-
1563-
return contents;
1564-
}
1565-
1566-
function escape_html(string) {
1567-
return string.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
1568-
}
1569-
1570-
function get_sym_div_left() {
1571-
document.sym_div_left = $(window)
1572-
.width() - (document.sym_div_width + document.sym_div_left_margin);
1573-
return document.sym_div_left;
1574-
}
1575-
1576-
function get_sym_div_height() {
1577-
document.sym_div_height = $(window)
1578-
.height() - document.sym_div_top - document.sym_div_height_margin;
1579-
1580-
if (document.sym_div_height > document.sym_div_height_max) {
1581-
document.sym_div_height = document.sym_div_height_max;
1582-
}
1583-
return document.sym_div_height;
1584-
}
1585-
1586-
function get_sym_div_top() {
1587-
return document.sym_div_top;
1588-
}
1589-
1590-
function get_sym_div_width() {
1591-
return document.sym_div_width;
1592-
}
1593-
1594-
/**
1595-
* Toggle the display of the 'Navigation' window used to highlight definitions.
1596-
*/
1597-
function lsttoggle() {
1598-
if (document.sym_div == null) {
1599-
document.sym_div = document.createElement("div");
1600-
document.sym_div.id = "sym_div";
1601-
1602-
document.sym_div.className = "sym_list_style";
1603-
document.sym_div.style.margin = "0px auto";
1604-
document.sym_div.style.width = get_sym_div_width() + "px";
1605-
document.sym_div.style.height = get_sym_div_height() + "px";
1606-
document.sym_div.style.top = get_sym_div_top() + "px";
1607-
document.sym_div.style.left = get_sym_div_left() + "px";
1608-
1609-
document.sym_div.innerHTML = get_sym_list_contents();
1610-
1611-
document.body.appendChild(document.sym_div);
1612-
document.sym_div_shown = 1;
1613-
1614-
if ($.scopesWindow.initialized) {
1615-
$.scopesWindow.on('show', function () {
1616-
document.sym_div_top = $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20
1617-
document.sym_div.style.height = get_sym_div_height() + "px";
1618-
$(document.sym_div).css('top', $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20);
1619-
}).on('hide', function () {
1620-
document.sym_div_top = 100
1621-
document.sym_div.style.height = get_sym_div_height() + "px";
1622-
$(document.sym_div).css('top', get_sym_div_top());
1623-
})
1624-
if ($.scopesWindow.is(':visible')) {
1625-
document.sym_div_top = $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20
1626-
document.sym_div.style.height = get_sym_div_height() + "px";
1627-
$(document.sym_div).css('top', $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20);
1628-
}
1629-
}
1630-
} else if (document.sym_div_shown == 1) {
1631-
document.sym_div.className = "sym_list_style_hide";
1632-
document.sym_div_shown = 0;
1633-
} else {
1634-
document.sym_div.style.height = get_sym_div_height() + "px";
1635-
document.sym_div.style.width = get_sym_div_width() + "px";
1636-
document.sym_div.style.top = get_sym_div_top() + "px";
1637-
document.sym_div.style.left = get_sym_div_left() + "px";
1638-
document.sym_div.className = "sym_list_style";
1639-
document.sym_div_shown = 1;
1640-
}
1611+
$.navigateWindow.init()
1612+
$.navigateWindow.update(get_sym_list())
1613+
$('#navigate').click(function () {
1614+
$.navigateWindow.toggle()
1615+
})
16411616
}
16421617

16431618
/**

web/mast.jsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ include file="pageheader.jspf"
165165
title="<%= "Show or hide line numbers (might be slower if "
166166
+ "file has more than 10 000 lines)."
167167
%>"><span id="line"></span>Line#</a></li><li><a
168-
href="#" onclick="javascript:lsttoggle();return false;"
168+
href="#" id="navigate"
169169
title="Show or hide symbol list."><%--
170170
--%><span id="defbox"></span>Navigate</a></li><%
171171
}

0 commit comments

Comments
 (0)