Skip to content

Commit 23cf270

Browse files
authored
Merge pull request #1659 from tulinkry/fixed-header
fixed header instead of javascript content height resize action
2 parents 1394488 + f6e3b71 commit 23cf270

File tree

7 files changed

+196
-80
lines changed

7 files changed

+196
-80
lines changed

src/org/opensolaris/opengrok/web/Scripts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ public String toHtml() {
125125
SCRIPTS.put("jquery-tablesorter", new FileScript("js/jquery-tablesorter-2.26.6.min.js", 12));
126126
SCRIPTS.put("tablesorter-parsers", new FileScript("js/tablesorter-parsers-0.0.1.js", 13));
127127
SCRIPTS.put("searchable-option-list", new FileScript("js/searchable-option-list-2.0.3.min.js", 14));
128-
SCRIPTS.put("utils", new FileScript("js/utils-0.0.11.js", 15));
128+
SCRIPTS.put("utils", new FileScript("js/utils-0.0.12.js", 15));
129129
SCRIPTS.put("repos", new FileScript("js/repos-0.0.1.js", 20));
130-
SCRIPTS.put("diff", new FileScript("js/diff-0.0.1.js", 20));
130+
SCRIPTS.put("diff", new FileScript("js/diff-0.0.2.js", 20));
131131
}
132132

133133
/**

web/default/style.css

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ body {
33
background-color: #ffffff;
44
color: black;
55
font-family: sans-serif;
6-
margin: 1ex 1ex 0 1ex;
6+
margin: 0;
77
}
88

99
a {
@@ -243,6 +243,18 @@ label {
243243
/* ############### start of header ############## */
244244
#whole_header { }
245245

246+
html.xref #whole_header,
247+
html.history #whole_header,
248+
html.more #whole_header,
249+
html.diff #whole_header {
250+
position: fixed;
251+
top: 0;
252+
background: #ddd;
253+
border-bottom: 5px solid #ddd;
254+
height: 85px;
255+
width: 100%;
256+
}
257+
246258
/* *** banner/deco above navbar *** */
247259
#header { }
248260

@@ -270,6 +282,9 @@ label {
270282
font-family: monospace; /* ala <kbd> */
271283
clear: left;
272284
margin-bottom: 1ex;
285+
margin-left: 1ex;
286+
margin-top: 1ex;
287+
margin-right: 1ex;
273288
}
274289

275290
#Masthead tt { /* slashes in the xref: line */
@@ -430,14 +445,13 @@ input.submit { /* start search button , clear button */
430445

431446
/* ############### end of header ############## */
432447

433-
434448
/* ############### start of content ############## */
435-
#content {
436-
position: fixed;
437-
left: 0;
438-
right: 0;
439-
overflow: auto;
440-
padding: 0 1ex 1ex 1ex; /* should be the same as body's margin */
449+
450+
html.xref #content,
451+
html.diff #content,
452+
html.more #content,
453+
html.history #content{
454+
margin-top: 90px;
441455
}
442456

443457
/* *** help page *** */
@@ -821,7 +835,7 @@ a.scope { /* scope */ color: steelblue; font-weight: bol
821835
}
822836

823837
.window {
824-
position: absolute;
838+
position: fixed;
825839
font-size: 12px;
826840
font-family: monospace;
827841
overflow: auto;

web/httpheader.jspf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ org.opensolaris.opengrok.web.PageConfig"
4747
%><?xml version="1.0" encoding="UTF-8"?>
4848
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4949
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
50-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
50+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
51+
class="<%= request.getServletPath().length() > 0 ? request.getServletPath().substring(1) : "" %>">
5152
<head>
5253
<meta name="robots" content="noindex,nofollow" />
5354
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

web/js/diff-0.0.1.js renamed to web/js/diff-0.0.2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@
152152
* animationDuration: // duration of toggling the jumper window
153153
* }
154154
*/
155-
$parent: $("#difftable"),
155+
$parent: $("#content"),
156156
$content: $("#content"), // first scrollable div
157157
chunkSelector: ".chunk",
158158
addSelector: ".a",
@@ -186,8 +186,8 @@
186186
if (this.options.scrollTop) {
187187
this.options.scrollTop($el)
188188
} else {
189-
$("#content").stop().animate({
190-
scrollTop: $el.offset().top - this.options.$parent.offset().top
189+
$('html, body').stop().animate({
190+
scrollTop: $el.position().top - this.options.$parent.offset().top
191191
}, 500);
192192
}
193193
return this;

web/js/utils-0.0.11.js renamed to web/js/utils-0.0.12.js

Lines changed: 110 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,100 @@
163163
$.spaces = new ($.extend(spaces, $.spaces ? $.spaces : {}));
164164
})(window, window.jQuery);
165165

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+
166260
(function(window, $) {
167261
var hash = function () {
168262
var inner = {
@@ -192,12 +286,12 @@
192286
if(l.length == 2) {
193287
window.location.hash = "#" + Math.min(l[0], val) + "-" + Math.max(val, l[1])
194288
} 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)
196290
}
197291
return false
198292
}
199293
return true
200-
})
294+
})
201295
},
202296

