|
1052 | 1052 | } |
1053 | 1053 | this.$scopes.empty() |
1054 | 1054 | this.$scopes.html(this.buildLink(data.id, data.link)) |
| 1055 | + this.$window.trigger('update') |
1055 | 1056 | } |
1056 | 1057 | }, options || {}), $.extend({ |
1057 | 1058 | $scopes: $(), |
|
1064 | 1065 | $.scopesWindow = new ($.extend(scopesWindow, $.scopesWindow ? $.scopesWindow : {})); |
1065 | 1066 | })(window, document, jQuery, jQuery.window); |
1066 | 1067 |
|
| 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("&", "&").replace("<", "<").replace(">", ">"); |
| 1155 | + } |
| 1156 | + }, context || {})); |
| 1157 | + } |
| 1158 | + } |
| 1159 | + $.navigateWindow = new ($.extend(navigateWindow, $.navigateWindow ? $.navigateWindow : {})); |
| 1160 | +})(window, document, jQuery, jQuery.window); |
| 1161 | + |
1067 | 1162 | function init_scopes() { |
1068 | 1163 | $.scopesWindow.init(); |
1069 | 1164 | $("#content").scroll(scope_on_scroll); |
@@ -1512,132 +1607,12 @@ function toggle_annotations() { |
1512 | 1607 | * Initialize defaults for list.jsp |
1513 | 1608 | */ |
1514 | 1609 | 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; |
1520 | 1610 | 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 += " "; |
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("&", "&").replace("<", "<").replace(">", ">"); |
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 | + }) |
1641 | 1616 | } |
1642 | 1617 |
|
1643 | 1618 | /** |
|
0 commit comments