Skip to content

Commit 91b0430

Browse files
committed
Several changes, merges from master:
- Maybe not recommend SHA1 for password hashes anymore - Always set cursor to pointer when we have .nav > li > a Solves issue #5867. Should be harmless? - Don't scroll to top in Wt 3 when path changes, minified scroll history - WFileUpload.C: we don't need id() in that variable fixes issue where change of object name caused syntax error - fix for when WTextEdit is bound as child of another widget in WTemplate - New scrolling behaviour on back/forward button presses - avoids flicker by updating scroll position only when server response arrives - for new hash updates (anchor click), the page will scroll to the top
1 parent e16abad commit 91b0430

File tree

10 files changed

+207
-136
lines changed

10 files changed

+207
-136
lines changed

resources/themes/bootstrap/2/wt.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@
125125
/*
126126
* Show pointer even if anchor has no href
127127
*/
128-
.navbar .nav > li > a,
129-
.tabwidget .nav-tabs > li > a {
128+
.nav > li > a {
130129
cursor: pointer;
131130
}
132131
/*

resources/themes/bootstrap/2/wt.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@
118118
/*
119119
* Show pointer even if anchor has no href
120120
*/
121-
.navbar .nav > li > a,
122-
.tabwidget .nav-tabs > li > a {
121+
.nav > li > a {
123122
cursor: pointer;
124123
}
125124

resources/themes/bootstrap/3/wt.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@
119119
* Show pointer even if anchor has no href
120120
*/
121121

122-
.navbar .nav > li > a,
123-
.tabwidget .nav-tabs > li > a {
122+
.nav > li > a {
124123
cursor: pointer;
125124
}
126125

resources/themes/bootstrap/3/wt.less

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
/*
108108
* Show pointer even if anchor has no href
109109
*/
110-
.navbar .nav > li > a,
111-
.tabwidget .nav-tabs > li > a {
110+
.nav > li > a {
112111
cursor: pointer;
113112
}
114113

src/Wt/Auth/HashFunction

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public:
9898
* This hash function is only available if %Wt was compiled with
9999
* OpenSSL support.
100100
*
101-
* This hashing function is useful for creating token hashes, and is
102-
* also considered adequate for password hashes.
101+
* This hash function is useful for creating token hashes, but
102+
* should not be used for password hashes.
103103
*
104104
* \ingroup auth
105105
*/

src/Wt/WFileUpload.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,9 @@ DomElement *WFileUpload::createDomElement(WApplication *app)
460460

461461
form->addChild(input);
462462

463-
doJavaScript("var a" + id() + "=" + jsRef() + ".action;"
463+
doJavaScript("var a =" + jsRef() + ".action;"
464464
"var f = function(event) {"
465-
"""if (a" + id() + ".indexOf(event.origin) === 0) {"
465+
"""if (a.indexOf(event.origin) === 0) {"
466466
"" "var data = JSON.parse(event.data);"
467467
"" "if (data.type === 'upload') {"
468468
"" "if (data.fu == '" + id() + "')"

src/Wt/WWebWidget.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,11 @@ DomElement *WWebWidget::createDomElement(WApplication *app)
22292229

22302230
bool WWebWidget::domCanBeSaved() const
22312231
{
2232-
return true;
2232+
bool canBeSaved = true;
2233+
iterateChildren([&canBeSaved](WWidget *child){
2234+
canBeSaved = canBeSaved && child->webWidget()->domCanBeSaved();
2235+
});
2236+
return canBeSaved;
22332237
}
22342238

22352239
bool WWebWidget::isRendered() const

src/web/WebSession.C

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,8 +2939,7 @@ void WebSession::notifySignal(const WEvent& e)
29392939
const std::string *hashE = request.getParameter(se + "_");
29402940
if (hashE) {
29412941
changeInternalPath(*hashE, handler.response());
2942-
app_->doJavaScript(WT_CLASS ".scrollIntoView("
2943-
+ WWebWidget::jsStringLiteral(*hashE) + ");");
2942+
app_->doJavaScript(WT_CLASS ".scrollHistory();");
29442943
} else
29452944
changeInternalPath("", handler.response());
29462945
} else {

src/web/skeleton/Wt.js

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -914,28 +914,50 @@ this.wheelDelta = function(e) {
914914
return delta;
915915
};
916916

917-
this.scrollIntoView = function(id) {
918-
setTimeout(function() {
919-
var hashI = id.indexOf('#');
920-
if (hashI != -1)
921-
id = id.substr(hashI + 1);
922-
923-
var obj = document.getElementById(id);
924-
if (obj) {
925-
/* Locate a suitable ancestor to scroll */
926-
var p;
927-
for (p = obj.parentNode; p != document.body; p = p.parentNode) {
928-
if (p.scrollHeight > p.clientHeight &&
929-
WT.css(p, 'overflow-y') == 'auto') {
930-
var xy = WT.widgetPageCoordinates(obj, p);
931-
p.scrollTop += xy.y;
932-
return;
933-
}
934-
}
917+
this.scrollHistory = function() {
918+
// after any hash change event (forward/backward, or user clicks
919+
// on an achor with internal path), the server calls this function
920+
// to update the scroll position of the main window
921+
try {
922+
if (window.history.state) {
923+
if (typeof window.history.state.pageXOffset !== UNDEFINED) {
924+
// scroll to a historic position where we have been before
925+
//console.log("scrollHistory: " + JSON.stringify(window.history.state));
926+
window.scrollTo(window.history.state.pageXOffset, window.history.state.pageYOffset);
927+
} else {
928+
// we went to a new hash (following an anchor, we assume some equivalence
929+
// with 'new page') that hasn't been scrolled yet.
930+
// Scroll to the top, which may be overriden by scrollIntoView (if the hash
931+
// exists somewhere as an object ID)
932+
//console.log("scrollHistory: new page scroll strategy");
933+
// window.scrollTo(0, 0);
934+
WT.scrollIntoView(window.history.state.state);
935+
}
936+
}
937+
} catch (error) {
938+
console.log(error);
939+
}
940+
}
935941

936-
obj.scrollIntoView(true);
942+
this.scrollIntoView = function(id) {
943+
var hashI = id.indexOf('#');
944+
if (hashI != -1)
945+
id = id.substr(hashI + 1);
946+
947+
var obj = document.getElementById(id);
948+
if (obj) {
949+
/* Locate a suitable ancestor to scroll */
950+
var p;
951+
for (p = obj.parentNode; p != document.body; p = p.parentNode) {
952+
if (p.scrollHeight > p.clientHeight &&
953+
WT.css(p, 'overflow-y') == 'auto') {
954+
var xy = WT.widgetPageCoordinates(obj, p);
955+
p.scrollTop += xy.y;
956+
return;
937957
}
938-
}, 100);
958+
}
959+
obj.scrollIntoView(true);
960+
}
939961
};
940962

941963
function isHighSurrogate(chr) {
@@ -1905,6 +1927,37 @@ function gentleURIEncode(s) {
19051927
}
19061928

19071929
if (html5History) {
1930+
// we need to update the scroll position at the scroll event,
1931+
// because we don't have the chance to update the html5history
1932+
// state anymore at the moment that onPopState() is called.
1933+
// For navigation, when pushState() is called, the scroll
1934+
// history can be updated before the pushState() call.
1935+
function updateScrollHistory() {
1936+
//console.log("updateScrollHistory");
1937+
try {
1938+
var newState = window.history.state;
1939+
if (window.history.state == null) {
1940+
// freshly initiated session, no state present yet
1941+
newState = {};
1942+
newState.state = "";
1943+
newState.title = window.document.title;
1944+
}
1945+
newState.pageXOffset = window.pageXOffset;
1946+
newState.pageYOffset = window.pageYOffset;
1947+
window.history.replaceState(newState, newState.title);
1948+
} catch (error) {
1949+
// shouldn't happen
1950+
console.log(error.toString());
1951+
}
1952+
}
1953+
window.addEventListener('scroll', updateScrollHistory);
1954+
1955+
// the 'auto' scrollRestoration gives too much flicker, since it
1956+
// updates the scroll state before the page is updated
1957+
// Browsers not supporting manual scrollRestoration, the flicker
1958+
// should not be worse than what it was.
1959+
window.history.scrollRestoration = 'manual';
1960+
19081961
this.history = (function()
19091962
{
19101963
var currentState = null, baseUrl = null, ugly = false, cb = null,
@@ -1925,7 +1978,9 @@ if (html5History) {
19251978
saveState(initialState);
19261979

19271980
function onPopState(event) {
1928-
var newState = event.state;
1981+
var newState = null;
1982+
if (event.state && event.state.state)
1983+
newState = event.state.state;
19291984

19301985
if (newState == null)
19311986
newState = stateMap[w.location.pathname + w.location.search];
@@ -1945,6 +2000,7 @@ if (html5History) {
19452000
currentState = newState;
19462001
onStateChange(currentState != "" ? currentState : "/");
19472002
}
2003+
//console.log("onPopState: " + JSON.stringify(window.history.state));
19482004
}
19492005

19502006
w.addEventListener("popstate", onPopState, false);
@@ -1965,6 +2021,7 @@ _$_$endif_$_();
19652021
},
19662022

19672023
navigate: function (state, generateEvent) {
2024+
//console.log("navigate: " + state);
19682025
WT.resolveRelativeAnchors();
19692026

19702027
currentState = state;
@@ -2004,7 +2061,18 @@ _$_$endif_$_();
20042061
}
20052062

20062063
try {
2007-
window.history.pushState(state ? state : "", document.title, url);
2064+
var historyState = { };
2065+
historyState.state = state ? state : "";
2066+
// By not setting historyState.page[XY]Offset, we indicate that
2067+
// this state change was made by navigation rather than by
2068+
// the back/forward button
2069+
// keep title for call to replaceState when page offset is updated
2070+
historyState.title = document.title;
2071+
// update scroll position of stack top with the position at the time of leaving the page
2072+
updateScrollHistory();
2073+
//console.log("pushState before: " + JSON.stringify(window.history.state));
2074+
window.history.pushState(historyState, document.title, url);
2075+
//console.log("pushState after: " + JSON.stringify(window.history.state));
20082076
} catch (error) {
20092077
/*
20102078
* In case we are wrong about our baseUrl or base href
@@ -2013,7 +2081,12 @@ _$_$endif_$_();
20132081
console.log(error.toString());
20142082
}
20152083

2016-
WT.scrollIntoView(state);
2084+
// We used to call scrollIntoView here. We modified this to have
2085+
// scrollIntoView called after the server round-trip, so that the
2086+
// new content is certainly visible before we scroll. This avoids
2087+
// flicker. If the rendering result was pre-learned client-side,
2088+
// the page will scroll to the right position only after a server
2089+
// round-trip, which is not ideal.
20172090

20182091
if (generateEvent)
20192092
cb(state);
@@ -2056,8 +2129,6 @@ _$_$endif_$_();
20562129

20572130
w.location.hash = state;
20582131

2059-
WT.scrollIntoView(state);
2060-
20612132
if (generateEvent)
20622133
cb(state);
20632134
},

0 commit comments

Comments
 (0)