203297
getHashParts: function (hash) {
@@ -245,14 +339,13 @@
245339
// not a case of line highlighting
246340
return
247341
}
248-
249342
for ( var i = 0; i < lines.length; i ++ ) {
250343
// color
251344
var slc = inner.format(inner.options.linkSelectorTemplate, { "parent": inner.options.parent,
252345
"n": lines[i] } );
253346
var el = $(slc).addClass(inner.options.highlightedClass)
254347
inner.highlighted.push(el)
255-
}
348+
}
256349
},
257350
format: function(format) {
258351
var args = Array.prototype.slice.call(arguments, 1);
@@ -270,7 +363,6 @@
270363
scroll: function (){
271364
if(!inner.options.autoScroll)
272365
return
273-
274366
var lines = inner.getLinesParts(window.location.hash);
275367
if (lines.length > 0) {
276368
var line = lines[0]; // first line
@@ -281,7 +373,7 @@
281373
if ($line.length > 0) {
282374
// if there is such element identified with the line number
283375
// we can scroll to it
284-
$("#content").animate({
376+
$('html, body').animate({
285377
scrollTop: $(inner.format(inner.options.linkSelectorTemplate, {
286378
parent: inner.options.parent,
287379
n: line
@@ -464,12 +556,12 @@
464556
var bw = {
465557
height: $(browserWindow).outerHeight(true),
466558
width: $(browserWindow).outerWidth(true),
467-
yOffset: browserWindow.pageYOffset,
468-
xOffset: browserWindow.pageXOffset
559+
yOffset: 0,
560+
xOffset: 0
469561
}
470562
position.top -= Math.max(0, position.top + w.height - bw.yOffset - bw.height + 20)
471563
position.left -= Math.max(0, position.left + w.width - bw.xOffset - bw.width + 20)
472-
return position
564+
return position;
473565
}
474566

475567
this.determinePosition = function () {
@@ -607,8 +699,8 @@
607699
this.addCallback('load', function ($window) {
608700
var that = this
609701
$(document).mousemove(function (e) {
610-
that.clientX = e.pageX;
611-
that.clientY = e.pageY;
702+
that.clientX = e.clientX;
703+
that.clientY = e.clientY;
612704
})
613705
$(document).keyup(function (e) {
614706
var key = e.keyCode
@@ -876,9 +968,10 @@
876968
},
877969
scrollTop: function ($el) {
878970
if (this.options.scrollTop) {
971+
879972
this.options.scrollTop($el)
880973
} else {
881-
$("#content").stop().animate({
974+
$('html, body').stop().animate({
882975
scrollTop: $el.offset().top - $("#src").offset().top
883976
}, 500);
884977
}
@@ -1035,7 +1128,7 @@
10351128
.append(this.$scopes = $("<div>"))
10361129
},
10371130
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')
10391132

10401133
// override the hide and show to throw an event and run
10411134
// scope_on_scroll() for update
@@ -1157,7 +1250,7 @@
11571250
return $('<a>').attr('href', '#' + href).attr('title', this.escapeHtml(name)).addClass(c).html(this.escapeHtml(name)).click(lnshow)
11581251
},
11591252
getTopOffset: function () {
1160-
return parseFloat($("#content").css('top'))
1253+
return $("#content").offset().top
11611254
},
11621255
updatePosition: function ($w) {
11631256
if (!$w.is(':visible')) {
@@ -1175,7 +1268,7 @@
11751268
if ($.scopesWindow &&
11761269
$.scopesWindow.initialized &&
11771270
$.scopesWindow.is(':visible')) {
1178-
a.top = $.scopesWindow.offset().top + $.scopesWindow.outerHeight() + 20;
1271+
a.top = $.scopesWindow.position().top + $.scopesWindow.outerHeight() + 20;
11791272
}
11801273
a.height = Math.min(parseFloat($w.css('max-height')) || 480, $(browserWindow).outerHeight() - a.top - ($w.outerHeight(true) - $w.height()) - 20);
11811274

@@ -1199,7 +1292,7 @@
11991292

12001293
function init_scopes() {
12011294
$.scopesWindow.init();
1202-
$("#content").scroll(scope_on_scroll);
1295+
$(window).scroll(scope_on_scroll);
12031296
}
12041297

12051298
function init_results_autohide() {
@@ -1473,17 +1566,6 @@ $(document).ready(function () {
14731566
$('a.result-annotate').tooltip()
14741567
});
14751568

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-
14871569
/**
14881570
* Get a parameter value from the URL.
14891571
*
@@ -1578,22 +1660,9 @@ function domReadyMast() {
15781660
$("#toggle-annotate-by-javascript").css('display', 'inline');
15791661
$("#toggle-annotate").hide()
15801662
}
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);
15861663
}
15871664

15881665
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-
});
15971666
}
15981667

15991668
function domReadyMenu() {
@@ -1841,8 +1910,7 @@ function scope_on_scroll() {
18411910
scope_timeout = null
18421911
}
18431912
scope_timeout = setTimeout(function () {
1844-
var cnt = document.getElementById("content");
1845-
var y = cnt.getBoundingClientRect().top + 2;
1913+
var y = $('#whole_header').outerHeight() + 2;
18461914
var c = document.elementFromPoint(15, y + 1);
18471915

18481916
if ($(c).is('.l, .hl')) {

0 commit comments

Comments
 (0)