Skip to content

The Unified and Autonomous Development Platform

Avoid scroll page if we are going back/forward

robin shineb15689d585ff
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
index 42692e030a..12e0fd1d28 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/codemirror/codemirror.js
@@ -67,8 +67,12 @@ pmease.commons.codemirror = {
if (viewState) {
if (viewState.cursor)
cm.setCursor(viewState.cursor);
- if (viewState.scroll)
- cm.scrollTo(viewState.scroll.left, viewState.scroll.top);
+ if (viewState.scroll) {
+ // use a timeout to make sure we scroll after possible viewport resize
+ setTimeout(function() {
+ cm.scrollTo(viewState.scroll.left, viewState.scroll.top);
+ }, 10);
+ }
}
CodeMirror.keyMap.default["Ctrl-L"] = "gotoLine";
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
index b2d83780ec..27acafa831 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
@@ -383,55 +383,82 @@ pmease.commons = {
},
history: {
+ getHashlessUrl: function(url) {
+ var index = url.indexOf('#');
+ if (index != -1)
+ return url.substring(0, index);
+ else
+ return url;
+ },
init: function(callback) {
- pmease.commons.history.urlWithoutHash = location.pathname+(location.search?location.search:"");
-
// Use a timeout here solve the problem that Safari (and previous versions of Chrome)
// fires event "onpopstate" on initial page load and this causes the page to reload
// infinitely
setTimeout(function() {
window.onpopstate = function(event) {
- var currentUrlWithoutHash = location.pathname+(location.search?location.search:"");
- if (currentUrlWithoutHash != pmease.commons.history.urlWithoutHash) {
+ if (pmease.commons.history.getHashlessUrl(window.location.href)
+ != pmease.commons.history.getHashlessUrl(pmease.commons.history.current.url)) {
if (pmease.commons.form.confirmLeave()) {
- if (!event.state || !event.state.data)
+ if (!event.state || !event.state.data) {
location.reload();
- else
+ } else {
callback(event.state.data);
- pmease.commons.history.current = {
- state: event.state,
- url: window.location.href
- };
+ pmease.commons.history.current = {
+ state: event.state,
+ url: window.location.href
+ };
+ }
} else {
+ /*
+ * In case we want to stay in the page, we should also re-push previous url
+ * as url has already been changed when user hits back/forward button
+ */
history.pushState(pmease.commons.history.current.state, '' ,
pmease.commons.history.current.url);
}
}
- pmease.commons.history.urlWithoutHash = currentUrlWithoutHash;
};
}, 100);
pmease.commons.history.current = {
- url: window.location.href
+ url: window.location.href
};
},
pushState: function(url, data) {
var state = {data: data};
pmease.commons.history.current = {state: state, url: url};
history.pushState(state, '', url);
- pmease.commons.history.urlWithoutHash = location.pathname+(location.search?location.search:'');
+ setTimeout(function() {
+ pmease.commons.history.setVisited();
+ }, 100);
},
- replaceState: function(data, url) {
- var state = {data: data};
- pmease.commons.history.current = {state: state, url: url};
- history.replaceState(state, '', url);
- pmease.commons.history.urlWithoutHash = location.pathname+(location.search?location.search:'');
+ /*
+ * visited flag is used to determine whether or not a page is newly visited
+ * or loaded via back/forward button. If loaded via back/forward button we
+ * will not respect scroll flag (such as mark param in url) and let browser
+ * scroll to original position for better usage experience
+ */
+ setVisited: function() {
+ var state = history.state;
+ if (!state)
+ state = {};
+ if (!state.loaded) {
+ var newState = {viewState: state.viewState, data: state.data, visited: true};
+ history.replaceState(newState, '', window.location.href);
+ pmease.commons.history.current = {
+ state: newState,
+ url: window.location.href
+ };
+ }
+ },
+ isVisited: function() {
+ return history.state && history.state.visited;
},
setViewState: function(viewState) {
var state = history.state;
if (!state)
state = {};
- var newState = {viewState: viewState, data: state.data};
+ var newState = {viewState: viewState, data: state.data, visited: state.visited};
history.replaceState(newState, '', window.location.href );
pmease.commons.history.current = {
state: newState,
@@ -461,3 +488,7 @@ $(function() {
pmease.commons.focus.setupAutoFocus();
pmease.commons.websocket.setupCallback();
});
+
+$(window).load(function() {
+ pmease.commons.history.setVisited();
+});
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
index 6b9f8130ee..b82cb1239e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.css
@@ -125,7 +125,7 @@
white-space: pre-wrap;
word-wrap: break-word;
position: absolute;
- z-index: 10;
+ z-index: 10000;
font-size: 13px;
border: 1px solid #BBB;
background: #F9F9F9;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
index a0cbd937da..7fd33ae068 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
@@ -464,7 +464,7 @@ gitplex.sourceview = {
},
blame: function(blameInfos) {
var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var alignment = {targetX: 100, targetY: 0, x: 0, y: 0};
+ var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};
if (blameInfos) {
var markCallback = $(".source-view").data("markCallback");
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
index 681e3c4843..98b4f97c10 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css
@@ -182,7 +182,7 @@
white-space: pre-wrap;
word-wrap: break-word;
position: absolute;
- z-index: 10;
+ z-index: 10000;
font-size: 13px;
border: 1px solid #BBB;
background: #F9F9F9;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
index 72854ec94e..174d8de4d3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js
@@ -437,13 +437,13 @@ gitplex.textdiff = {
if (mark) {
$container.data("mark", mark);
gitplex.textdiff.mark($container, mark);
- if (scroll)
+ if (scroll && !pmease.commons.history.isVisited())
gitplex.textdiff.scroll($container, mark);
}
},
initBlameTooltip: function(containerId, $hashLink) {
var $container = $("#" + containerId);
- var alignment = {targetX: 100, targetY: 0, x: 0, y: 0};
+ var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};
$hashLink.hover(function() {
var $commitLink = $(this);
var $content = $commitLink.closest("tr").children("td.content");
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
index bf6cc5f315..80a1ac3061 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
@@ -14,7 +14,7 @@
<td class="path-filter">
<form wicket:id="pathFilter">
<div class="input-group">
- <input wicket:id="input" class="form-control" spellcheck="false" placeholder="Filter by path pattern" type="text"></input>
+ <input wicket:id="input" class="form-control" spellcheck="false" autocomplete="false" placeholder="Filter by path pattern" type="text"></input>
<span class="input-group-btn">
<button wicket:id="submit" title="Filter" class="btn btn-default" type="submit"><i class="fa fa-filter"></i></button>
</span>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
index db3dec1bc8..dec88d0af5 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
@@ -95,4 +95,4 @@ gitplex.revisionDiff = {
}
$(function() {
$(window).on("scroll resize", gitplex.revisionDiff.reposition);
-});
+})