|
163 | 163 | $.spaces = new ($.extend(spaces, $.spaces ? $.spaces : {}));
|
164 | 164 | })(window, window.jQuery);
|
165 | 165 |
|
| 166 | +/** |
| 167 | + * Offseting the target anchors by the height of the fixed header. |
| 168 | + * Code taken from http://jsfiddle.net/ianclark001/rkocah23/. |
| 169 | + * |
| 170 | + * If this is not used, clicking on a anchor |
| 171 | + * with a hash target (href="#some-id") will |
| 172 | + * lead to incorrect positioning at the top of the page. |
| 173 | + */ |
| 174 | +(function (document, history, location) { |
| 175 | + var HISTORY_SUPPORT = !!(history && history.pushState); |
| 176 | + |
| 177 | + var anchorScrolls = { |
| 178 | + ANCHOR_REGEX: /^#[^ ]+$/, |
| 179 | + OFFSET_HEIGHT_PX: 90, |
| 180 | + |
| 181 | + /** |
| 182 | + * Establish events, and fix initial scroll position if a hash is provided. |
| 183 | + */ |
| 184 | + init: function () { |
| 185 | + this.scrollToCurrent(); |
| 186 | + $(window).on('hashchange', $.proxy(this, 'scrollToCurrent')); |
| 187 | + $('body').on('click', 'a', $.proxy(this, 'delegateAnchors')); |
| 188 | + }, |
| 189 | + |
| 190 | + /** |
| 191 | + * Return the offset amount to deduct from the normal scroll position. |
| 192 | + * Modify as appropriate to allow for dynamic calculations |
| 193 | + */ |
| 194 | + getFixedOffset: function () { |
| 195 | + return this.OFFSET_HEIGHT_PX; |
| 196 | + }, |
| 197 | + |
| 198 | + /** |
| 199 | + * If the provided href is an anchor which resolves to an element on the |
| 200 | + * page, scroll to it. |
| 201 | + * @param {String} href |
| 202 | + * @return {Boolean} - Was the href an anchor. |
| 203 | + */ |
| 204 | + scrollIfAnchor: function (href, pushToHistory) { |
| 205 | + var match, anchorOffset; |
| 206 | + |
| 207 | + if (!this.ANCHOR_REGEX.test(href)) { |
| 208 | + return false; |
| 209 | + } |
| 210 | + |
| 211 | + match = document.getElementById(href.slice(1)); |
| 212 | + if (!match) { |
| 213 | + /** |
| 214 | + * Match the elements with name="href", take the first match |
| 215 | + */ |
| 216 | + match = document.getElementsByName(href.slice(1)); |
| 217 | + match = match.length > 0 ? match[0] : null; |
| 218 | + } |
| 219 | + |
| 220 | + if (match) { |
| 221 | + anchorOffset = $(match).offset().top - this.getFixedOffset(); |
| 222 | + $('html, body').animate({scrollTop: anchorOffset}); |
| 223 | + |
| 224 | + location.hash = href; |
| 225 | + |
| 226 | + // Add the state to history as-per normal anchor links |
| 227 | + if (HISTORY_SUPPORT && pushToHistory) { |
| 228 | + history.pushState({}, document.title, location.pathname + href); |
| 229 | + } |
| 230 | + } |
| 231 | + |
| 232 | + return !!match; |
| 233 | + }, |
| 234 | + |
| 235 | + /** |
| 236 | + * Attempt to scroll to the current location's hash. |
| 237 | + */ |
| 238 | + scrollToCurrent: function (e) { |
| 239 | + if (this.scrollIfAnchor(window.location.hash) && e) { |
| 240 | + e.preventDefault(); |
| 241 | + } |
| 242 | + }, |
| 243 | + |
| 244 | + /** |
| 245 | + * If the click event's target was an anchor, fix the scroll position. |
| 246 | + */ |
| 247 | + delegateAnchors: function (e) { |
| 248 | + var elem = e.target; |
| 249 | + |
| 250 | + if (this.scrollIfAnchor(elem.getAttribute('href'), true)) { |
| 251 | + e.preventDefault(); |
| 252 | + } |
| 253 | + } |
| 254 | + }; |
| 255 | + |
| 256 | + |
| 257 | + $(document).ready($.proxy(anchorScrolls, 'init')); |
| 258 | +})(window.document, window.history, window.location); |
| 259 | + |
166 | 260 | (function(window, $) {
|
167 | 261 | var hash = function () {
|
168 | 262 | var inner = {
|
|
192 | 286 | if(l.length == 2) {
|
193 | 287 | window.location.hash = "#" + Math.min(l[0], val) + "-" + Math.max(val, l[1])
|
194 | 288 | } else if ( l.length == 1){
|
195 |
| - window.location.hash = "#" + Math.min(l[0], val) + "-" + Math.max(l[0], val) |
| 289 | + window.location.hash = "#" + Math.min(l[0], val) + "-" + Math.max(l[0], val) |
196 | 290 | }
|
197 | 291 | return false
|
198 | 292 | }
|
199 | 293 | return true
|
200 |
| - }) |
| 294 | + }) |
201 | 295 | },
|
202 | 296 |
|
203 | 297 | getHashParts: function (hash) {
|
|
245 | 339 | // not a case of line highlighting
|
246 | 340 | return
|
247 | 341 | }
|
248 |
| - |
249 | 342 | for ( var i = 0; i < lines.length; i ++ ) {
|
250 | 343 | // color
|
251 | 344 | var slc = inner.format(inner.options.linkSelectorTemplate, { "parent": inner.options.parent,
|
252 | 345 | "n": lines[i] } );
|
253 | 346 | var el = $(slc).addClass(inner.options.highlightedClass)
|
254 | 347 | inner.highlighted.push(el)
|
255 |
| - } |
| 348 | + } |
256 | 349 | },
|
257 | 350 | format: function(format) {
|
258 | 351 | var args = Array.prototype.slice.call(arguments, 1);
|
|
270 | 363 | scroll: function (){
|
271 | 364 | if(!inner.options.autoScroll)
|
272 | 365 | return
|
273 |
| - |
274 | 366 | var lines = inner.getLinesParts(window.location.hash);
|
275 | 367 | if (lines.length > 0) {
|
276 | 368 | var line = lines[0]; // first line
|
|
281 | 373 | if ($line.length > 0) {
|
282 | 374 | // if there is such element identified with the line number
|
283 | 375 | // we can scroll to it
|
284 |
| - $("#content").animate({ |
| 376 | + $('html, body').animate({ |
285 | 377 | scrollTop: $(inner.format(inner.options.linkSelectorTemplate, {
|
286 | 378 | parent: inner.options.parent,
|
287 | 379 | n: line
|
|
464 | 556 | var bw = {
|
465 | 557 | height: $(browserWindow).outerHeight(true),
|
466 | 558 | width: $(browserWindow).outerWidth(true),
|
467 |
| - yOffset: browserWindow.pageYOffset, |
468 |
| - xOffset: browserWindow.pageXOffset |
| 559 | + yOffset: 0, |
| 560 | + xOffset: 0 |
469 | 561 | }
|
470 | 562 | position.top -= Math.max(0, position.top + w.height - bw.yOffset - bw.height + 20)
|
471 | 563 | position.left -= Math.max(0, position.left + w.width - bw.xOffset - bw.width + 20)
|
472 |
| - return position |
| 564 | + return position; |
473 | 565 | }
|
474 | 566 |
|
475 | 567 | this.determinePosition = function () {
|
|
607 | 699 | this.addCallback('load', function ($window) {
|
608 | 700 | var that = this
|
609 | 701 | $(document).mousemove(function (e) {
|
610 |
| - that.clientX = e.pageX; |
611 |
| - that.clientY = e.pageY; |
| 702 | + that.clientX = e.clientX; |
| 703 | + that.clientY = e.clientY; |
612 | 704 | })
|
613 | 705 | $(document).keyup(function (e) {
|
614 | 706 | var key = e.keyCode
|
|
876 | 968 | },
|
877 | 969 | scrollTop: function ($el) {
|
878 | 970 | if (this.options.scrollTop) {
|
| 971 | + |
879 | 972 | this.options.scrollTop($el)
|
880 | 973 | } else {
|
881 |
| - $("#content").stop().animate({ |
| 974 | + $('html, body').stop().animate({ |
882 | 975 | scrollTop: $el.offset().top - $("#src").offset().top
|
883 | 976 | }, 500);
|
884 | 977 | }
|
|
1035 | 1128 | .append(this.$scopes = $("<div>"))
|
1036 | 1129 | },
|
1037 | 1130 | load: function ($window) {
|
1038 |
| - $window.hide().css('top', parseFloat($("#content").css('top').replace('px', '')) + 10 + 'px') |
| 1131 | + $window.hide().css('top', $("#content").offset().top + 10 + 'px') |
1039 | 1132 |
|
1040 | 1133 | // override the hide and show to throw an event and run
|
1041 | 1134 | // scope_on_scroll() for update
|
|
1157 | 1250 | return $('<a>').attr('href', '#' + href).attr('title', this.escapeHtml(name)).addClass(c).html(this.escapeHtml(name)).click(lnshow)
|
1158 | 1251 | },
|
1159 | 1252 | getTopOffset: function () {
|
1160 |
| - return parseFloat($("#content").css('top')) |
| 1253 | + return $("#content").offset().top |
1161 | 1254 | },
|
1162 | 1255 | updatePosition: function ($w) {
|
1163 | 1256 | if (!$w.is(':visible')) {
|
|
1175 | 1268 | if ($.scopesWindow &&
|
1176 | 1269 | $.scopesWindow.initialized &&
|
1177 | 1270 | $.scopesWindow.is(':visible')) {
|
1178 |
| - a.top = $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20; |
| 1271 | + a.top = $.scopesWindow.position().top + $.scopesWindow.outerHeight() + 20; |
1179 | 1272 | }
|
1180 | 1273 | a.height = Math.min(parseFloat($w.css('max-height')) || 480, $(browserWindow).outerHeight() - a.top - ($w.outerHeight(true) - $w.height()) - 20);
|
1181 | 1274 |
|
|
1199 | 1292 |
|
1200 | 1293 | function init_scopes() {
|
1201 | 1294 | $.scopesWindow.init();
|
1202 |
| - $("#content").scroll(scope_on_scroll); |
| 1295 | + $(window).scroll(scope_on_scroll); |
1203 | 1296 | }
|
1204 | 1297 |
|
1205 | 1298 | function init_results_autohide() {
|
@@ -1473,17 +1566,6 @@ $(document).ready(function () {
|
1473 | 1566 | $('a.result-annotate').tooltip()
|
1474 | 1567 | });
|
1475 | 1568 |
|
1476 |
| -/** |
1477 |
| - * Resize the element with the ID 'content' so that it fills the whole browser |
1478 |
| - * window (i.e. the space between the header and the bottom of the window) and |
1479 |
| - * thus get rid off the scrollbar in the page header. |
1480 |
| - */ |
1481 |
| -function resizeContent() { |
1482 |
| - if (document.adjustContent != 0) { |
1483 |
| - $('#content').css('top', $('body').outerHeight(true)).css('bottom', 0); |
1484 |
| - } |
1485 |
| -} |
1486 |
| - |
1487 | 1569 | /**
|
1488 | 1570 | * Get a parameter value from the URL.
|
1489 | 1571 | *
|
@@ -1578,22 +1660,9 @@ function domReadyMast() {
|
1578 | 1660 | $("#toggle-annotate-by-javascript").css('display', 'inline');
|
1579 | 1661 | $("#toggle-annotate").hide()
|
1580 | 1662 | }
|
1581 |
| - |
1582 |
| - // When we move to a version of XHTML that supports the onscroll |
1583 |
| - // attribute in the div element, we should add an onscroll attribute |
1584 |
| - // in the generated XHTML in mast.jsp. For now, set it with jQuery. |
1585 |
| - $("#content").scroll(scope_on_scroll); |
1586 | 1663 | }
|
1587 | 1664 |
|
1588 | 1665 | function pageReadyMast() {
|
1589 |
| - document.adjustContent = 0; |
1590 |
| - if ($('#whole_header').length > 0 && $('#content').length > 0) { |
1591 |
| - document.adjustContent = 1; |
1592 |
| - resizeContent(); |
1593 |
| - } |
1594 |
| - $(window).resize(function () { |
1595 |
| - resizeContent(); |
1596 |
| - }); |
1597 | 1666 | }
|
1598 | 1667 |
|
1599 | 1668 | function domReadyMenu() {
|
@@ -1841,8 +1910,7 @@ function scope_on_scroll() {
|
1841 | 1910 | scope_timeout = null
|
1842 | 1911 | }
|
1843 | 1912 | scope_timeout = setTimeout(function () {
|
1844 |
| - var cnt = document.getElementById("content"); |
1845 |
| - var y = cnt.getBoundingClientRect().top + 2; |
| 1913 | + var y = $('#whole_header').outerHeight() + 2; |
1846 | 1914 | var c = document.elementFromPoint(15, y + 1);
|
1847 | 1915 |
|
1848 | 1916 | if ($(c).is('.l, .hl')) {
|
|
0 commit comments