The Unified and Autonomous Development Platform
Improve viewState handling
robin shine4c22b46d87f8
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/ClosestDescendantResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/ClosestDescendantResourceReference.javadeleted file mode 100644index e000a15843..0000000000--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/ClosestDescendantResourceReference.java+++ /dev/null@@ -1,15 +0,0 @@-package com.pmease.commons.wicket.assets.closestdescendant;--import org.apache.wicket.request.resource.JavaScriptResourceReference;--public class ClosestDescendantResourceReference extends JavaScriptResourceReference {-- private static final long serialVersionUID = 1L;-- public static final ClosestDescendantResourceReference INSTANCE = new ClosestDescendantResourceReference();-- private ClosestDescendantResourceReference() {- super(ClosestDescendantResourceReference.class, "closest-descendant.js");- }--}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/closest-descendant.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/closest-descendant.jsdeleted file mode 100644index 7d045dd091..0000000000--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/closestdescendant/closest-descendant.js+++ /dev/null@@ -1,64 +0,0 @@-/*!- * .closestDescendant( selector [, findAll ] )- * https://github.com/tlindig/jquery-closest-descendant- *- * v0.1.2 - 2014-02-17- *- * Copyright (c) 2014 Tobias Lindig- * http://tlindig.de/- *- * License: MIT- *- * Author: Tobias Lindig <[email protected]>- */-(function($) {-- /**- * Get the first element(s) that matches the selector by traversing down- * through descendants in the DOM tree level by level. It use a breadth- * first search (BFS), that mean it will stop search and not going deeper in- * the current subtree if the first matching descendant was found.- *- * @param {selectors} selector -required- a jQuery selector- * @param {boolean} findAll -optional- default is false, if true, every- * subtree will be visited until first match- * @return {jQuery} matched element(s)- */- $.fn.closestDescendant = function(selector, findAll) {-- if (!selector || selector === '') {- return $();- }-- findAll = findAll ? true : false;-- var resultSet = $();-- this.each(function() {-- var $this = $(this);-- // breadth first search for every matched node,- // go deeper, until a child was found in the current subtree or the leave was reached.- var queue = [];- queue.push($this);- while (queue.length > 0) {- var node = queue.shift();- var children = node.children();- for (var i = 0; i < children.length; ++i) {- var $child = $(children[i]);- if ($child.is(selector)) {- resultSet.push($child[0]); //well, we found one- if (!findAll) {- return false; //stop processing- }- } else {- queue.push($child); //go deeper- }- }- }- });-- return resultSet;- };-})(jQuery);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.jsindex 12e0fd1d28..241cd27002 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@@ -41,29 +41,17 @@ pmease.commons.codemirror = {CodeMirror.autoLoadMode(cm, modeInfo.mode);}},+ getViewState: function(cm) {+ var cursor = cm.getCursor();+ var scrollInfo = cm.getScrollInfo();+ var scroll = {left: scrollInfo.left, top: scrollInfo.top};+ return {cursor: cursor, scroll: scroll};+ },initState: function(cm, viewState) {- if (viewState) {- pmease.commons.history.setViewState(viewState);+ if (!viewState) {+ viewState = pmease.commons.history.getViewState();}- // use timer to minimize performance impact- var timer;- function onViewStateChange() {- if (timer)- clearTimeout(timer);- timer = setTimeout(function() {- timer = undefined;- var cursor = cm.getCursor();- var scrollInfo = cm.getScrollInfo();- var scroll = {left: scrollInfo.left, top: scrollInfo.top};- pmease.commons.history.setViewState({cursor: cursor, scroll: scroll});- }, 500);- };-- cm.on("cursorActivity", onViewStateChange);- cm.on("scroll", onViewStateChange);-- var viewState = pmease.commons.history.getViewState();if (viewState) {if (viewState.cursor)cm.setCursor(viewState.cursor);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.jsindex 27acafa831..20c2200165 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@@ -425,6 +425,7 @@ pmease.commons = {};},pushState: function(url, data) {+ $(".autofit:visible").first().trigger("storeViewState");var state = {data: data};pmease.commons.history.current = {state: state, url: url};history.pushState(state, '', url);@@ -491,4 +492,7 @@ $(function() {$(window).load(function() {pmease.commons.history.setVisited();+});+$(window).on("beforeunload", function() {+ $(".autofit:visible").first().trigger("storeViewState");});\ No newline at end of filediff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.javaindex d3134afead..10b9f0414a 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ViewStateAwareAjaxLink.java@@ -1,45 +1,46 @@-package com.pmease.commons.wicket.component;--import javax.annotation.Nullable;--import org.apache.commons.lang3.StringUtils;-import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;-import org.apache.wicket.model.IModel;-import org.apache.wicket.request.cycle.RequestCycle;--@SuppressWarnings("serial")-public abstract class ViewStateAwareAjaxLink<T> extends PreventDefaultAjaxLink<T> {-- public ViewStateAwareAjaxLink(String id) {- super(id);- }-- public ViewStateAwareAjaxLink(String id, IModel<T> model) {- super(id, model);- }-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.setMethod(Method.POST);-- String script = ""- + "var viewState = pmease.commons.history.getViewState();"- + "return viewState?JSON.stringify(viewState):'';";- attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");- }-- @Override- public final void onClick(AjaxRequestTarget target) {- String value = RequestCycle.get().getRequest().getRequestParameters()- .getParameterValue("view_state").toString();- if (StringUtils.isNotBlank(value))- onClick(target, value);- else- onClick(target, null);- }-- protected abstract void onClick(AjaxRequestTarget target, @Nullable String viewState);-}+package com.pmease.commons.wicket.component;++import javax.annotation.Nullable;++import org.apache.commons.lang3.StringUtils;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;+import org.apache.wicket.model.IModel;+import org.apache.wicket.request.cycle.RequestCycle;++@SuppressWarnings("serial")+public abstract class ViewStateAwareAjaxLink<T> extends PreventDefaultAjaxLink<T> {++ public ViewStateAwareAjaxLink(String id) {+ super(id);+ }++ public ViewStateAwareAjaxLink(String id, IModel<T> model) {+ super(id, model);+ }++ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.setMethod(Method.POST);++ String script = ""+ + "$('.autofit:visible').first().trigger('storeViewState');"+ + "var viewState = pmease.commons.history.getViewState();"+ + "return viewState?JSON.stringify(viewState):'';";+ attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");+ }++ @Override+ public final void onClick(AjaxRequestTarget target) {+ String value = RequestCycle.get().getRequest().getRequestParameters()+ .getParameterValue("view_state").toString();+ if (StringUtils.isNotBlank(value))+ onClick(target, value);+ else+ onClick(target, null);+ }++ protected abstract void onClick(AjaxRequestTarget target, @Nullable String viewState);+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.javaindex 3a9875a2d8..7310bef72a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/Constants.java@@ -22,5 +22,5 @@ public class Constants {/* commit constants */public static final int MAX_DISPLAY_COMMITS = 500;-+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobRenderer.javaindex acefb2521d..bca62f98fa 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobRenderer.java@@ -7,6 +7,6 @@ import com.pmease.commons.loader.ExtensionPoint;@ExtensionPointpublic interface BlobRenderer {- @Nullable BlobViewPanel render(String panelId, BlobViewContext context, @Nullable String viewState);+ @Nullable BlobViewPanel render(String panelId, BlobViewContext context);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.javaindex 6d23165f46..1fd6829fdb 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java@@ -37,7 +37,7 @@ public interface BlobViewContext extends Serializable {String getMarkUrl(Mark mark);Mode getMode();-+boolean isOnBranch();boolean isAtSourceBranchHead();@@ -50,7 +50,7 @@ public interface BlobViewContext extends Serializable {void onDelete(AjaxRequestTarget target);- void onEdit(AjaxRequestTarget target, @Nullable String viewState);+ void onEdit(AjaxRequestTarget target);void onCommentOpened(AjaxRequestTarget target, @Nullable CodeComment comment);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.javaindex d09a815f3e..cc8cc64efe 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewPanel.java@@ -13,7 +13,6 @@ import org.apache.wicket.request.resource.JavaScriptResourceReference;import com.google.common.base.Preconditions;import com.pmease.commons.git.BlobIdent;-import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;import com.pmease.commons.wicket.component.menu.MenuItem;import com.pmease.commons.wicket.component.menu.MenuLink;@@ -47,7 +46,6 @@ public abstract class BlobViewPanel extends Panel {public void renderHead(IHeaderResponse response) {super.renderHead(response);- response.render(JavaScriptHeaderItem.forReference(ClosestDescendantResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(BlobViewPanel.class, "blob-view.js")));response.render(CssHeaderItem.forReference(diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/binary/BinaryRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/binary/BinaryRenderer.javaindex 7c33872c58..99ce914bae 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/binary/BinaryRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/binary/BinaryRenderer.java@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;public class BinaryRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {Blob blob = context.getDepot().getBlob(context.getBlobIdent());if (blob.getText() == nulldiff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.jsindex 711b328e90..174b7b51e9 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/blob-view.js@@ -1,18 +1,21 @@gitplex.blobView = function(containerId) {var $blobView = $("#" + containerId + ">.blob-view");var $content = $blobView.find(">.content");- $content.scroll(function() {- pmease.commons.history.setViewState({scroll:{left: $content.scrollLeft(), top: $content.scrollTop()}});- });- $blobView.on("autofit", function(event, width, height) {- event.stopPropagation();+ $blobView.on("storeViewState", function(e) {+ e.stopPropagation();+ pmease.commons.history.setViewState({scroll:{left: $content.scrollLeft(), top: $content.scrollTop()}});+ $content.find(".autofit:visible").first().trigger("storeViewState");+ });++ $blobView.on("autofit", function(e, width, height) {+ e.stopPropagation();$blobView.outerWidth(width);$blobView.outerHeight(height);height = $blobView.height();$content.outerWidth(width).outerHeight(height);- $content.closestDescendant(".autofit:visible").trigger("autofit", [$content.width(), $content.height()]);+ $content.find(".autofit:visible").first().trigger("autofit", [$content.width(), $content.height()]);var viewState = pmease.commons.history.getViewState();if (viewState && viewState.scroll) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/gitlink/GitLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/gitlink/GitLinkRenderer.javaindex 4821b552aa..10613eb9fc 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/gitlink/GitLinkRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/gitlink/GitLinkRenderer.java@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;public class GitLinkRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {if (context.getBlobIdent().isGitLink())return new GitLinkPanel(panelId, context);elsediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/image/ImageRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/image/ImageRenderer.javaindex 70f795ee8a..2a5a11401a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/image/ImageRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/image/ImageRenderer.java@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;public class ImageRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {Blob blob = context.getDepot().getBlob(context.getBlobIdent());if (blob.getMediaType().getType().equalsIgnoreCase("image"))return new ImageViewPanel(panelId, context);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownRenderer.javaindex 6510a98e71..1b6b9c7cc9 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/markdown/MarkdownRenderer.java@@ -10,13 +10,13 @@ import com.pmease.gitplex.web.component.depotfile.blobview.source.SourceViewPanepublic class MarkdownRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {Blob blob = context.getDepot().getBlob(context.getBlobIdent());if (context.getBlobIdent().isFile()&& blob.getText() != null&& context.getBlobIdent().path.endsWith(".md")) {if (context.getMark() != null || context.getMode() == Mode.BLAME)- return new SourceViewPanel(panelId, context, viewState);+ return new SourceViewPanel(panelId, context);elsereturn new MarkdownFilePanel(panelId, context);} else {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceRenderer.javaindex 37e5eef922..2045d2e0e8 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceRenderer.java@@ -8,12 +8,12 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;public class SourceRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {Blob blob = context.getDepot().getBlob(context.getBlobIdent());if (context.getBlobIdent().isFile()&& blob.getText() != null&& !context.getBlobIdent().path.endsWith(".md")) {- return new SourceViewPanel(panelId, context, viewState);+ return new SourceViewPanel(panelId, context);} else {return null;}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.javaindex 2d6af11c2e..97e5f0d072 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java@@ -114,8 +114,6 @@ public class SourceViewPanel extends BlobViewPanel {private final List<Symbol> symbols = new ArrayList<>();- private final String viewState;-private final IModel<Collection<CodeComment>> commentsModel =new LoadableDetachableModel<Collection<CodeComment>>() {@@ -135,7 +133,7 @@ public class SourceViewPanel extends BlobViewPanel {private AbstractDefaultAjaxBehavior ajaxBehavior;- public SourceViewPanel(String id, BlobViewContext context, @Nullable String viewState) {+ public SourceViewPanel(String id, BlobViewContext context) {super(id, context);Blob blob = context.getDepot().getBlob(context.getBlobIdent());@@ -150,7 +148,6 @@ public class SourceViewPanel extends BlobViewPanel {}}- this.viewState = viewState;}@Override@@ -826,6 +823,7 @@ public class SourceViewPanel extends BlobViewPanel {CharSequence callback = ajaxBehavior.getCallbackFunction(explicit("action"), explicit("param1"), explicit("param2"),explicit("param3"), explicit("param4"));+ String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "+ "%s, %s, %s, %s, %s);",JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),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.jsindex 7fd33ae068..acace580b0 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@@ -36,6 +36,13 @@ gitplex.sourceview = {});}+ $sourceView.on("storeViewState", function(event) {+ event.stopPropagation();+ if (cm) {+ pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));+ }+ });+$sourceView.on("autofit", function(event, width, height) {event.stopPropagation();$sourceView.outerWidth(width);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkRenderer.javaindex e45b73b197..8d7a14f07d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/symbollink/SymbolLinkRenderer.java@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;public class SymbolLinkRenderer implements BlobRenderer {@Override- public BlobViewPanel render(String panelId, BlobViewContext context, String viewState) {+ public BlobViewPanel render(String panelId, BlobViewContext context) {if (context.getBlobIdent().isSymbolLink())return new SymbolLinkPanel(panelId, context);elsediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.javaindex 137843ac14..efd54da0a3 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/EditSavePanel.java@@ -7,6 +7,8 @@ import javax.annotation.Nullable;import org.apache.commons.lang3.StringEscapeUtils;import org.apache.commons.lang3.StringUtils;import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.ajax.markup.html.form.AjaxButton;import org.apache.wicket.markup.ComponentTag;@@ -21,6 +23,7 @@ import org.apache.wicket.markup.html.form.TextField;import org.apache.wicket.markup.html.panel.Panel;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;+import org.apache.wicket.request.cycle.RequestCycle;import org.apache.wicket.request.resource.CssResourceReference;import org.apache.wicket.request.resource.JavaScriptResourceReference;import org.eclipse.jgit.diff.DiffEntry;@@ -47,6 +50,7 @@ import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.manager.AccountManager;import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;import jersey.repackaged.com.google.common.base.Objects;@@ -200,6 +204,17 @@ public abstract class EditSavePanel extends Panel {form.add(new AjaxButton("save") {+ @Override+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {+ super.updateAjaxAttributes(attributes);+ attributes.setMethod(Method.POST);++ String script = String.format(""+ + "var viewState = $('#%s').data('viewState');"+ + "return viewState?JSON.stringify(viewState):'';", EditSavePanel.this.getMarkupId());+ attributes.getDynamicExtraParameters().add("return {view_state: function() {" + script + "}}");+ }+@Overrideprotected void onComponentTag(ComponentTag tag) {super.onComponentTag(tag);@@ -212,6 +227,10 @@ public abstract class EditSavePanel extends Panel {protected void onSubmit(AjaxRequestTarget target, Form<?> form) {super.onSubmit(target, form);+ String viewState = RequestCycle.get().getRequest().getRequestParameters()+ .getParameterValue("view_state").toString();+ RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);+change = null;PathAndContent newFile = fileEdit.getNewFile();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/edit-save.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/edit-save.jsindex de56a8bd03..724bab3080 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/edit-save.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/editsave/edit-save.js@@ -1,12 +1,12 @@gitplex.editsave = {init: function(containerId) {var $editSave = $("#" + containerId + ">.edit-save");- $editSave.scroll(function() {+ $editSave.on("storeViewState", function(e) {+ e.stopPropagation();pmease.commons.history.setViewState({scroll:{left: $editSave.scrollLeft(), top: $editSave.scrollTop()}});});-- $editSave.on("autofit", function(event, width, height) {- event.stopPropagation();+ $editSave.on("autofit", function(e, width, height) {+ e.stopPropagation();$editSave.closest(".body").css("overflow", "hidden");$editSave.outerWidth(width);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.javaindex a45077d741..5a5b891c2d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/FileEditPanel.java@@ -8,7 +8,6 @@ import org.apache.wicket.ajax.AjaxRequestTarget;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;import org.apache.wicket.ajax.attributes.CallbackParameter;-import org.apache.wicket.ajax.markup.html.AjaxLink;import org.apache.wicket.markup.head.CssHeaderItem;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptHeaderItem;@@ -35,9 +34,9 @@ import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.PathAndContent;import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;-import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;import com.pmease.commons.wicket.assets.diffmatchpatch.DiffMatchPatchResourceReference;+import com.pmease.commons.wicket.component.ViewStateAwareAjaxLink;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.Depot;import com.pmease.gitplex.core.entity.PullRequest;@@ -45,6 +44,7 @@ import com.pmease.gitplex.core.entity.component.Mark;import com.pmease.gitplex.web.component.depotfile.editsave.EditSavePanel;import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;import com.pmease.gitplex.web.component.diff.revision.DiffViewMode;+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;@SuppressWarnings("serial")public abstract class FileEditPanel extends Panel {@@ -65,8 +65,6 @@ public abstract class FileEditPanel extends Panel {private final Mark mark;- private final String viewState;-private AbstractDefaultAjaxBehavior previewBehavior;private AbstractDefaultAjaxBehavior saveBehavior;@@ -75,7 +73,7 @@ public abstract class FileEditPanel extends Panel {public FileEditPanel(String id, IModel<Depot> depotModel, String refName,@Nullable String oldPath, String content, ObjectId prevCommitId,- @Nullable Mark mark, @Nullable String viewState) {+ @Nullable Mark mark) {super(id);this.depotModel = depotModel;this.refName = refName;@@ -83,7 +81,6 @@ public abstract class FileEditPanel extends Panel {this.content = content;this.prevCommitId = prevCommitId;this.mark = mark;- this.viewState = viewState;newPath = this.oldPath;}@@ -165,7 +162,7 @@ public abstract class FileEditPanel extends Panel {};add(new WebMarkupContainer("saveLink").add(saveBehavior));- add(new AjaxLink<Void>("cancelLink") {+ add(new ViewStateAwareAjaxLink<Void>("cancelLink") {@Overrideprotected void updateAjaxAttributes(AjaxRequestAttributes attributes) {@@ -174,7 +171,8 @@ public abstract class FileEditPanel extends Panel {}@Override- public void onClick(AjaxRequestTarget target) {+ protected void onClick(AjaxRequestTarget target, String viewState) {+ RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);FileEditPanel.this.onCancel(target);}@@ -212,7 +210,6 @@ public abstract class FileEditPanel extends Panel {super.renderHead(response);response.render(JavaScriptHeaderItem.forReference(CodeMirrorResourceReference.INSTANCE));- response.render(JavaScriptHeaderItem.forReference(ClosestDescendantResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(DiffMatchPatchResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(@@ -220,6 +217,8 @@ public abstract class FileEditPanel extends Panel {response.render(CssHeaderItem.forReference(new CssResourceReference(FileEditPanel.class, "file-edit.css")));+ String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);+String script = String.format("gitplex.fileedit.init('%s', '%s', '%s', %s, %s, %s, %s);",getMarkupId(), getNewPathParam(), StringEscapeUtils.escapeEcmaScript(content),previewBehavior.getCallbackFunction(CallbackParameter.explicit("content")),@@ -268,4 +267,5 @@ public abstract class FileEditPanel extends Panel {protected abstract void onCommitted(AjaxRequestTarget target, ObjectId oldCommit, ObjectId newCommit);protected abstract void onCancel(AjaxRequestTarget target);+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.jsindex c68d49a247..f0c5fe3496 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/fileedit/file-edit.js@@ -17,8 +17,15 @@ gitplex.fileedit = {saveCallback(cm.getValue());});- $fileEdit.on("autofit", function(event, width, height) {- event.stopPropagation();+ $fileEdit.on("storeViewState", function(e) {+ e.stopPropagation();+ if (cm) {+ pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));+ }+ });++ $fileEdit.on("autofit", function(e, width, height) {+ e.stopPropagation();$fileEdit.outerWidth(width);$fileEdit.outerHeight(height);@@ -177,6 +184,13 @@ gitplex.fileedit = {}var $fileEdit = $tab.closest(".file-edit");var $body = $fileEdit.find(">.body");++ var $cm = $fileEdit.find(">.body>div.edit>.CodeMirror");+ if ($cm.is(":visible")) {+ var cm = $cm[0].CodeMirror;+ $fileEdit.find(">.body>div.save").data("viewState", pmease.commons.codemirror.getViewState(cm));+ }+$body.find(">div").hide();if ($tab.hasClass("edit")) {$body.find(">div.edit").show().find(">.CodeMirror")[0].CodeMirror.focus();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/file-list.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/file-list.jsindex 7c40e28ef7..e76d5d0a2e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/file-list.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filelist/file-list.js@@ -3,8 +3,8 @@ gitplex.filelist = {var $container = $("#" + containerId);var $fileList = $container.find(">.file-list");- $fileList.on("autofit", function(event, width, height) {- event.stopPropagation();+ $fileList.on("autofit", function(e, width, height) {+ e.stopPropagation();$fileList.outerWidth(width);$fileList.outerHeight(height);@@ -14,9 +14,10 @@ gitplex.filelist = {$fileList.scrollTop(viewState.scroll.top);}});-- $fileList.scroll(function() {- pmease.commons.history.setViewState({scroll:{left: $fileList.scrollLeft(), top: $fileList.scrollTop()}});++ $fileList.on("storeViewState", function(e) {+ e.stopPropagation();+ pmease.commons.history.setViewState({scroll:{left: $fileList.scrollLeft(), top: $fileList.scrollTop()}});});$.ajax({diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.javaindex e0a1733441..33904c3eb7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/filenavigator/FileNavigator.java@@ -494,7 +494,8 @@ public abstract class FileNavigator extends Panel {@Overridepublic void onClick(AjaxRequestTarget target, String viewState) {close();- context.onEdit(target, viewState);+ RequestCycle.get().setMetaData(DepotFilePage.VIEW_STATE_KEY, viewState);+ context.onEdit(target);}};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.javaindex d667b736ad..d758acb643 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java@@ -50,7 +50,6 @@ import com.pmease.commons.git.GitUtils;import com.pmease.commons.git.exception.ObjectNotExistException;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.lang.extractors.TokenPosition;-import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;import com.pmease.commons.wicket.component.menu.MenuItem;@@ -97,9 +96,14 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {private static class SearchResultKey extends MetaDataKey<ArrayList<QueryHit>> {};-+public static final SearchResultKey SEARCH_RESULT_KEY = new SearchResultKey();+ private static class ViewStateKey extends MetaDataKey<String> {+ };++ public static final ViewStateKey VIEW_STATE_KEY = new ViewStateKey();+private static final String PARAM_REVISION = "revision";private static final String PARAM_PATH = "path";@@ -159,9 +163,6 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {private transient List<QueryHit> queryHits;- // client state holding CodeMirror cursor, scroll, marks, etc.- private transient String viewState;-public DepotFilePage(final PageParameters params) {super(params);@@ -229,7 +230,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {}}- viewState = params.get(PARAM_VIEW_STATE).toString();+ RequestCycle.get().setMetaData(VIEW_STATE_KEY, params.get(PARAM_VIEW_STATE).toString());if (mode == Mode.EDIT || mode == Mode.DELETE) {if (!isOnBranch())@@ -344,7 +345,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {});newContributionPanel(null);- newFileViewer(null, viewState);+ newFileViewer(null);add(searchResultContainer = new WebMarkupContainer("searchResultContainer"));@@ -441,7 +442,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {newFileNavigator(target);newContributionPanel(target);- newFileViewer(target, null);+ newFileViewer(target);pushState(target);resizeWindow(target);@@ -492,9 +493,9 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {}}- private BlobViewPanel renderBlobViewer(String panelId, @Nullable String viewState) {+ private BlobViewPanel renderBlobViewer(String panelId) {for (BlobRenderer renderer: GitPlex.getExtensions(BlobRenderer.class)) {- BlobViewPanel panel = renderer.render(panelId, this, viewState);+ BlobViewPanel panel = renderer.render(panelId, this);if (panel != null)return panel;}@@ -502,7 +503,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {throw new IllegalStateException("No applicable blob renderer found.");}- private void newFileViewer(@Nullable AjaxRequestTarget target, @Nullable String viewState) {+ private void newFileViewer(@Nullable AjaxRequestTarget target) {Component fileViewer;if (mode == Mode.EDIT) {final String refName = GitUtils.branch2ref(blobIdent.revision);@@ -511,7 +512,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {FILE_VIEWER_ID, depotModel, refName,blobIdent.isTree()?null:blobIdent.path,blobIdent.isTree()?"":getDepot().getBlob(blobIdent).getText().getContent(),- getDepot().getObjectId(blobIdent.revision), mark, viewState) {+ getDepot().getObjectId(blobIdent.revision), mark) {@Overrideprotected void onCommitted(AjaxRequestTarget target, ObjectId oldCommit, ObjectId newCommit) {@@ -537,7 +538,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {mode = null;newFileNavigator(target);newContributionPanel(target);- newFileViewer(target, null);+ newFileViewer(target);pushState(target);resizeWindow(target);}@@ -551,8 +552,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {@Overridepublic void onCancel(AjaxRequestTarget target) {mode = null;-- newFileViewer(target, null);+ newFileViewer(target);pushState(target);resizeWindow(target);@@ -605,7 +605,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {};} else {- fileViewer = renderBlobViewer(FILE_VIEWER_ID, viewState);+ fileViewer = renderBlobViewer(FILE_VIEWER_ID);}if (target != null) {replace(fileViewer);@@ -717,14 +717,13 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {target.add(revisionIndexing);newContributionPanel(target);- newFileViewer(target, null);+ newFileViewer(target);}@Overridepublic void renderHead(IHeaderResponse response) {super.renderHead(response);- response.render(JavaScriptHeaderItem.forReference(ClosestDescendantResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(JQueryUIResourceReference.INSTANCE));@@ -871,7 +870,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {FileEditPanel fileEditor = (FileEditPanel) fileViewer;fileEditor.mark(target, mark);} else {- newFileViewer(target, null);+ newFileViewer(target);resizeWindow(target);}}@@ -884,7 +883,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {newFileNavigator(target);newContributionPanel(target);- newFileViewer(target, null);+ newFileViewer(target);resizeWindow(target);}@@ -902,7 +901,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {mode = (blamed?Mode.BLAME:null);Component fileViewer = get(FILE_VIEWER_ID);if (!(fileViewer instanceof SourceViewPanel)) {- newFileViewer(target, null);+ newFileViewer(target);resizeWindow(target);}pushState(target);@@ -912,18 +911,18 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {public void onDelete(AjaxRequestTarget target) {mode = Mode.DELETE;- newFileViewer(target, null);+ newFileViewer(target);pushState(target);resizeWindow(target);}@Override- public void onEdit(AjaxRequestTarget target, @Nullable String viewState) {+ public void onEdit(AjaxRequestTarget target) {mode = Mode.EDIT;newFileNavigator(target);newContributionPanel(target);- newFileViewer(target, viewState);+ newFileViewer(target);pushState(target);resizeWindow(target);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.jsindex d08058cccb..590dff4318 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/depot-file.js@@ -1,69 +1,69 @@-$(window).load(function() {- var cookieKey = "repoFile.searchResult.height";- $("body").css("overflow", "hidden");- var $searchResult = $("#repo-file>.search-result");- var height = Cookies.get(cookieKey);- if (height)- $searchResult.outerHeight(height);- $searchResult.resizable({- autoHide: false,- handles: {"n": "#search-result-resize-handle"},- minHeight: 75,- resize: function(e, ui) {- var $fileViewer = $("#repo-file>.file-viewer");- var fileViewerHeight = $fileViewer.outerHeight();- if(fileViewerHeight < 100)- $(this).resizable({maxHeight: ui.size.height});- },- stop: function(e, ui) {- $(this).resizable({maxHeight: undefined});- Cookies.set(cookieKey, ui.size.height, {expires: Infinity});- }- });-- $(window).resize(function(e) {- e.stopPropagation();-- var $head = $("#repo-file>.head");- var $revisionPicker = $head.find(">.revision-picker");-- // we should simply call $head.width() here, but the value is incorrect after maximize and restore- // window in IE and Chrome (maybe due to use of table in sidebar?), so we go with the complicate- // approach of calculating the head width- var headWidth = $("#repository").width() - $("#repository>.sidebar>table>tbody>tr>td.nav").outerWidth();-- // below code moves file navigator to bottom if it is too wide- var maxWidth = headWidth - $revisionPicker.outerWidth() - 80;- var maxHeight = $head.height();-- var $fileNavigator = $head.find(">.file-navigator");- if ($fileNavigator.length != 0) {- if ($fileNavigator.outerWidth() > maxWidth || $fileNavigator.outerHeight() > maxHeight)- $("#repo-file>.file-navigator").show().append($fileNavigator);- } else {- $fileNavigator = $("#repo-file>.file-navigator>div");- if ($fileNavigator.outerWidth() <= maxWidth && $fileNavigator.outerHeight() <= maxHeight) {- $fileNavigator.insertAfter($revisionPicker);- $("#repo-file>.file-navigator").hide();- }- }-- var $fileViewer = $("#repo-file>.file-viewer");- var width = $(window).width()-$("#repo-file").parent().prev().outerWidth();- var height = $(window).height()-$fileViewer.offset().top;- if ($("#main>.foot").length != 0)- height -= $("#main>.foot").outerHeight();- if ($searchResult.is(":visible")) {- $searchResult.outerWidth(width);- var $searchResultBody = $searchResult.find(".search-result>.body");- $searchResultBody.outerWidth($searchResult.width());- height -= $searchResult.outerHeight();- $searchResultBody.outerHeight($searchResult.height()- -$searchResult.find(".search-result>.head").outerHeight()- -$("#search-result-resize-handle").outerHeight());- }- $fileViewer.outerWidth(width).outerHeight(height);- $fileViewer.closestDescendant(".autofit:visible").trigger("autofit", [$fileViewer.width(), $fileViewer.height()]);- });- $(window).resize();-});+$(window).load(function() {+ var cookieKey = "repoFile.searchResult.height";+ $("body").css("overflow", "hidden");+ var $searchResult = $("#repo-file>.search-result");+ var height = Cookies.get(cookieKey);+ if (height)+ $searchResult.outerHeight(height);+ $searchResult.resizable({+ autoHide: false,+ handles: {"n": "#search-result-resize-handle"},+ minHeight: 75,+ resize: function(e, ui) {+ var $fileViewer = $("#repo-file>.file-viewer");+ var fileViewerHeight = $fileViewer.outerHeight();+ if(fileViewerHeight < 100)+ $(this).resizable({maxHeight: ui.size.height});+ },+ stop: function(e, ui) {+ $(this).resizable({maxHeight: undefined});+ Cookies.set(cookieKey, ui.size.height, {expires: Infinity});+ }+ });++ $(window).resize(function(e) {+ e.stopPropagation();++ var $head = $("#repo-file>.head");+ var $revisionPicker = $head.find(">.revision-picker");++ // we should simply call $head.width() here, but the value is incorrect after maximize and restore+ // window in IE and Chrome (maybe due to use of table in sidebar?), so we go with the complicate+ // approach of calculating the head width+ var headWidth = $("#repository").width() - $("#repository>.sidebar>table>tbody>tr>td.nav").outerWidth();++ // below code moves file navigator to bottom if it is too wide+ var maxWidth = headWidth - $revisionPicker.outerWidth() - 80;+ var maxHeight = $head.height();++ var $fileNavigator = $head.find(">.file-navigator");+ if ($fileNavigator.length != 0) {+ if ($fileNavigator.outerWidth() > maxWidth || $fileNavigator.outerHeight() > maxHeight)+ $("#repo-file>.file-navigator").show().append($fileNavigator);+ } else {+ $fileNavigator = $("#repo-file>.file-navigator>div");+ if ($fileNavigator.outerWidth() <= maxWidth && $fileNavigator.outerHeight() <= maxHeight) {+ $fileNavigator.insertAfter($revisionPicker);+ $("#repo-file>.file-navigator").hide();+ }+ }++ var $fileViewer = $("#repo-file>.file-viewer");+ var width = $(window).width()-$("#repo-file").parent().prev().outerWidth();+ var height = $(window).height()-$fileViewer.offset().top;+ if ($("#main>.foot").length != 0)+ height -= $("#main>.foot").outerHeight();+ if ($searchResult.is(":visible")) {+ $searchResult.outerWidth(width);+ var $searchResultBody = $searchResult.find(".search-result>.body");+ $searchResultBody.outerWidth($searchResult.width());+ height -= $searchResult.outerHeight();+ $searchResultBody.outerHeight($searchResult.height()+ -$searchResult.find(".search-result>.head").outerHeight()+ -$("#search-result-resize-handle").outerHeight());+ }+ $fileViewer.outerWidth(width).outerHeight(height);+ $fileViewer.find(".autofit:visible").first().trigger("autofit", [$fileViewer.width(), $fileViewer.height()]);+ });+ $(window).resize();+});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.htmlindex 5e2765c7e5..0445426613 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html@@ -1,12 +1,17 @@<wicket:extend>- <div class='container' style="margin: 100px;">- <a class="trigger" style='border:1px solid blue;'>test</a>- </div>+ <div class="doit"></div>+ <div><div class="autofit 1"><div><div class="autofit 2"></div></div></div></div>+ <div class="autofit 3"></div>+ <a class="link">test</a><script type="text/javascript">- $(".trigger").hover(function() {- var $content = $("<div style='border:1px solid red;'>hello world</div>");- $(".container").append($content);- return $content;- }, {targetX: 0, targetY: 0, x: 0, y:0});+ $(".autofit.1").on("storeViewState", function(e) {+ e.stopPropagation();+ console.log("view state stored");+ });+ $("a.link").click(function(e) {+ console.log("before");+ $(".autofit:visible").first().trigger("storeViewState");+ console.log("after");+ });</script></wicket:extend>\ No newline at end of file