The Unified and Autonomous Development Platform
Add ScrollBehavior and StickyBehavior.
robin shine2e53bf26c0b7
diff --git a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.javaindex 74af6f13d4..b3e8c01f01 100644--- a/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java+++ b/commons.util/src/test/java/com/pmease/commons/util/diff/DiffUtilsTest.java@@ -114,6 +114,11 @@ public class DiffUtilsTest {" this is the 10th line\n" +"+this is the 11th line\n",diffChunks.get(1).toString());+ diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 0);+ assertEquals(3, diffChunks.size());+ assertEquals(2, diffChunks.get(0).getDiffLines().size());+ assertEquals(2, diffChunks.get(1).getDiffLines().size());+ assertEquals(1, diffChunks.get(2).getDiffLines().size());text1 = new ArrayList<>();text1.add("this is the 1st line");@@ -140,8 +145,11 @@ public class DiffUtilsTest {text2.add("this is the 10th line");diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 3);+ assertEquals(1, diffChunks.size());+ diffChunks = DiffUtils.diffAsChunks(text1, text2, null, 0);assertEquals(1, diffChunks.size());+ assertEquals(2, diffChunks.get(0).getDiffLines().size());}@Testdiff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.javaindex 82626d712d..086963ab31 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonResourceReference.java@@ -82,6 +82,10 @@ class CommonResourceReference extends JavaScriptResourceReference {dependencies.add(JavaScriptHeaderItem.forReference(Bootstrap.getSettings().getModernizrResourceReference()));dependencies.addAll(bootstrapHeaderItems);+ dependencies.add(JavaScriptHeaderItem.forReference(Asset.ALIGN_JS));++ dependencies.add(JavaScriptHeaderItem.forReference(Asset.STICKY_JS));+dependencies.add(JavaScriptHeaderItem.forReference(Asset.ARE_YOU_SURE_JS));dependencies.add(CssHeaderItem.forReference(Asset.COMMON_CSS));diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/Asset.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/Asset.javaindex d48caf5eb5..70f7f93d22 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/Asset.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/Asset.java@@ -8,6 +8,12 @@ public class Asset {public static final JavaScriptResourceReference ARE_YOU_SURE_JS =new JavaScriptResourceReference(Asset.class, "jquery.are-you-sure.patched.js");+ public static final JavaScriptResourceReference STICKY_JS =+ new JavaScriptResourceReference(Asset.class, "jquery.sticky-kit.js");++ public static final JavaScriptResourceReference ALIGN_JS =+ new JavaScriptResourceReference(Asset.class, "jquery.align.js");+public static final JavaScriptResourceReference COMMON_JS =new JavaScriptResourceReference(Asset.class, "common.js");diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.jsindex 523ab014d9..89041fc5cc 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/common.js@@ -2,154 +2,6 @@* Define common javascript functions and setups here.***************************************************************/-jQuery.fn.align = function(alignment) {- if (this[0] == undefined)- return this;-- if (alignment == undefined)- alignment = this[0].alignment;-- var indicator = this.find(">.indicator");-- var borderTop = jQuery(window).scrollTop();- var borderBottom = borderTop + jQuery(window).height();- var borderLeft = jQuery(window).scrollLeft();- var borderRight = borderLeft + jQuery(window).width();-- var width = this.outerWidth();- var height = this.outerHeight();-- var indicatorSize = 6;-- var left, top;- var targetLeft, targetTop;- var targetWidth, targetHeight;- var targetX, targetY;-- if (alignment.target.element == undefined) { // align to mouse- targetLeft = alignment.target.pageX;- targetTop = alignment.target.pageY;- targetWidth = 0;- targetHeight = 0;- targetX = 0;- targetY = 0;- } else {- var target = $(alignment.target.element);- targetLeft = target.offset().left;- targetTop = target.offset().top;- targetWidth = target.outerWidth();- targetHeight = target.outerHeight();- targetX = alignment.target.x;- targetY = alignment.target.y;- }-- var anchor = targetWidth*targetX/100.0 + targetLeft;- left = anchor - alignment.x*width/100.0;- if (left < borderLeft || left + width > borderRight) {- // flip horizontally to see if width can fit into screen- anchor = targetWidth*(100-targetX)/100.0 + targetLeft;- left = anchor - (100 - alignment.x) * width / 100.0;- if (left < borderLeft || left + width > borderRight) {- // does not fit even flipped, so we revert back- anchor = targetWidth*targetX/100.0 + targetLeft;- left = anchor - alignment.x*width/100.0;- }- if (left + width > borderRight)- left = borderRight - width;- if (left < borderLeft)- left = borderLeft;- }-- anchor = targetHeight * targetY / 100.0 + targetTop;- top = anchor - alignment.y * height / 100.0;- if (top < borderTop || top + height > borderBottom) {- // flip vertically to see if height can fit into screen- anchor = targetHeight * (100 - targetY) / 100.0 + targetTop;- top = anchor - (100 - alignment.y) * height / 100.0;- if (top < borderTop || top+height > borderBottom) {- // does not fit even flipped, so we revert back- anchor = targetHeight * targetY / 100.0 + targetTop;- top = anchor - alignment.y * height / 100.0;- }- if (top + height > borderBottom)- top = borderBottom - height;- if (top < borderTop)- top = borderTop;- }-- if (indicator[0] && indicator[1]) {- indicator.removeClass("left right top bottom");- if (left >= targetLeft + targetWidth) {- if (left + width + alignment.offset <= borderRight) {- indicator.addClass("right");- left += alignment.offset;- var targetCenter = targetTop + targetHeight/2.0;- var indicatorTop = targetCenter - top - indicatorSize;- if (indicatorTop < indicatorSize)- indicatorTop = indicatorSize;- if (indicatorTop > height - 3 * indicatorSize)- indicatorTop = height - 3 * indicatorSize;- $(indicator[0]).css({top: (indicatorTop - 1) + "px"});- $(indicator[1]).css({top: indicatorTop + "px"});- }- } else if (left + width <= targetLeft) {- if (left - alignment.offset >= borderLeft) {- indicator.addClass("left");- left -= alignment.offset;- var targetCenter = targetTop + targetHeight/2.0;- var indicatorTop = targetCenter - top - indicatorSize;- if (indicatorTop < indicatorSize)- indicatorTop = indicatorSize;- if (indicatorTop > height - 3 * indicatorSize)- indicatorTop = height - 3 * indicatorSize;- $(indicator[0]).css({top: (indicatorTop - 1) + "px"});- $(indicator[1]).css({top: indicatorTop + "px"});- }- } else if (top >= targetTop + targetHeight) {- if (top + height + alignment.offset <= borderBottom) {- indicator.addClass("bottom");- top += alignment.offset;- var targetCenter = targetLeft + targetWidth/2.0;- var indicatorLeft = targetCenter - left - indicatorSize;- if (indicatorLeft < indicatorSize)- indicatorLeft = indicatorSize;- if (indicatorLeft > width - 3 * indicatorSize)- indicatorLeft = width - 3 * indicatorSize;- $(indicator[0]).css({left: (indicatorLeft - 1) + "px"});- $(indicator[1]).css({left: indicatorLeft + "px"});- }- } else if (top + height <= targetTop) {- if (top - alignment.offset >= borderTop) {- indicator.addClass("top");- top -= alignment.offset;- var targetCenter = targetLeft + targetWidth/2.0;- var indicatorLeft = targetCenter - left - indicatorSize;- if (indicatorLeft < indicatorSize)- indicatorLeft = indicatorSize;- if (indicatorLeft > width - 3 * indicatorSize)- indicatorLeft = width - 3 * indicatorSize;- $(indicator[0]).css({left: (indicatorLeft - 1) + "px"});- $(indicator[1]).css({left: indicatorLeft + "px"});- }- }- } else {- if (left >= targetLeft + targetWidth) {- if (left + width + alignment.offset <= borderRight)- left += alignment.offset;- } else if (left + width <= targetLeft) {- if (left - alignment.offset >= borderLeft)- left -= alignment.offset;- } else if (top >= targetTop + targetHeight) {- if (top + height + alignment.offset <= borderBottom)- top += alignment.offset;- } else if (top + height <= targetTop) {- if (top - alignment.offset >= borderTop)- top -= alignment.offset;- }- }- this.css({left:left, top:top});- return this;-};var pmease = {};@@ -673,6 +525,57 @@ pmease.commons = {});},+ scroll: {+ next: function(fixContainerId, selector, margin) {+ var next = pmease.commons.scroll.getNext(fixContainerId, selector, margin);+ if (next != null) {+ var $fixContainer = $("#" + fixContainerId);+ var topMargin = margin+$fixContainer.outerHeight();+ $('html, body').animate({scrollTop: $(next).offset().top-topMargin}, 500);+ }+ },++ prev: function(fixContainerId, selector, margin) {+ var prev = pmease.commons.scroll.getPrev(fixContainerId, selector, margin);+ if (prev != null) {+ var $fixContainer = $("#" + fixContainerId);+ var topMargin = margin+$fixContainer.outerHeight();+ $('html, body').animate({scrollTop: $(prev).offset().top-topMargin}, 500);+ }+ },++ getNext: function(fixContainerId, selector, margin) {+ var next = null;+ $(selector).each(function() {+ var bottom = $(window).scrollTop() + $(window).height() - margin;++ var thisTop = $(this).offset().top;+ if (bottom < thisTop && $(document).height()-thisTop>margin) {+ next = this;+ return false;+ }+ });+ return next;+ },++ getPrev: function(fixContainerId, selector, margin) {+ var $fixContainer = $("#" + fixContainerId);+ var topMargin = margin+$fixContainer.outerHeight();+ var prev = null;+ $($(selector).get().reverse()).each(function() {+ var top = $(window).scrollTop() + topMargin;++ var thisTop = $(this).offset().top;+ if (top > thisTop && thisTop > topMargin) {+ prev = this;+ return false;+ }+ });+ return prev;+ },++ },+focus: {$components: null,@@ -719,11 +622,11 @@ pmease.commons = {var $input = $("#" + inputId);$input.bind("input propertychange keyup", function() {var value = $(this).val();- var button = $("#" + buttonId);+ var $button = $("#" + buttonId);if (value.trim().length != 0)- button.removeAttr("disabled");+ $button.removeAttr("disabled");else- button.attr("disabled", "disabled");+ $button.attr("disabled", "disabled");});$input.trigger("input");},diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.align.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.align.jsnew file mode 100644index 0000000000..5540ad628c--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.align.js@@ -0,0 +1,151 @@+/*+ * 2014, Robin Shen+ */+jQuery.fn.align = function(alignment) {+ if (this[0] == undefined)+ return this;++ if (alignment == undefined)+ alignment = this[0].alignment;++ var indicator = this.find(">.indicator");++ var borderTop = jQuery(window).scrollTop();+ var borderBottom = borderTop + jQuery(window).height();+ var borderLeft = jQuery(window).scrollLeft();+ var borderRight = borderLeft + jQuery(window).width();++ var width = this.outerWidth();+ var height = this.outerHeight();++ var indicatorSize = 6;++ var left, top;+ var targetLeft, targetTop;+ var targetWidth, targetHeight;+ var targetX, targetY;++ if (alignment.target.element == undefined) { // align to mouse+ targetLeft = alignment.target.pageX;+ targetTop = alignment.target.pageY;+ targetWidth = 0;+ targetHeight = 0;+ targetX = 0;+ targetY = 0;+ } else {+ var target = $(alignment.target.element);+ targetLeft = target.offset().left;+ targetTop = target.offset().top;+ targetWidth = target.outerWidth();+ targetHeight = target.outerHeight();+ targetX = alignment.target.x;+ targetY = alignment.target.y;+ }++ var anchor = targetWidth*targetX/100.0 + targetLeft;+ left = anchor - alignment.x*width/100.0;+ if (left < borderLeft || left + width > borderRight) {+ // flip horizontally to see if width can fit into screen+ anchor = targetWidth*(100-targetX)/100.0 + targetLeft;+ left = anchor - (100 - alignment.x) * width / 100.0;+ if (left < borderLeft || left + width > borderRight) {+ // does not fit even flipped, so we revert back+ anchor = targetWidth*targetX/100.0 + targetLeft;+ left = anchor - alignment.x*width/100.0;+ }+ if (left + width > borderRight)+ left = borderRight - width;+ if (left < borderLeft)+ left = borderLeft;+ }++ anchor = targetHeight * targetY / 100.0 + targetTop;+ top = anchor - alignment.y * height / 100.0;+ if (top < borderTop || top + height > borderBottom) {+ // flip vertically to see if height can fit into screen+ anchor = targetHeight * (100 - targetY) / 100.0 + targetTop;+ top = anchor - (100 - alignment.y) * height / 100.0;+ if (top < borderTop || top+height > borderBottom) {+ // does not fit even flipped, so we revert back+ anchor = targetHeight * targetY / 100.0 + targetTop;+ top = anchor - alignment.y * height / 100.0;+ }+ if (top + height > borderBottom)+ top = borderBottom - height;+ if (top < borderTop)+ top = borderTop;+ }++ if (indicator[0] && indicator[1]) {+ indicator.removeClass("left right top bottom");+ if (left >= targetLeft + targetWidth) {+ if (left + width + alignment.offset <= borderRight) {+ indicator.addClass("right");+ left += alignment.offset;+ var targetCenter = targetTop + targetHeight/2.0;+ var indicatorTop = targetCenter - top - indicatorSize;+ if (indicatorTop < indicatorSize)+ indicatorTop = indicatorSize;+ if (indicatorTop > height - 3 * indicatorSize)+ indicatorTop = height - 3 * indicatorSize;+ $(indicator[0]).css({top: (indicatorTop - 1) + "px"});+ $(indicator[1]).css({top: indicatorTop + "px"});+ }+ } else if (left + width <= targetLeft) {+ if (left - alignment.offset >= borderLeft) {+ indicator.addClass("left");+ left -= alignment.offset;+ var targetCenter = targetTop + targetHeight/2.0;+ var indicatorTop = targetCenter - top - indicatorSize;+ if (indicatorTop < indicatorSize)+ indicatorTop = indicatorSize;+ if (indicatorTop > height - 3 * indicatorSize)+ indicatorTop = height - 3 * indicatorSize;+ $(indicator[0]).css({top: (indicatorTop - 1) + "px"});+ $(indicator[1]).css({top: indicatorTop + "px"});+ }+ } else if (top >= targetTop + targetHeight) {+ if (top + height + alignment.offset <= borderBottom) {+ indicator.addClass("bottom");+ top += alignment.offset;+ var targetCenter = targetLeft + targetWidth/2.0;+ var indicatorLeft = targetCenter - left - indicatorSize;+ if (indicatorLeft < indicatorSize)+ indicatorLeft = indicatorSize;+ if (indicatorLeft > width - 3 * indicatorSize)+ indicatorLeft = width - 3 * indicatorSize;+ $(indicator[0]).css({left: (indicatorLeft - 1) + "px"});+ $(indicator[1]).css({left: indicatorLeft + "px"});+ }+ } else if (top + height <= targetTop) {+ if (top - alignment.offset >= borderTop) {+ indicator.addClass("top");+ top -= alignment.offset;+ var targetCenter = targetLeft + targetWidth/2.0;+ var indicatorLeft = targetCenter - left - indicatorSize;+ if (indicatorLeft < indicatorSize)+ indicatorLeft = indicatorSize;+ if (indicatorLeft > width - 3 * indicatorSize)+ indicatorLeft = width - 3 * indicatorSize;+ $(indicator[0]).css({left: (indicatorLeft - 1) + "px"});+ $(indicator[1]).css({left: indicatorLeft + "px"});+ }+ }+ } else {+ if (left >= targetLeft + targetWidth) {+ if (left + width + alignment.offset <= borderRight)+ left += alignment.offset;+ } else if (left + width <= targetLeft) {+ if (left - alignment.offset >= borderLeft)+ left -= alignment.offset;+ } else if (top >= targetTop + targetHeight) {+ if (top + height + alignment.offset <= borderBottom)+ top += alignment.offset;+ } else if (top + height <= targetTop) {+ if (top - alignment.offset >= borderTop)+ top -= alignment.offset;+ }+ }+ this.css({left:left, top:top});+ return this;+};\ No newline at end of filediff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.sticky-kit.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.sticky-kit.jsnew file mode 100644index 0000000000..022f75a968--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/asset/jquery.sticky-kit.js@@ -0,0 +1,196 @@+// Generated by CoffeeScript 1.7.1++/**+@license Sticky-kit v1.0.4 | WTFPL | Leaf Corcoran 2014 | http://leafo.net+ */++(function() {+ var $, win;++ $ = this.jQuery;++ win = $(window);++ $.fn.stick_in_parent = function(opts) {+ var elm, inner_scrolling, offset_top, parent_selector, sticky_class, _fn, _i, _len;+ if (opts == null) {+ opts = {};+ }+ sticky_class = opts.sticky_class, inner_scrolling = opts.inner_scrolling, parent_selector = opts.parent, offset_top = opts.offset_top;+ if (offset_top == null) {+ offset_top = 0;+ }+ if (parent_selector == null) {+ parent_selector = void 0;+ }+ if (inner_scrolling == null) {+ inner_scrolling = true;+ }+ if (sticky_class == null) {+ sticky_class = "is_stuck";+ }+ _fn = function(elm, padding_bottom, parent_top, parent_height, top, height, el_float) {+ var bottomed, detach, fixed, last_pos, offset, parent, recalc, recalc_and_tick, spacer, tick;+ if (elm.data("sticky_kit")) {+ return;+ }+ elm.data("sticky_kit", true);+ parent = elm.parent();+ if (parent_selector != null) {+ parent = parent.closest(parent_selector);+ }+ if (!parent.length) {+ throw "failed to find stick parent";+ }+ fixed = false;+ bottomed = false;+ spacer = $("<div />");+ spacer.css('position', elm.css('position'));+ recalc = function() {+ var border_top, padding_top, restore;+ border_top = parseInt(parent.css("border-top-width"), 10);+ padding_top = parseInt(parent.css("padding-top"), 10);+ padding_bottom = parseInt(parent.css("padding-bottom"), 10);+ parent_top = parent.offset().top + border_top + padding_top;+ parent_height = parent.height();+ restore = fixed ? (fixed = false, bottomed = false, elm.insertAfter(spacer).css({+ position: "",+ top: "",+ width: "",+ bottom: ""+ }), spacer.detach(), true) : void 0;+ top = elm.offset().top - parseInt(elm.css("margin-top"), 10) - offset_top;+ height = elm.outerHeight(true);+ el_float = elm.css("float");+ spacer.css({+ width: elm.outerWidth(true),+ height: height,+ display: elm.css("display"),+ "vertical-align": elm.css("vertical-align"),+ "float": el_float+ });+ if (restore) {+ return tick();+ }+ };+ recalc();+ if (height === parent_height) {+ return;+ }+ last_pos = void 0;+ offset = offset_top;+ tick = function() {+ var css, delta, scroll, will_bottom, win_height;+ scroll = win.scrollTop();+ if (last_pos != null) {+ delta = scroll - last_pos;+ }+ last_pos = scroll;+ if (fixed) {+ will_bottom = scroll + height + offset > parent_height + parent_top;+ if (bottomed && !will_bottom) {+ bottomed = false;+ elm.css({+ position: "fixed",+ bottom: "",+ top: offset+ }).trigger("sticky_kit:unbottom");+ }+ if (scroll < top) {+ fixed = false;+ offset = offset_top;+ if (el_float === "left" || el_float === "right") {+ elm.insertAfter(spacer);+ }+ spacer.detach();+ css = {+ position: "",+ width: "",+ top: ""+ };+ elm.css(css).removeClass(sticky_class).trigger("sticky_kit:unstick");+ }+ if (inner_scrolling) {+ win_height = win.height();+ if (height > win_height) {+ if (!bottomed) {+ offset -= delta;+ offset = Math.max(win_height - height, offset);+ offset = Math.min(offset_top, offset);+ if (fixed) {+ elm.css({+ top: offset + "px"+ });+ }+ }+ }+ }+ } else {+ if (scroll > top) {+ fixed = true;+ css = {+ position: "fixed",+ top: offset+ };+ css.width = elm.css("box-sizing") === "border-box" ? elm.outerWidth() + "px" : elm.width() + "px";+ elm.css(css).addClass(sticky_class).after(spacer);+ if (el_float === "left" || el_float === "right") {+ spacer.append(elm);+ }+ elm.trigger("sticky_kit:stick");+ }+ }+ if (fixed) {+ if (will_bottom == null) {+ will_bottom = scroll + height + offset > parent_height + parent_top;+ }+ if (!bottomed && will_bottom) {+ bottomed = true;+ if (parent.css("position") === "static") {+ parent.css({+ position: "relative"+ });+ }+ return elm.css({+ position: "absolute",+ bottom: padding_bottom,+ top: "auto"+ }).trigger("sticky_kit:bottom");+ }+ }+ };+ recalc_and_tick = function() {+ recalc();+ return tick();+ };+ detach = function() {+ win.off("scroll", tick);+ $(document.body).off("sticky_kit:recalc", recalc_and_tick);+ elm.off("sticky_kit:detach", detach);+ elm.removeData("sticky_kit");+ elm.css({+ position: "",+ bottom: "",+ top: ""+ });+ parent.position("position", "");+ if (fixed) {+ elm.insertAfter(spacer).removeClass(sticky_class);+ return spacer.remove();+ }+ };+ win.on("touchmove", tick);+ win.on("scroll", tick);+ win.on("resize", recalc_and_tick);+ $(document.body).on("sticky_kit:recalc", recalc_and_tick);+ elm.on("sticky_kit:detach", detach);+ return setTimeout(tick, 0);+ };+ for (_i = 0, _len = this.length; _i < _len; _i++) {+ elm = this[_i];+ _fn($(elm));+ }+ return this;+ };++}).call(this);diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.javanew file mode 100644index 0000000000..3e99cc0141--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/ScrollBehavior.java@@ -0,0 +1,65 @@+package com.pmease.commons.wicket.behavior;++import org.apache.wicket.AttributeModifier;+import org.apache.wicket.Component;+import org.apache.wicket.behavior.Behavior;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;++@SuppressWarnings("serial")+public class ScrollBehavior extends Behavior {++ private final Component fixContainer;++ private final String selector;++ private final int margin;++ private final boolean forward;++ public ScrollBehavior(Component fixContainer, String selector, int margin, boolean forward) {+ fixContainer.setOutputMarkupId(true);+ this.fixContainer = fixContainer;+ this.selector = selector;+ this.margin = margin;+ this.forward = forward;+ }++ @Override+ public void bind(Component component) {+ super.bind(component);++ component.setOutputMarkupId(true);++ String function;+ if (forward)+ function = "next";+ else+ function = "prev";+ String script = String.format("pmease.commons.scroll.%s('%s', '%s', %d);",+ function, fixContainer.getMarkupId(), selector, margin);+ component.add(AttributeModifier.replace("onclick", script));+ }++ @Override+ public void renderHead(Component component, IHeaderResponse response) {+ super.renderHead(component, response);++ String function;+ if (forward)+ function = "getNext";+ else+ function = "getPrev";++ String script = String.format("$(window).scroll(function() {"+ + "var $component = $('#%s');"+ + "if (pmease.commons.scroll.%s('%s', '%s', %d) == null)"+ + " $component.attr('disabled', 'disabled');"+ + "else "+ + " $component.removeAttr('disabled');"+ + "})", component.getMarkupId(), function, fixContainer.getMarkupId(), selector, margin);++ response.render(OnDomReadyHeaderItem.forScript(script));+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/StickyBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/StickyBehavior.javanew file mode 100644index 0000000000..6957e7ead5--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/StickyBehavior.java@@ -0,0 +1,31 @@+package com.pmease.commons.wicket.behavior;++import org.apache.wicket.Component;+import org.apache.wicket.behavior.Behavior;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;++import com.pmease.commons.wicket.jquery.FunctionWithParams;++import de.agilecoders.wicket.jquery.JQuery;++@SuppressWarnings("serial")+public class StickyBehavior extends Behavior {++ @Override+ public void bind(Component component) {+ super.bind(component);+ component.setOutputMarkupId(true);+ }++ @Override+ public void renderHead(Component component, IHeaderResponse response) {+ super.renderHead(component, response);++ String script = JQuery.$(component)+ .chain(new FunctionWithParams("stick_in_parent"))+ .get();+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.htmlindex 8b5d006874..83ded71710 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html@@ -7,7 +7,8 @@</div><div class="pull-right"><span wicket:id="identical"><i class="fa fa-info-circle fa-lg"></i> <em>content is identical</em></span>- <span wicket:id="viewFull" class="fa fa-file-txt fa-lg action" title="View full file"></span>+ <span wicket:id="firstDiffBlock" class="fa fa-file-diff fa-lg action" title="Go to first difference block"></span>+ <span wicket:id="firstCommentLine" class="fa fa-comment fa-lg action" title="Go to first commented line"></span><span wicket:id="diffOptionsTrigger" class="fa fa-gear fa-lg action" title="Diff options"></span><div wicket:id="diffOptions"></div></div>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.htmlindex c8ff99b15b..8a107ca2d2 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html@@ -6,5 +6,147 @@<div wicket:id="comment"></div><input type="submit" value="Save" class="btn btn-primary dirty-aware"></input></form>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div class="panel panel-default">+ <div wicket:id="head" class="panel-heading">+ <a wicket:id="prev" class="btn btn-primary btn-sm">prev</a>+ <a wicket:id="next" class="btn btn-primary btn-sm">next</a>+ </div>+ <div class="panel-body">+ <div class="diff" style="background: red;">diff1</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div class="diff" style="background: red;">diff2</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div class="diff" style="background: red;">diff3</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div class="diff" style="background: red;">diff4</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div>hello world</div>+ <div class="diff" style="background: red;">diff5</div>+ <div>hello world</div>+ <div>hello world</div>+ </div>+ </div></div></wicket:extend>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.javaindex 1d6d575e7c..1b6970b6bd 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java@@ -10,6 +10,8 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;import com.pmease.commons.git.DiffTreeNode;import com.pmease.commons.hibernate.dao.Dao;+import com.pmease.commons.wicket.behavior.ScrollBehavior;+import com.pmease.commons.wicket.behavior.StickyBehavior;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.component.comment.CommentInput;@@ -76,6 +78,12 @@ public class TestPage extends BasePage {};form.add(new CommentInput("comment", new PropertyModel<String>(this, "comment")));add(form);++ WebMarkupContainer head = new WebMarkupContainer("head");+ head.add(new StickyBehavior());+ head.add(new WebMarkupContainer("prev").add(new ScrollBehavior(head, ".diff", 200, false)));+ head.add(new WebMarkupContainer("next").add(new ScrollBehavior(head, ".diff", 200, true)));+ add(head);}@Override