The Unified and Autonomous Development Platform
midwork
robin shine1a5f79fc437d
diff --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 91f3609184..944d8fc58a 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@@ -84,7 +84,6 @@ public class CommonResourceReference extends JavaScriptResourceReference {new WebjarsCssResourceReference("font-awesome/current/css/font-awesome.min.css")));dependencies.add(JavaScriptHeaderItem.forReference(AutoSizeResourceReference.INSTANCE));- dependencies.add(JavaScriptHeaderItem.forReference(Assets.ALIGN_JS));dependencies.add(JavaScriptHeaderItem.forReference(Assets.STICKY_JS));diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/Assets.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/Assets.javaindex f483225c3d..80e014b464 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/Assets.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/Assets.java@@ -11,9 +11,6 @@ public class Assets {public static final JavaScriptResourceReference STICKY_JS =new JavaScriptResourceReference(Assets.class, "jquery.sticky-kit.js");- public static final JavaScriptResourceReference ALIGN_JS =- new JavaScriptResourceReference(Assets.class, "jquery.align.js");-public static final JavaScriptResourceReference COMMON_JS =new JavaScriptResourceReference(Assets.class, "common.js");diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.javanew file mode 100644index 0000000000..894f8f5725--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/AlignResourceReference.java@@ -0,0 +1,15 @@+package com.pmease.commons.wicket.assets.align;++import org.apache.wicket.request.resource.JavaScriptResourceReference;++public class AlignResourceReference extends JavaScriptResourceReference {++ private static final long serialVersionUID = 1L;++ public static final AlignResourceReference INSTANCE = new AlignResourceReference();++ private AlignResourceReference() {+ super(AlignResourceReference.class, "jquery.align.js");+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.jsnew file mode 100644index 0000000000..5a7acc5dbb--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/align/jquery.align.js@@ -0,0 +1,143 @@+/*+ * 2014, Robin Shen+ */+(function ( $ ) {++ $.fn.align = function( alignment ) {++ jQuery("body").append(this);++ this.css("position", "absolute");++ var margin = 8;+ var borderTop = jQuery(window).scrollTop() + margin;+ var borderBottom = borderTop + jQuery(window).height() - 2*margin;+ var borderLeft = jQuery(window).scrollLeft() + margin;+ var borderRight = borderLeft + jQuery(window).width() - 2*margin;++ var width = this.outerWidth();+ var height = this.outerHeight();++ var left, top;+ var targetLeft, targetTop;+ var targetWidth, targetHeight;+ var offset = 0;++ if (alignment.offset)+ offset = alignment.offset;++ if (alignment.target instanceof jQuery || alignment.target instanceof HTMLElement) {+ var $targetEl = jQuery(alignment.target);+ targetLeft = $targetEl.offset().left;+ targetTop = $targetEl.offset().top;+ targetWidth = $targetEl.outerWidth();+ targetHeight = $targetEl.outerHeight();+ } else {+ targetLeft = alignment.target.left;+ targetTop = alignment.target.top;+ targetWidth = alignment.target.width;+ targetHeight = alignment.target.height;+ }++ var anchor = targetWidth*alignment.targetX/100.0 + targetLeft;+ left = anchor - alignment.x*width/100.0;+ if (alignment.targetX == 0 && alignment.x == 100)+ left -= offset;+ else if (alignment.targetX == 100 && alignment.x == 0)+ left += offset;++ if (left < borderLeft || left + width > borderRight) {+ // flip to see if width can fit into screen+ anchor = targetWidth*(100-alignment.targetX)/100.0 + targetLeft;+ left = anchor - (100 - alignment.x) * width / 100.0;++ if (alignment.targetX == 0 && alignment.x == 100)+ left += offset;+ else if (alignment.targetX == 100 && alignment.x == 0)+ left -= offset;++ if (left < borderLeft || left + width > borderRight) {+ // does not fit even flipped, so we revert back+ anchor = targetWidth*alignment.targetX/100.0 + targetLeft;+ left = anchor - alignment.x*width/100.0;+ if (alignment.targetX == 0 && alignment.x == 100)+ left -= offset;+ else if (alignment.targetX == 100 && alignment.x == 0)+ left += offset;+ }++ if (alignment.targetY==100 && alignment.y==0+ || alignment.targetY==0 && alignment.y==100) {+ if (left + width > borderRight)+ left = borderRight - width;+ if (left < borderLeft)+ left = borderLeft;+ }++ // last resort: resize element+ if (left + width > borderRight)+ width = borderRight - left;+ if (left < borderLeft) {+ left = borderLeft;+ width -= borderLeft - left;+ }+ }++ anchor = targetHeight*alignment.targetY/100.0 + targetTop;+ top = anchor - alignment.y*height/100.0;+ if (alignment.targetY == 0 && alignment.y == 100)+ top -= offset;+ else if (alignment.targetY == 100 && alignment.y == 0)+ top += offset;++ if (top < borderTop || top + height > borderBottom) {+ // flip to see if height can fit into screen+ anchor = targetHeight*(100-alignment.targetY)/100.0 + targetTop;+ top = anchor - (100 - alignment.y) * height / 100.0;++ if (alignment.targetY == 0 && alignment.y == 100)+ top += offset;+ else if (alignment.targetY == 100 && alignment.y == 0)+ top -= offset;++ if (top < borderTop || top + height> borderBottom) {+ // does not fit even flipped, so we revert back+ anchor = targetHeight*alignment.targetY/100.0 + targetTop;+ top = anchor - alignment.y*height/100.0;+ if (alignment.targetY == 0 && alignment.y == 100)+ top -= offset;+ else if (alignment.targetY == 100 && alignment.y == 0)+ top += offset;+ }++ if (alignment.targetX==100 && alignment.x==0+ || alignment.targetX==0 && alignment.x==100) {+ if (top + height > borderBottom)+ top = borderBottom - height;+ if (top < borderTop)+ top = borderTop;+ }++ // last resort: resize element+ if (top + height > borderBottom)+ height = borderBottom - top;+ if (top < borderTop) {+ top = borderTop;+ height -= borderTop - top;+ }+ }++ this.css({left:left, top:top});+ if (alignment.resizable) {+ var $resizable = this.find(alignment.resizable);+ $resizable.outerWidth(width - this.outerWidth() + $resizable.outerWidth());+ $resizable.outerHeight(height - this.outerHeight() + $resizable.outerHeight());+ $resizable.css({overflow: "auto"});+ } else {+ this.outerWidth(width).outerHeight(height).css({overflow: "auto"});+ }++ return this;+ };++}( jQuery ));diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/jquery.align.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/jquery.align.jsdeleted file mode 100644index feacbe4f84..0000000000--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/jquery.align.js+++ /dev/null@@ -1,95 +0,0 @@-/*- * 2014, Robin Shen- */-jQuery.fn.align = function(alignment) {- if (this.length == 0)- return this;-- // make sure position is absolute as otherwise width/height calculation- // below might be inaccurate- this.css("position", "absolute");-- if (alignment == undefined)- alignment = this.data("alignment");-- 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 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 (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/component/copyclipboard/CopyClipboard.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/CopyClipboard.javaindex 109177b5a0..ea77a10ecc 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/CopyClipboard.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/CopyClipboard.java@@ -32,7 +32,7 @@ public class CopyClipboard extends WebMarkupContainer {response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(CopyClipboard.class, "copy-clipboard.js")));- String script = String.format("gitplex.copyClipboard('%s');", getMarkupId(true));+ String script = String.format("pmease.commons.copyClipboard('%s');", getMarkupId(true));response.render(OnDomReadyHeaderItem.forScript(script));}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/copy-clipboard.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/copy-clipboard.jsindex bdb2ebffbe..b2d4fdb87f 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/copy-clipboard.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/copyclipboard/copy-clipboard.js@@ -1,4 +1,4 @@-gitplex.copyClipboard = function(bridgeId) {+pmease.commons.copyClipboard = function(bridgeId) {var $bridge = $('#' + bridgeId);var client = new ZeroClipboard($bridge);client.on('ready', function(e) {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/Alignment.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/Alignment.javanew file mode 100644index 0000000000..59f74662fa--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/Alignment.java@@ -0,0 +1,43 @@+package com.pmease.commons.wicket.component.floating;++import java.io.Serializable;++public class Alignment implements Serializable {++ private static final long serialVersionUID = 1L;++ private final int targetX, targetY;++ private final int x, y;++ private final int offset;++ public Alignment(int targetX, int targetY, int x, int y, int offset) {+ this.targetX = targetX;+ this.targetY = targetY;+ this.x = x;+ this.y = y;+ this.offset = offset;+ }++ public int getTargetX() {+ return targetX;+ }++ public int getTargetY() {+ return targetY;+ }++ public int getX() {+ return x;+ }++ public int getY() {+ return y;+ }++ public int getOffset() {+ return offset;+ }++}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.htmlnew file mode 100644index 0000000000..d4947ecbb1--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.html@@ -0,0 +1,5 @@+<wicket:panel>+ <div class="floating">+ <div wicket:id="content" class="content"></div>+ </div>+</wicket:panel>\ No newline at end of filediff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.javanew file mode 100644index 0000000000..243f25b5c9--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/FloatingPanel.java@@ -0,0 +1,71 @@+package com.pmease.commons.wicket.component.floating;++import org.apache.wicket.Component;+import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;+import org.apache.wicket.ajax.AjaxRequestTarget;+import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;+import org.apache.wicket.markup.html.panel.Panel;+import org.apache.wicket.model.IModel;++import com.fasterxml.jackson.core.JsonProcessingException;+import com.fasterxml.jackson.databind.ObjectMapper;+import com.pmease.commons.loader.AppLoader;++@SuppressWarnings("serial")+public abstract class FloatingPanel extends Panel {++ private final Component target;++ private final Alignment alignment;++ public FloatingPanel(String id, Component target, Alignment alignment) {+ super(id);++ this.target = target;+ this.alignment = alignment;+ }++ public FloatingPanel(String id, IModel<?> model, Component target, Alignment alignment) {+ super(id, model);++ this.target = target;+ this.alignment = alignment;+ }++ @Override+ protected void onInitialize() {+ super.onInitialize();++ add(newContent("content"));++ add(new AbstractDefaultAjaxBehavior() {++ @Override+ protected void respond(AjaxRequestTarget target) {+ FloatingPanel.this.remove();+ }++ @Override+ public void renderHead(Component component, IHeaderResponse response) {+ super.renderHead(component, response);++ ObjectMapper mapper = AppLoader.getInstance(ObjectMapper.class);+ String alignmentJson;+ try {+ alignmentJson = mapper.writeValueAsString(alignment);+ } catch (JsonProcessingException e) {+ throw new RuntimeException(e);+ }++ String script = String.format("pmease.commons.floating.init('%s', '%s', %s, %s);",+ getMarkupId(true), target.getMarkupId(true), alignmentJson, getCallbackFunction());+ response.render(OnDomReadyHeaderItem.forScript(script));+ }++ });+ }++ protected abstract Component newContent(String id);++}\ No newline at end of filediff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.cssnew file mode 100644index 0000000000..1cef5becd6--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.css@@ -0,0 +1,14 @@+.floating {+ background-clip: padding-box;+ background-color: #FFF;+ border: 1px solid rgba(0, 0, 0, 0.2);+ border-radius: 4px;+ box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);+ position: absolute;+ z-index: 2000;+ padding: 8px;+}+.floating>.content {+ margin: 0;+ padding: 0;+}diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.jsnew file mode 100644index 0000000000..1e52db96ca--- /dev/null+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/floating/floating.js@@ -0,0 +1,58 @@+pmease.commons.floating = {+ init: function(floatingId, targetId, alignment, callback) {+ var $floating = $("#" + floatingId);+ var $target = $("#" + targetId);+ $target.addClass("alignment-target");++ alignment.target = $target;+ alignment.resizable = ">.content";+ $floating.data("alignment", alignment);+ $floating.align(alignment);++ $floating.data("mouseUpOrTouchStart") = function(e) {+ if (!$floating.is(e.target) // if the target of the click isn't the container...+ && $floating.has(e.target).length === 0) { // ... nor a descendant of the container+ pmease.commons.floating.close(floatingId, callback);+ }+ };+ $(document).on("mouseup touchstart", $floating.data("mouseUpOrTouchStart"));++ $floating.data("keydown") = function(e) {+ if (e.keyCode == 27) { // esc+ if ($(".select2-drop:visible").length == 0) {+ var topmostPopup = $("body>.popup:visible:last");+ if (topmostPopup[0]) {+ if (topmostPopup.hasClass("modal")) {+ if (!topmostPopup[0].confirm)+ pmease.commons.modal.hide(topmostPopup[0].id);+ else+ topmostPopup.modal("hide").remove();+ }+ if (topmostPopup.hasClass("dropdown-panel"))+ pmease.commons.dropdown.hide(topmostPopup[0].id);+ }+ }+ } else if (e.keyCode == 13) {+ var topmostPopup = $("body>.popup:visible:last");+ if (topmostPopup[0] && topmostPopup[0].confirm) {+ topmostPopup[0].confirm.callback();+ topmostPopup.modal("hide").remove();+ }+ }+ }++ // use keydown as keypress does not work in chrome/safari+ $(document).on("keydown", $floating.data("keydown"));+ },++ close: function(floatingId, callback) {+ var $floating = $("#" + floatingId);++ $(document).off("mouseup touchstart", $floating.data("mouseUpOrTouchStart"));+ $(document).off("keydown", $floating.data("keydown"));++ $floating.remove();+ if (callback)+ callback();+ }+}\ No newline at end of filediff --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 795b443f3a..0ebdd7cb2a 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,3 +1,20 @@<wicket:extend>- <a wicket:id="test">test</a>+ <a wicket:id="test" class="target"+ style="border: 1px solid red; position: absolute; left: 1000px; top: 100px">test</a>+ <div class="float" style="border: 1px solid rgba(0, 0, 0, 0.2); box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);padding: 20px;">+ <div class="content" style="border: 1px solid green;">+ <div style="width: 600px; height: 600px;"></div>+ </div>+ </div>+ <script type="text/javascript">+ $(".float").align({+ target: $(".target"),+ targetX: 0,+ x: 0,+ targetY: 100,+ y: 0,+ offset: 10,+ resizable: ".content"+ });+ </script></wicket:extend>\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.javaindex 6a784f6760..2a6bc5d7d1 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.java@@ -1,8 +1,10 @@package com.pmease.gitplex.web.page.test;import org.apache.wicket.markup.head.IHeaderResponse;+import org.apache.wicket.markup.head.JavaScriptHeaderItem;import org.apache.wicket.markup.html.link.Link;+import com.pmease.commons.wicket.assets.align.AlignResourceReference;import com.pmease.gitplex.web.page.base.BasePage;@SuppressWarnings("serial")@@ -25,6 +27,7 @@ public class TestPage extends BasePage {public void renderHead(IHeaderResponse response) {super.renderHead(response);+ response.render(JavaScriptHeaderItem.forReference(AlignResourceReference.INSTANCE));}}