The Unified and Autonomous Development Platform
Abstract selection popup into a jquery plugin
robin shined560f8adf828
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.cssindex 42e0136576..6a0a0c851b 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.css+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.css@@ -1,466 +1,437 @@-/**************************************************************- * This file defines common css styles for PMEase products.- *- **************************************************************/--/* CURSORS */-.pointer {- cursor: pointer;-}--/* TEXT AREA */-textarea {- max-height: 600px;-}--/* TOOLTIPS */-.tooltip-inner {- max-width: 400px;-}-.tooltip .tooltip-inner {- text-align: left;-}-.tooltip .tooltip-inner dl dt {- font-size: 15px;-}-.tooltip .tooltip-inner dl {- margin-bottom: 0;-}--/* FEEDBACK */-#session-feedback {- position:absolute;- max-width:75%;- padding: 6px 12px;- z-index:10000;- border-radius:0 0 4px 4px;- border: 1px solid;- border-top: none;- display: none;-}-#session-feedback.success {- background: #DFF0D8;- color: #3C763D;- border-color: #D6E9C6;-}-#session-feedback.error {- background: #F2DEDE;- color: #A94442;- border-color: #EBCCD1;-}-#session-feedback.warning {- background: #FCF8E3;- color: #8A6D3B;- border-color: #FAEBCC;-}-#session-feedback.info {- background: #D9EDF7;- color: #31708F;- border-color: #BCE8F1;-}-#session-feedback ul {- padding: 0; margin: 0;-}-#session-feedback li {- list-style: none;-}--.noselect {- -webkit-touch-callout: none;- -webkit-user-select: none;- -khtml-user-select: none;- -moz-user-select: none;- -ms-user-select: none;- user-select: none;-}--/* Table navigator */-table .navigator {- border-radius: 4px 4px 4px 4px;- margin-bottom: 0px;- margin-left: 0;- float: right;-}-table thead .navigatorLabel, table tfoot .navigatorLabel {- padding-top: 2px;- padding-right: 8px;- float: left;-}-table thead tr.navigation td, table tfoot tr.navigation td {- vertical-align: middle;- padding-top: 12px;- text-align: right;- min-width: 500px;-}-table .navigator>div a, table .navigator>div em {- -moz-border-bottom-colors: none;- -moz-border-left-colors: none;- -moz-border-right-colors: none;- -moz-border-top-colors: none;- background-color: #FFFFFF;- border-color: #DDDDDD;- border-image: none;- border-style: solid;- border-width: 1px 1px 1px 0;- line-height: 18px;- padding: 4px 8px;- text-decoration: none;- float: left;-}-table .navigator>div .first em, table .navigator>div a.first {- border-bottom-left-radius: 4px;- border-left-width: 1px;- border-top-left-radius: 4px;-}-table .navigator>div .last em, table .navigator>div a.last {- border-bottom-right-radius: 4px;- border-top-right-radius: 4px;-}-table .navigator>div em {- font-style: normal;- cursor: default;-}-table .navigator>div .first, table .navigator>div .last, table .navigator>div .prev, table .navigator>div .next {- font-family: monospace inherit;-}-table .navigator>div a:hover, table .navigator>div a:focus,-table .navigator>div em:hover, table .navigator>div em:focus,-table .navigator>div .goto em {- background-color: #F5F5F5;-}-table .navigator>div .goto em, table .navigator>div>span>em {- color: #999999;- cursor: default;-}-table .navigator>div>span>em, table .navigator>div>span>em:hover, table .navigator>div>span>em:focus {- background-color: transparent;-}-table .row-selector {- width: 24px;-}--/* TABLE SORTER */-a.wicket_orderUp:after, a.wicket_orderDown:after, a.wicket_orderNone:after {- font-family: FontAwesome;- font-weight: normal;- font-style: normal;- text-decoration: none;- display: inline-block;- color: #666;- margin-left: 8px;-}--a.wicket_orderUp:AFTER {- content: "\f062";-}-a.wicket_orderDown:AFTER {- content: "\f063";-}--.pagination {- margin: 0;-}-.pagination em {- font-style: normal;-}-.pagination .first, .pagination .last, .pagination .prev, .pagination .next {- font-family: monospace inherit;-}-.pagination>li>span>em {- color: #BBB;-}-.pagination>li.active>span>em {- color: white;-}--/* TREE */-.tree-theme-windows .tree-node span.tree-content a {- color: #444444;-}-.tree-content {- white-space: nowrap;-}--/* Tabs */-.tabbable>.tab-content {- padding-top: 16px;-}--/* Forms */-form .required {- font-size: 16px;- color: #B94A48;-}-form .form-group ul.feedbackPanel, form td.value ul.feedbackPanel {- margin: 4px 0 0 -8px;- padding-bottom: 0;-}-form .form-group li.feedbackPanelERROR, form td.value li.feedbackPanelERROR {- color: #AA0000;- list-style: disc;-}-form>.test-feedback {- margin-top: 16px;-}--.help-block {- font-size: 13px;-}--/* Editor and Viewer */-.editable table.list {- margin-bottom: 0;-}-.editable table.list>tbody>tr>td, .editable table.list>tfoot>tr>td {- border-top-style: dotted;- border-top-width: 2px;-}-.editable table.list>tfoot>tr.add-element>td {- border-bottom: 2px dotted #DDD;- padding: 0;-}-.editable table.list>tfoot>tr.add-element>td>a {- display: block;- text-decoration: none;- padding: 4px 8px;-}--.editable table.list>tbody>tr.no-elements>td {- font-style: italic;-}-.editable table.list>tbody>tr.no-elements>td:hover {- background: inherit;-}-.editable table.list>tfoot>tr.add-element>td:hover {- background-color: #F2F2F2;-}--.editable>.reflection>table {- width: 100%;-}-.editable>.reflection>table>tbody>tr>td {- vertical-align: top;-}-.editable>.reflection>table>tbody>tr>td {- padding: 10px;-}-.editable>.reflection>table>tbody>tr>td.name {- font-weight: bold;- font-size: 13px;- background: #F0F0F0;- text-align: right;- white-space: nowrap;- width: 20%;-}-.editable>.reflection>table>tbody>tr:first-child>td.name {- border-radius: 4px 4px 0 0;-}-.editable>.reflection>table>tbody>tr:last-child>td.name {- border-radius: 0 0 4px 4px;-}-.editable>.reflection>table>tbody>tr:first-child:last-child>td.name {- border-radius: 4px;-}--.editor>.reflection.properties>div.form-group:last-child {- margin-bottom: 0;-}--.editable>table.polymorphic.vertical.list>tbody>tr>td>.type-selector {- margin-bottom: 8px;-}-.editable>.polymorphic.vertical>div.type-selector {- margin-bottom: 8px;-}--.editable>.polymorphic.horizontal>table {- width: 100%;-}-.editable>.polymorphic.horizontal>table>tbody>tr>td {- vertical-align: top;-}-.editable>.polymorphic.horizontal>table>tbody>tr>td:first-child {- padding-right: 8px;-}--.editor>table.list .help-block {- display: none;-}--.editor>table.concrete.list>tbody>tr>td.actions {- width: 76px;-}-.editor>table.concrete.list>tbody>tr>td.actions a {- margin-right: 8px;-}-.editor>table.list>tbody>tr>td.actions .handle {- color: #666;- cursor: move;- font-size: 22px;- margin-top: 4px;-}-.editor>table.list .sort-helper {- border: 2px solid #DDD;- background: #F5F5F5;-}--.editor>input.enable {- margin-bottom: 12px;-}--.editor .password-confirm {- margin-top: 12px;-}--.viewer .reflection>table>tbody>tr.name-omitted>td {- padding: 0;-}-.viewer .type-selector {- font-style: italic;-}--/* Select2 */-.editor .select2-container {- width: 100%;-}-.input-group .select2-container.form-control .select2-choice,-.input-group .select2-container.form-control .select2-choices {- border-radius: 0 4px 4px 0;-}--/* Ajax Loading Indicator */-#ajax-loading-indicator {- position: fixed;- top: 0;- left: 50%;- display:none;- z-index: 10000;-}-#ajax-loading-indicator>div {- position:relative;- left:-50%;- top:0;- text-align:center;- font-weight: bold;- width:95px;- background: #FAF3D0;- color: #8A6D3B;- border: 2px solid #F6DBA4;- border-top:none;- padding:6px 12px;- border-radius:0 0 4px 4px;-}--.working-indicator {- color: #25A305;- margin-left: 4px;-}--/* Ajax Loading Overlay */-#ajax-loading-overlay {- z-index:1;- display: none;-}-#ajax-loading-overlay>div {- bottom: 0;- left: 0;- position: fixed;- right: 0;- top: 0;- z-index: 1000000;- filter:alpha(opacity=0); /* Only applies to IE */- background: white; /* This will be overwritten by browsers that support rgba */- background: rgba(255,255,255,0.0); /* IE ignores this since it's not supported */-}--/* ICONS */-span.add.icon {- padding: 12px;- background: url("add.png") no-repeat 50% 50%;-}-span.delete.icon {- padding: 12px;- background: url("delete.png") no-repeat 50% 50%;-}-span.move.icon {- padding: 12px;- background: url("move.png") no-repeat 50% 50%;-}--/* BACK TO TOP */-.back-to-top {- position: fixed;- right: 20px;- bottom: 40px;- cursor: pointer;- padding: 25px;- background: url("back-to-top.png") no-repeat 0 0; z-index: 100; opacity: 0.8;-}--/* WEB SOCKET ERROR */-#websocket-error {- display: none;- position: fixed;- left: 50%;- top: 0;- background: #f2dede;- border: 1px solid #ebccd1;- color: #a94442;- padding: 4px 8px;- margin-left: -120px;-}-#websocket-error span {- width: 16px;- height: 16px;- background: url("error.png") 0 0 no-repeat;-}--/* FILE INPUT */-.btn-file {- position: relative;- overflow: hidden;-}-.btn-file input[type=file] {- position: absolute;- top: 0;- right: 0;- min-width: 100%;- min-height: 100%;- font-size: 100px;- text-align: right;- filter: alpha(opacity=0);- opacity: 0;- outline: none;- background: white;- cursor: inherit;- display: block;-}--/* Selection popup */-#selection-popup {- z-index: 10000;- position: absolute;- display: none;-}-#selection-popup>.content {- background: #333;- border-radius: 6px;- padding: 12px;-}-#selection-popup>.content a {- color: white;- display: block;- white-space: nowrap;-}-#selection-popup>.content>a.permanent {- margin-bottom: 8px;-}-#selection-popup>.triangle {- position: relative;- left: 50%;- width: 0;- height: 0;- border-left: 6px solid transparent;- border-right: 6px solid transparent;- border-top: 6px solid #333;-}\ No newline at end of file+/**************************************************************+ * This file defines common css styles for PMEase products.+ *+ **************************************************************/++/* CURSORS */+.pointer {+ cursor: pointer;+}++/* TEXT AREA */+textarea {+ max-height: 600px;+}++/* TOOLTIPS */+.tooltip-inner {+ max-width: 400px;+}+.tooltip .tooltip-inner {+ text-align: left;+}+.tooltip .tooltip-inner dl dt {+ font-size: 15px;+}+.tooltip .tooltip-inner dl {+ margin-bottom: 0;+}++/* FEEDBACK */+#session-feedback {+ position:absolute;+ max-width:75%;+ padding: 6px 12px;+ z-index:10000;+ border-radius:0 0 4px 4px;+ border: 1px solid;+ border-top: none;+ display: none;+}+#session-feedback.success {+ background: #DFF0D8;+ color: #3C763D;+ border-color: #D6E9C6;+}+#session-feedback.error {+ background: #F2DEDE;+ color: #A94442;+ border-color: #EBCCD1;+}+#session-feedback.warning {+ background: #FCF8E3;+ color: #8A6D3B;+ border-color: #FAEBCC;+}+#session-feedback.info {+ background: #D9EDF7;+ color: #31708F;+ border-color: #BCE8F1;+}+#session-feedback ul {+ padding: 0; margin: 0;+}+#session-feedback li {+ list-style: none;+}++.noselect {+ -webkit-touch-callout: none;+ -webkit-user-select: none;+ -khtml-user-select: none;+ -moz-user-select: none;+ -ms-user-select: none;+ user-select: none;+}++/* Table navigator */+table .navigator {+ border-radius: 4px 4px 4px 4px;+ margin-bottom: 0px;+ margin-left: 0;+ float: right;+}+table thead .navigatorLabel, table tfoot .navigatorLabel {+ padding-top: 2px;+ padding-right: 8px;+ float: left;+}+table thead tr.navigation td, table tfoot tr.navigation td {+ vertical-align: middle;+ padding-top: 12px;+ text-align: right;+ min-width: 500px;+}+table .navigator>div a, table .navigator>div em {+ -moz-border-bottom-colors: none;+ -moz-border-left-colors: none;+ -moz-border-right-colors: none;+ -moz-border-top-colors: none;+ background-color: #FFFFFF;+ border-color: #DDDDDD;+ border-image: none;+ border-style: solid;+ border-width: 1px 1px 1px 0;+ line-height: 18px;+ padding: 4px 8px;+ text-decoration: none;+ float: left;+}+table .navigator>div .first em, table .navigator>div a.first {+ border-bottom-left-radius: 4px;+ border-left-width: 1px;+ border-top-left-radius: 4px;+}+table .navigator>div .last em, table .navigator>div a.last {+ border-bottom-right-radius: 4px;+ border-top-right-radius: 4px;+}+table .navigator>div em {+ font-style: normal;+ cursor: default;+}+table .navigator>div .first, table .navigator>div .last, table .navigator>div .prev, table .navigator>div .next {+ font-family: monospace inherit;+}+table .navigator>div a:hover, table .navigator>div a:focus,+table .navigator>div em:hover, table .navigator>div em:focus,+table .navigator>div .goto em {+ background-color: #F5F5F5;+}+table .navigator>div .goto em, table .navigator>div>span>em {+ color: #999999;+ cursor: default;+}+table .navigator>div>span>em, table .navigator>div>span>em:hover, table .navigator>div>span>em:focus {+ background-color: transparent;+}+table .row-selector {+ width: 24px;+}++/* TABLE SORTER */+a.wicket_orderUp:after, a.wicket_orderDown:after, a.wicket_orderNone:after {+ font-family: FontAwesome;+ font-weight: normal;+ font-style: normal;+ text-decoration: none;+ display: inline-block;+ color: #666;+ margin-left: 8px;+}++a.wicket_orderUp:AFTER {+ content: "\f062";+}+a.wicket_orderDown:AFTER {+ content: "\f063";+}++.pagination {+ margin: 0;+}+.pagination em {+ font-style: normal;+}+.pagination .first, .pagination .last, .pagination .prev, .pagination .next {+ font-family: monospace inherit;+}+.pagination>li>span>em {+ color: #BBB;+}+.pagination>li.active>span>em {+ color: white;+}++/* TREE */+.tree-theme-windows .tree-node span.tree-content a {+ color: #444444;+}+.tree-content {+ white-space: nowrap;+}++/* Tabs */+.tabbable>.tab-content {+ padding-top: 16px;+}++/* Forms */+form .required {+ font-size: 16px;+ color: #B94A48;+}+form .form-group ul.feedbackPanel, form td.value ul.feedbackPanel {+ margin: 4px 0 0 -8px;+ padding-bottom: 0;+}+form .form-group li.feedbackPanelERROR, form td.value li.feedbackPanelERROR {+ color: #AA0000;+ list-style: disc;+}+form>.test-feedback {+ margin-top: 16px;+}++.help-block {+ font-size: 13px;+}++/* Editor and Viewer */+.editable table.list {+ margin-bottom: 0;+}+.editable table.list>tbody>tr>td, .editable table.list>tfoot>tr>td {+ border-top-style: dotted;+ border-top-width: 2px;+}+.editable table.list>tfoot>tr.add-element>td {+ border-bottom: 2px dotted #DDD;+ padding: 0;+}+.editable table.list>tfoot>tr.add-element>td>a {+ display: block;+ text-decoration: none;+ padding: 4px 8px;+}++.editable table.list>tbody>tr.no-elements>td {+ font-style: italic;+}+.editable table.list>tbody>tr.no-elements>td:hover {+ background: inherit;+}+.editable table.list>tfoot>tr.add-element>td:hover {+ background-color: #F2F2F2;+}++.editable>.reflection>table {+ width: 100%;+}+.editable>.reflection>table>tbody>tr>td {+ vertical-align: top;+}+.editable>.reflection>table>tbody>tr>td {+ padding: 10px;+}+.editable>.reflection>table>tbody>tr>td.name {+ font-weight: bold;+ font-size: 13px;+ background: #F0F0F0;+ text-align: right;+ white-space: nowrap;+ width: 20%;+}+.editable>.reflection>table>tbody>tr:first-child>td.name {+ border-radius: 4px 4px 0 0;+}+.editable>.reflection>table>tbody>tr:last-child>td.name {+ border-radius: 0 0 4px 4px;+}+.editable>.reflection>table>tbody>tr:first-child:last-child>td.name {+ border-radius: 4px;+}++.editor>.reflection.properties>div.form-group:last-child {+ margin-bottom: 0;+}++.editable>table.polymorphic.vertical.list>tbody>tr>td>.type-selector {+ margin-bottom: 8px;+}+.editable>.polymorphic.vertical>div.type-selector {+ margin-bottom: 8px;+}++.editable>.polymorphic.horizontal>table {+ width: 100%;+}+.editable>.polymorphic.horizontal>table>tbody>tr>td {+ vertical-align: top;+}+.editable>.polymorphic.horizontal>table>tbody>tr>td:first-child {+ padding-right: 8px;+}++.editor>table.list .help-block {+ display: none;+}++.editor>table.concrete.list>tbody>tr>td.actions {+ width: 76px;+}+.editor>table.concrete.list>tbody>tr>td.actions a {+ margin-right: 8px;+}+.editor>table.list>tbody>tr>td.actions .handle {+ color: #666;+ cursor: move;+ font-size: 22px;+ margin-top: 4px;+}+.editor>table.list .sort-helper {+ border: 2px solid #DDD;+ background: #F5F5F5;+}++.editor>input.enable {+ margin-bottom: 12px;+}++.editor .password-confirm {+ margin-top: 12px;+}++.viewer .reflection>table>tbody>tr.name-omitted>td {+ padding: 0;+}+.viewer .type-selector {+ font-style: italic;+}++/* Select2 */+.editor .select2-container {+ width: 100%;+}+.input-group .select2-container.form-control .select2-choice,+.input-group .select2-container.form-control .select2-choices {+ border-radius: 0 4px 4px 0;+}++/* Ajax Loading Indicator */+#ajax-loading-indicator {+ position: fixed;+ top: 0;+ left: 50%;+ display:none;+ z-index: 10000;+}+#ajax-loading-indicator>div {+ position:relative;+ left:-50%;+ top:0;+ text-align:center;+ font-weight: bold;+ width:95px;+ background: #FAF3D0;+ color: #8A6D3B;+ border: 2px solid #F6DBA4;+ border-top:none;+ padding:6px 12px;+ border-radius:0 0 4px 4px;+}++.working-indicator {+ color: #25A305;+ margin-left: 4px;+}++/* Ajax Loading Overlay */+#ajax-loading-overlay {+ z-index:1;+ display: none;+}+#ajax-loading-overlay>div {+ bottom: 0;+ left: 0;+ position: fixed;+ right: 0;+ top: 0;+ z-index: 1000000;+ filter:alpha(opacity=0); /* Only applies to IE */+ background: white; /* This will be overwritten by browsers that support rgba */+ background: rgba(255,255,255,0.0); /* IE ignores this since it's not supported */+}++/* ICONS */+span.add.icon {+ padding: 12px;+ background: url("add.png") no-repeat 50% 50%;+}+span.delete.icon {+ padding: 12px;+ background: url("delete.png") no-repeat 50% 50%;+}+span.move.icon {+ padding: 12px;+ background: url("move.png") no-repeat 50% 50%;+}++/* BACK TO TOP */+.back-to-top {+ position: fixed;+ right: 20px;+ bottom: 40px;+ cursor: pointer;+ padding: 25px;+ background: url("back-to-top.png") no-repeat 0 0; z-index: 100; opacity: 0.8;+}++/* WEB SOCKET ERROR */+#websocket-error {+ display: none;+ position: fixed;+ left: 50%;+ top: 0;+ background: #f2dede;+ border: 1px solid #ebccd1;+ color: #a94442;+ padding: 4px 8px;+ margin-left: -120px;+}+#websocket-error span {+ width: 16px;+ height: 16px;+ background: url("error.png") 0 0 no-repeat;+}++/* FILE INPUT */+.btn-file {+ position: relative;+ overflow: hidden;+}+.btn-file input[type=file] {+ position: absolute;+ top: 0;+ right: 0;+ min-width: 100%;+ min-height: 100%;+ font-size: 100px;+ text-align: right;+ filter: alpha(opacity=0);+ opacity: 0;+ outline: none;+ background: white;+ cursor: inherit;+ display: block;+}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 0b9803d183..b2d83780ec 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@@ -451,37 +451,6 @@ pmease.commons = {|| ua.indexOf("iphone") != -1|| ua.indexOf("ipad") != -1|| ua.indexOf("windows phone") != -1;- },- setupSelectionPopup: function() {- $("body").append("" +- "<div id='selection-popup'>" +- "<div class='content'>" +- "<a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>" +- "<a class='comment'><i class='fa fa-comment'></i> Add comment for this selection</a>" +- "</div>" +- "<div class='triangle'></div>" +- "</div>");-- var $selectionPopup = $("#selection-popup");- $selectionPopup.data("open", function(position, permanentCallback, commentCallback, containerEl) {- var alignment = {- target: {left: position.left, top: position.top, width: 0, height: 0},- placement: {x: 50, y: 100, targetX: 0, targetY: 0}};- $selectionPopup.find(".triangle").show();- $selectionPopup.show().align(alignment);- if (Math.abs($selectionPopup.offset().top+$selectionPopup.outerHeight() - position.top)>10) {- $selectionPopup.find(".triangle").hide();- }- permanentCallback($selectionPopup.find(".permanent"));- commentCallback($selectionPopup.find(".comment"));- $selectionPopup.data("container", containerEl);- });- Wicket.Event.subscribe('/ajax/call/complete', function() {- if (!jQuery.contains(document, $selectionPopup.data("container"))) {- $selectionPopup.hide();- }- });-}};@@ -491,5 +460,4 @@ $(function() {pmease.commons.form.setupDirtyCheck();pmease.commons.focus.setupAutoFocus();pmease.commons.websocket.setupCallback();- pmease.commons.setupSelectionPopup();});diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.cssindex 73430a2f67..cf3a763a49 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.css@@ -8,12 +8,12 @@border-radius: 6px;padding: 12px;}-.selection-popover>.content a {+.selection-popover>.content a, .selection-popover>.content span {color: white;display: block;white-space: nowrap;}-.selection-popover>.content>a.permanent {+.selection-popover>.content a:FIRST-CHILD {margin-bottom: 8px;}.selection-popover>.triangle {diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.jsindex d73a07e36d..ab800d13e0 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/selectionpopover/jquery.selectionpopover.js@@ -1,6 +1,6 @@(function ( $ ) {- $.fn.selectionPopover = function(callback) {+ $.fn.selectionPopover = function(action, options) {var $container = jQuery(this);function popover(options) {@@ -14,39 +14,61 @@"<div class='content'></div>" +"<div class='triangle'></div>" +"</div>");- $popover.append(options.content);+ $popover.children(".content").append(options.content);$("body").append($popover);+ $popover.data("container", $container[0]);var alignment = {target: {left: options.position.left, top: options.position.top, width: 0, height: 0},placement: {x: 50, y: 100, targetX: 0, targetY: 0}};$popover.children(".triangle").show();$popover.show().align(alignment);- if (Math.abs($popover.offset().top+$popover.outerHeight() - position.top)>10) {+ if (Math.abs($popover.offset().top+$popover.outerHeight() - options.position.top)>10) {$popover.children(".triangle").hide();}- /*- Wicket.Event.subscribe('/ajax/call/complete', function() {- if (!jQuery.contains(document, $container[0])) {- $popover.remove();- }- });- */$container.data("selectionPopover", $popover[0]);}}- $container.on("mouseup", function() {- popover(callback());- });- $container.on("keyup", function(e) {- if (e.which == 37 || e.which == 38 || e.which == 39 || e.which == 40) {- popover(callback());- }- });+ if (action == "init") {+ $container.on("mouseup", function() {+ // use a timeout to make sure selection remains stable after mouse or keyboard action+ setTimeout(function() {+ popover(options());+ }, 100);+ });+ $container.on("keyup", function(e) {+ if (e.which == 37 || e.which == 38 || e.which == 39 || e.which == 40) {+ // use a timeout to make sure selection remains stable after mouse or keyboard action+ setTimeout(function() {+ popover(options());+ }, 100);+ }+ });+ } else if (action == "open") {+ popover(options);+ } else {+ popover();+ }return this;};}( jQuery ));++$(function() {+ Wicket.Event.subscribe('/ajax/call/complete', function() {+ $("body>.selection-popover").each(function() {+ var $popover = $(this);+ if (!jQuery.contains(document, $popover.data("container"))) {+ $popover.remove();+ }+ });+ });+ $(document).keydown(function(e) {+ if (e.keyCode == 27) {+ $("body>.selection-popover").remove();+ }+ });+});\ No newline at end of filediff --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 849f35b6bb..8aa772150a 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@@ -64,6 +64,7 @@ import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;import com.pmease.commons.wicket.assets.jqueryui.JQueryUIResourceReference;+import com.pmease.commons.wicket.assets.selectionpopover.SelectionPopoverResourceReference;import com.pmease.commons.wicket.behavior.ViewStateAwareBehavior;import com.pmease.commons.wicket.component.PreventDefaultAjaxLink;import com.pmease.commons.wicket.component.menu.MenuItem;@@ -348,9 +349,9 @@ public class SourceViewPanel extends BlobViewPanel {IRequestParameters params = RequestCycle.get().getRequest().getQueryParameters();switch(params.getParameterValue("action").toString()) {- case "openSelectionPopup":+ case "openSelectionPopover":Mark mark = getMark(params, "param1", "param2", "param3", "param4");- String script = String.format("gitplex.sourceview.openSelectionPopup(%s, '%s', %s);",+ String script = String.format("gitplex.sourceview.openSelectionPopover(%s, '%s', %s);",mark.toJson(), context.getMarkUrl(mark),SecurityUtils.getAccount()!=null);target.appendJavaScript(script);@@ -706,6 +707,7 @@ public class SourceViewPanel extends BlobViewPanel {super.renderHead(response);response.render(JavaScriptHeaderItem.forReference(JQueryUIResourceReference.INSTANCE));+ response.render(JavaScriptHeaderItem.forReference(SelectionPopoverResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(CookiesResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(CodeMirrorResourceReference.INSTANCE));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 ca9cbb6988..0b2845a669 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@@ -116,27 +116,16 @@ gitplex.sourceview = {gitplex.sourceview.highlightCommentTrigger();}, 10);- function onSelectText() {+ $code.selectionPopover("init", function() {if (cm.hasFocus()) {var from = cm.getCursor("from");var to = cm.getCursor("to");if (from.line != to.line || from.ch != to.ch) {- markCallback("openSelectionPopup", from.line, from.ch, to.line, to.ch);- } else {- $("#selection-popup").hide();+ markCallback("openSelectionPopover", from.line, from.ch, to.line, to.ch);}}- }-- $code.on("mouseup", function() {- onSelectText();- });- $code.on("keyup", function(e) {- if (e.which == 37 || e.which == 38 || e.which == 39 || e.which == 40) {- onSelectText();- }});-+$code.mouseover(function(e) {var node = e.target || e.srcElement, $node = $(node);if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")@@ -292,32 +281,31 @@ gitplex.sourceview = {}cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);},- openSelectionPopup: function(mark, markUrl, loggedIn) {+ openSelectionPopover: function(mark, markUrl, loggedIn) {var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var $sourceView = $(".source-view");- var markCallback = $sourceView.data("markCallback");var ch = (mark.beginChar + mark.endChar)/2;var position = cm.charCoords({line:mark.beginLine, ch:ch});- var permanentLinkCallback = function($permanentLink) {- $permanentLink.attr("href", markUrl);- };- var commentLinkCallback = function($commentLink) {- $commentLink.off("click");- if (loggedIn) {- $commentLink.html("<i class='fa fa-comment'></i> Add comment of this selection");- $commentLink.click(function() {- if ($sourceView.find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);- });- } else {- $commentLink.html("Log in to comment on selection");- }- };- $("#selection-popup").data("open")(- position, permanentLinkCallback, commentLinkCallback, $(".source-view>.code")[0]);++ var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");+ $content.children("a.permanent").attr("href", markUrl);+ if (loggedIn) {+ $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");+ $content.children("a.comment").click(function() {+ if ($(".source-view").find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var markCallback = $(".source-view").data("markCallback");+ markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);+ });+ } else {+ $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");+ }++ $(".source-view>.code").selectionPopover("open", {+ position: position,+ content: $content+ });},onCommentAdded: function(comment) {var $sourceView = $(".source-view");@@ -377,7 +365,7 @@ gitplex.sourceview = {var $sourceView = $(".source-view");$sourceView.removeData("openComment");$sourceView.data("mark", mark);- $("#selection-popup").hide();+ $(".source-view>.code").selectionPopover("close");var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;pmease.commons.codemirror.clearSelection(cm);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex aac4319a85..ef2711dee6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -45,6 +45,7 @@ import com.pmease.commons.lang.tokenizers.CmToken;import com.pmease.commons.util.Range;import com.pmease.commons.util.RangeUtils;import com.pmease.commons.util.StringUtils;+import com.pmease.commons.wicket.assets.selectionpopover.SelectionPopoverResourceReference;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.Depot;@@ -170,12 +171,12 @@ public class TextDiffPanel extends Panel implements MarkAware {getMarkupId(), index, expanded);target.appendJavaScript(script);break;- case "openSelectionPopup":+ case "openSelectionPopover":String jsonOfPosition = String.format("{left: %d, top: %d}",params.getParameterValue("param1").toInt(),params.getParameterValue("param2").toInt());DiffMark mark = getMark(params, "param3", "param4", "param5", "param6", "param7");- script = String.format("gitplex.textdiff.openSelectionPopup('%s', %s, %s, '%s', %s);",+ script = String.format("gitplex.textdiff.openSelectionPopover('%s', %s, %s, '%s', %s);",getMarkupId(), jsonOfPosition, mark.toJson(), markSupport.getMarkUrl(mark),SecurityUtils.getAccount()!=null);target.appendJavaScript(script);@@ -291,6 +292,7 @@ public class TextDiffPanel extends Panel implements MarkAware {public void renderHead(IHeaderResponse response) {super.renderHead(response);+ response.render(JavaScriptHeaderItem.forReference(SelectionPopoverResourceReference.INSTANCE));response.render(JavaScriptHeaderItem.forReference(new JavaScriptResourceReference(TextDiffPanel.class, "text-diff.js")));response.render(CssHeaderItem.forReference(diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.jsindex 1e33f77fa9..4505dfd575 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js@@ -40,407 +40,380 @@ gitplex.textdiff = {if (!markSupport)return;-- $container.on("mouseup keyup", function() {- // use a timeout to make sure selection remains stable after mouse or keyboard action- setTimeout(function() {- function hideSelectionPopup() {- $("#selection-popup").hide();- }- var selection = window.getSelection();- if (!selection.rangeCount) {- hideSelectionPopup();- return;- }- var firstRange = selection.getRangeAt(0).cloneRange();- var lastRange = selection.getRangeAt(selection.rangeCount-1).cloneRange();- var $start = $(firstRange.startContainer);- var $end = $(lastRange.endContainer);-- /*- * offset represents offset within $start or $end node, for instance for below selection- * <span>hello</span><span>world</span>- * ^ ^- * $start will be <span>hello</span> and startOffset will be index of character 'l' which is 2,- * $end will be <span>world</span> and endOffset will be index of character 'd' which will be 4- */- var startOffset = firstRange.startOffset;- var endOffset = lastRange.endOffset;-- var $startDiff;- if (!$start.hasClass("text-diff"))- $startDiff = $start.closest(".text-diff");- else- $startDiff = $start;-- var $endDiff;- if (!$end.hasClass("text-diff"))- $endDiff = $end.closest(".text-diff");- else- $endDiff = $end;-- // selection must be within same file- if ($startDiff.length == 0 || $endDiff.length == 0 || !$startDiff.is($endDiff)) {- hideSelectionPopup();- return;- }-- var $startTd = $start.is("td.content")? $start: $start.closest(".text-diff td.content");- var $endTd = $end.is("td.content")? $end: $end.closest(".text-diff td.content");- // at least one side of selection must be within a table cell- if ($startTd.length == 0 && $endTd.length == 0) {- hideSelectionPopup();- return;- }+ $container.selectionPopover("init", function() {+ var selection = window.getSelection();+ if (!selection.rangeCount) {+ return;+ }+ var firstRange = selection.getRangeAt(0).cloneRange();+ var lastRange = selection.getRangeAt(selection.rangeCount-1).cloneRange();+ var $start = $(firstRange.startContainer);+ var $end = $(lastRange.endContainer);++ /*+ * offset represents offset within $start or $end node, for instance for below selection+ * <span>hello</span><span>world</span>+ * ^ ^+ * $start will be <span>hello</span> and startOffset will be index of character 'l' which is 2,+ * $end will be <span>world</span> and endOffset will be index of character 'd' which will be 4+ */+ var startOffset = firstRange.startOffset;+ var endOffset = lastRange.endOffset;++ var $startDiff;+ if (!$start.hasClass("text-diff"))+ $startDiff = $start.closest(".text-diff");+ else+ $startDiff = $start;++ var $endDiff;+ if (!$end.hasClass("text-diff"))+ $endDiff = $end.closest(".text-diff");+ else+ $endDiff = $end;++ // selection must be within same file+ if ($startDiff.length == 0 || $endDiff.length == 0 || !$startDiff.is($endDiff)) {+ return;+ }++ var $startTd = $start.is("td.content")? $start: $start.closest(".text-diff td.content");+ var $endTd = $end.is("td.content")? $end: $end.closest(".text-diff td.content");- // make sure we are processing td.content on the same side on split view- function getTd($tr) {- var $td = $startTd.length != 0? $startTd: $endTd;- if ($td.hasClass("left"))- return $tr.find("td.content.left");- else if ($td.hasClass("right"))- return $tr.find("td.content.right");- else- return $tr.find("td.content");- }+ // at least one side of selection must be within a table cell+ if ($startTd.length == 0 && $endTd.length == 0) {+ return;+ }- /*- * sometimes the selection returns $start and $end as td instead of- * children under td, for instance:- * <td><span>hello</span><span>world</span></td>- * ^- * in this case, both $start and $end is the whole td, and startOffset- * is index of first span element which is 0, and endOffset is index of- * last span element plus 1 which is 2.- *- * this function returns the equivalent child node and offset under td.- * with above example, the equivalent child node will be <span>hello</span>- * and offset will be 0 for selection start, while equivalent end child node- * is <span>world</span> with offset being 5- *- */- function getNodeAndOffsetUnderTd($td, contentIndex) {- var $contents = $td.contents();- for (var i=0; i<$contents.length; i++) {- if (i == contentIndex) {- return {- node: $($contents[i]),- offset: 0- }- }- }- var $lastContent = $contents.last();- return {- node: $lastContent,- offset: $lastContent.text().length- }- }+ // make sure we are processing td.content on the same side on split view+ function getTd($tr) {+ var $td = $startTd.length != 0? $startTd: $endTd;+ if ($td.hasClass("left"))+ return $tr.find("td.content.left");+ else if ($td.hasClass("right"))+ return $tr.find("td.content.right");+ else+ return $tr.find("td.content");+ }- // normalize $start to be within td.content- if ($start.parent().parent().is("td.content")) // $start might be the text node under span- $start = $start.parent();- if (!$start.parent().is("td.content")) {- var $td;- if ($start.is("td.content")) { // this happens if we triple click to select a line in firefox- $td = $start;- } else if ($start.is("tr.code")) { // this may happen if we drag mouse to select multiple lines in firefox- $td = getTd($start);- startOffset = startOffset<=$td.index()? 0: $td.contents().length;- } else if ($start.is("tr.expander") || $start.closest("tr.expander").length != 0) { // this may happen if we drag mouse over to expander line- var $tr = $start.is("tr.expander")? $start.next(): $start.closest("tr.expander").next();- if ($tr.length == 0) {- hideSelectionPopup();- return;- }- $td = getTd($tr);- startOffset = 0;- } else {- var $tr = $startDiff.find("tr.code").first();- if ($tr.length == 0) {- hideSelectionPopup();- return;+ /*+ * sometimes the selection returns $start and $end as td instead of+ * children under td, for instance:+ * <td><span>hello</span><span>world</span></td>+ * ^+ * in this case, both $start and $end is the whole td, and startOffset+ * is index of first span element which is 0, and endOffset is index of+ * last span element plus 1 which is 2.+ *+ * this function returns the equivalent child node and offset under td.+ * with above example, the equivalent child node will be <span>hello</span>+ * and offset will be 0 for selection start, while equivalent end child node+ * is <span>world</span> with offset being 5+ *+ */+ function getNodeAndOffsetUnderTd($td, contentIndex) {+ var $contents = $td.contents();+ for (var i=0; i<$contents.length; i++) {+ if (i == contentIndex) {+ return {+ node: $($contents[i]),+ offset: 0}- $td = getTd($tr);- startOffset = 0;}- var nodeAndOffset = getNodeAndOffsetUnderTd($td, startOffset);- $start = nodeAndOffset.node;- startOffset = nodeAndOffset.offset;+ }+ var $lastContent = $contents.last();+ return {+ node: $lastContent,+ offset: $lastContent.text().length}-- // drag mouse over a line below expander, chrome may set $start as the line- // above expander, below code normalizes this case- $startTd = $start.parent();- var $lastContent = $startTd.contents().last();- var noneSelected = $start.is($lastContent) && startOffset >= $lastContent.text().length;- if (noneSelected && $startTd.parent().next().is("tr.expander")) {- var $tr = $startTd.parent().next().next();+ }++ // normalize $start to be within td.content+ if ($start.parent().parent().is("td.content")) // $start might be the text node under span+ $start = $start.parent();+ if (!$start.parent().is("td.content")) {+ var $td;+ if ($start.is("td.content")) { // this happens if we triple click to select a line in firefox+ $td = $start;+ } else if ($start.is("tr.code")) { // this may happen if we drag mouse to select multiple lines in firefox+ $td = getTd($start);+ startOffset = startOffset<=$td.index()? 0: $td.contents().length;+ } else if ($start.is("tr.expander") || $start.closest("tr.expander").length != 0) { // this may happen if we drag mouse over to expander line+ var $tr = $start.is("tr.expander")? $start.next(): $start.closest("tr.expander").next();if ($tr.length == 0) {- hideSelectionPopup();return;}- var $td = getTd($tr);- $start = $td.contents().first();+ $td = getTd($tr);startOffset = 0;- }-- // normalize $end to be within td.content- if ($end.parent().parent().is("td.content"))- $end = $end.parent();- if (!$end.parent().is("td.content")) {- var $td;- if ($end.is("td.content")) {- $td = $end;- } else if ($end.is("tr.code")) {- $td = getTd($end);- endOffset = endOffset>$td.index()? $td.contents().length: 0;- } else if ($end.is("tr.expander") || $end.closest("tr.expander").length != 0) {- var $tr = $end.is("tr.expander")? $end.prev(): $end.closest("tr.expander").prev();- if ($tr.length == 0) {- hideSelectionPopup();- return;- }- $td = getTd($tr);- endOffset = $td.contents().length;- } else {- var $tr = $endDiff.find("tr.code").last();- if ($tr.length == 0) {- hideSelectionPopup();- return;- }- $td = getTd($tr);- endOffset = $td.contents().length;- }- var nodeAndOffset = getNodeAndOffsetUnderTd($td, endOffset);- $end = nodeAndOffset.node;- endOffset = nodeAndOffset.offset;- }-- // drag mouse over a line above expander, chrome may set $end as the line- // below expander, below code normalizes this case- $endTd = $end.parent();- var $firstContent = $endTd.contents().first();- var noneSelected = $end.is($firstContent) && endOffset == 0;- if (noneSelected && $endTd.parent().prev().is("tr.expander")) {- var $tr = $endTd.parent().prev().prev();+ } else {+ var $tr = $startDiff.find("tr.code").first();if ($tr.length == 0) {- hideSelectionPopup();return;}- var $td = getTd($tr);- $end = $td.contents().last();- endOffset = $end.text().length;+ $td = getTd($tr);+ startOffset = 0;}-- $startTd = $start.parent();- $endTd = $end.parent();-- // selection must not span the split view- if ($startTd.hasClass("left") && $endTd.hasClass("right")- || $startTd.hasClass("right") && $endTd.hasClass("left")) {- hideSelectionPopup();- return;- }-- var $startTr = $startTd.parent();- var $endTr = $endTd.parent();- if ($startTr.index() > $endTr.index()) {- hideSelectionPopup();+ var nodeAndOffset = getNodeAndOffsetUnderTd($td, startOffset);+ $start = nodeAndOffset.node;+ startOffset = nodeAndOffset.offset;+ }++ // drag mouse over a line below expander, chrome may set $start as the line+ // above expander, below code normalizes this case+ $startTd = $start.parent();+ var $lastContent = $startTd.contents().last();+ var noneSelected = $start.is($lastContent) && startOffset >= $lastContent.text().length;+ if (noneSelected && $startTd.parent().next().is("tr.expander")) {+ var $tr = $startTd.parent().next().next();+ if ($tr.length == 0) {return;}-- function nextContent($content) {- var $td = $content.parent();- var array = $td.contents().toArray();- var index = array.indexOf($content[0]);- if (index == array.length-1) {- var $nextTr = $td.parent().next();- if ($nextTr.hasClass("expander")) {- $nextTr = $nextTr.next();- }- if ($nextTr.length == 0)- return undefined;- return getTd($nextTr).contents().first();- } else {- return $(array[index+1]);+ var $td = getTd($tr);+ $start = $td.contents().first();+ startOffset = 0;+ }++ // normalize $end to be within td.content+ if ($end.parent().parent().is("td.content"))+ $end = $end.parent();+ if (!$end.parent().is("td.content")) {+ var $td;+ if ($end.is("td.content")) {+ $td = $end;+ } else if ($end.is("tr.code")) {+ $td = getTd($end);+ endOffset = endOffset>$td.index()? $td.contents().length: 0;+ } else if ($end.is("tr.expander") || $end.closest("tr.expander").length != 0) {+ var $tr = $end.is("tr.expander")? $end.prev(): $end.closest("tr.expander").prev();+ if ($tr.length == 0) {+ return;}- }-- function prevContent($content) {- var $td = $content.parent();- var array = $td.contents().toArray();- var index = array.indexOf($content[0]);- if (index == 0) {- var $prevTr = $td.parent().prev();- if ($prevTr.hasClass("expander")) {- $prevTr = $prevTr.next();- }- if ($prevTr.length == 0)- return undefined;- return getTd($prevTr).contents().last();- } else {- return $(array[index-1]);+ $td = getTd($tr);+ endOffset = $td.contents().length;+ } else {+ var $tr = $endDiff.find("tr.code").last();+ if ($tr.length == 0) {+ return;}+ $td = getTd($tr);+ endOffset = $td.contents().length;}-- function hasOldOrNewData($content) {- var $td = $content.parent();- return $td.attr("data-old") || $td.attr("data-new");+ var nodeAndOffset = getNodeAndOffsetUnderTd($td, endOffset);+ $end = nodeAndOffset.node;+ endOffset = nodeAndOffset.offset;+ }++ // drag mouse over a line above expander, chrome may set $end as the line+ // below expander, below code normalizes this case+ $endTd = $end.parent();+ var $firstContent = $endTd.contents().first();+ var noneSelected = $end.is($firstContent) && endOffset == 0;+ if (noneSelected && $endTd.parent().prev().is("tr.expander")) {+ var $tr = $endTd.parent().prev().prev();+ if ($tr.length == 0) {+ return;}-- /*- * continue to normalize $start and $end. This time we convert below selection:- * <span>begin</span><span>middle</span><span>end</span>- * ^ ^- * into this selection:- * <span>begin</span><span>middle</span><span>end</span>- * ^ ^- * this normalization makes it accurate to detect invalid selections where start- * and end of selection points to different revisions- */- var $content = $start;- while (!$content.is($end) && (startOffset >= $content.text().length || !hasOldOrNewData($content))) {- $content = nextContent($content);- if (!$content) {- hideSelectionPopup();- return;- } else {- $start = $content;- startOffset = 0;+ var $td = getTd($tr);+ $end = $td.contents().last();+ endOffset = $end.text().length;+ }++ $startTd = $start.parent();+ $endTd = $end.parent();++ // selection must not span the split view+ if ($startTd.hasClass("left") && $endTd.hasClass("right")+ || $startTd.hasClass("right") && $endTd.hasClass("left")) {+ return;+ }++ var $startTr = $startTd.parent();+ var $endTr = $endTd.parent();+ if ($startTr.index() > $endTr.index()) {+ return;+ }++ function nextContent($content) {+ var $td = $content.parent();+ var array = $td.contents().toArray();+ var index = array.indexOf($content[0]);+ if (index == array.length-1) {+ var $nextTr = $td.parent().next();+ if ($nextTr.hasClass("expander")) {+ $nextTr = $nextTr.next();}+ if ($nextTr.length == 0)+ return undefined;+ return getTd($nextTr).contents().first();+ } else {+ return $(array[index+1]);}-- $content = $end;- while (!$content.is($start) && (endOffset == 0 || !hasOldOrNewData($content))) {- $content = prevContent($content);- if (!$content) {- hideSelectionPopup();- return;- } else {- $end = $content;- endOffset = $content.text().length;+ }++ function prevContent($content) {+ var $td = $content.parent();+ var array = $td.contents().toArray();+ var index = array.indexOf($content[0]);+ if (index == 0) {+ var $prevTr = $td.parent().prev();+ if ($prevTr.hasClass("expander")) {+ $prevTr = $prevTr.next();}+ if ($prevTr.length == 0)+ return undefined;+ return getTd($prevTr).contents().last();+ } else {+ return $(array[index-1]);}+ }- // check if there is anything selected- if ($start.is($end) && startOffset >= endOffset- || !hasOldOrNewData($start) || !hasOldOrNewData($end)) {- hideSelectionPopup();+ function hasOldOrNewData($content) {+ var $td = $content.parent();+ return $td.attr("data-old") || $td.attr("data-new");+ }++ /*+ * continue to normalize $start and $end. This time we convert below selection:+ * <span>begin</span><span>middle</span><span>end</span>+ * ^ ^+ * into this selection:+ * <span>begin</span><span>middle</span><span>end</span>+ * ^ ^+ * this normalization makes it accurate to detect invalid selections where start+ * and end of selection points to different revisions+ */+ var $content = $start;+ while (!$content.is($end) && (startOffset >= $content.text().length || !hasOldOrNewData($content))) {+ $content = nextContent($content);+ if (!$content) {return;+ } else {+ $start = $content;+ startOffset = 0;}-- firstRange.collapse(true);- var startRect = firstRange.getClientRects()[0];- lastRange.collapse(false);- var endRect = lastRange.getClientRects()[0];- if (!startRect || !endRect) {- startRect = selection.getRangeAt(0).getClientRects()[0];- endRect = startRect;+ }++ $content = $end;+ while (!$content.is($start) && (endOffset == 0 || !hasOldOrNewData($content))) {+ $content = prevContent($content);+ if (!$content) {+ return;+ } else {+ $end = $content;+ endOffset = $content.text().length;}- var position = {- left: (startRect.left + endRect.right)/2,- top: startRect.top- };- position.left += $(window).scrollLeft();- position.top += $(window).scrollTop();-- function showInvalidSelection() {- var invalidSelectionUrl = "http://wiki.pmease.com/display/gp/Diff+Selection";- var permanentCallback = function($permanentLink) {- $permanentLink.off("click");- $permanentLink.attr("href", invalidSelectionUrl);- $permanentLink.html("<i class='fa fa-link'></i> No permanent link to this selection, see why");- };- var commentCallback = function($commentLink) {- $commentLink.attr("href", invalidSelectionUrl);- $commentLink.html("<i class='fa fa-comment'></i> Unable to comment this selection, see why");- };- $("#selection-popup").data("open")(position, permanentCallback,- commentCallback, $container[0]);+ }++ // check if there is anything selected+ if ($start.is($end) && startOffset >= endOffset+ || !hasOldOrNewData($start) || !hasOldOrNewData($end)) {+ return;+ }++ firstRange.collapse(true);+ var startRect = firstRange.getClientRects()[0];+ lastRange.collapse(false);+ var endRect = lastRange.getClientRects()[0];+ if (!startRect || !endRect) {+ startRect = selection.getRangeAt(0).getClientRects()[0];+ endRect = startRect;+ }+ var position = {+ left: (startRect.left + endRect.right)/2,+ top: startRect.top+ };+ position.left += $(window).scrollLeft();+ position.top += $(window).scrollTop();++ function showInvalidSelection() {+ var $content = $("<div></div>");+ $content.append("<a class='invalid'><i class='fa fa-warning'></i> Invalid selection, click for details</a>");+ $content.children("a").attr("href", "http://wiki.pmease.com/display/gp/Diff+Selection");+ return {+ position: position,+ content: $content}+ }- // all lines between selection has been expanded- if ($startTr.nextAll("tr.expander").filter($endTr.prevAll("tr.expander")).length != 0- || $startTr.prevAll("tr.expander").filter($endTr.nextAll("tr.expander")).length != 0) {- showInvalidSelection();- return;+ // all lines between selection has been expanded+ if ($startTr.nextAll("tr.expander").filter($endTr.prevAll("tr.expander")).length != 0+ || $startTr.prevAll("tr.expander").filter($endTr.nextAll("tr.expander")).length != 0) {+ return showInvalidSelection();+ }++ /*+ * cursor.line represents line number of selection and cursor.ch represents+ * character index inside text of the whole line, without considering element+ * tags.+ */+ function getCursor($node, offset) {+ $nodeTd = $node.parent();+ var oldLine, newLine;+ if (!$nodeTd.hasClass("old") && !$nodeTd.hasClass("new")+ || $nodeTd.hasClass("old") && $nodeTd.hasClass("new")) {+ oldLine = $nodeTd.data("old") + 1;+ newLine = $nodeTd.data("new") + 1;+ } else if ($nodeTd.hasClass("old")) {+ oldLine = $nodeTd.data("old") + 1;+ } else {+ newLine = $nodeTd.data("new") + 1;}-- /*- * cursor.line represents line number of selection and cursor.ch represents- * character index inside text of the whole line, without considering element- * tags.- */- function getCursor($node, offset) {- $nodeTd = $node.parent();- var oldLine, newLine;- if (!$nodeTd.hasClass("old") && !$nodeTd.hasClass("new")- || $nodeTd.hasClass("old") && $nodeTd.hasClass("new")) {- oldLine = $nodeTd.data("old") + 1;- newLine = $nodeTd.data("new") + 1;- } else if ($nodeTd.hasClass("old")) {- oldLine = $nodeTd.data("old") + 1;- } else {- newLine = $nodeTd.data("new") + 1;- }- var $contents = $nodeTd.contents();- var oldOffset = 0, newOffset = 0;- for (var i=0; i<$contents.length; i++) {- var $content = $($contents[i]);- if ($content.is($node)) {- if ($content.hasClass("delete")) {- oldCh = oldOffset + offset;- newCh = undefined;- newLine = undefined;- } else if ($content.hasClass("insert")) {- oldCh = undefined;- oldLine = undefined;- newCh = newOffset + offset;- } else {- oldCh = oldOffset + offset;- newCh = newOffset + offset;- }- break;- } else {- var len = $content.text().length;- if ($content.hasClass("delete")) {- oldOffset += len;- } else if ($content.hasClass("insert")) {- newOffset += len;- } else {- oldOffset += len;- newOffset += len;- }- }- }- if ($nodeTd.hasClass("left")) {- newLine = newCh = undefined;- } else if ($nodeTd.hasClass("right")) {- oldLine = oldCh = undefined;- }- return {- oldLine: oldLine,- oldCh: oldCh,- newLine: newLine,- newCh: newCh- };- }+ var $contents = $nodeTd.contents();+ var oldOffset = 0, newOffset = 0;+ for (var i=0; i<$contents.length; i++) {+ var $content = $($contents[i]);+ if ($content.is($node)) {+ if ($content.hasClass("delete")) {+ oldCh = oldOffset + offset;+ newCh = undefined;+ newLine = undefined;+ } else if ($content.hasClass("insert")) {+ oldCh = undefined;+ oldLine = undefined;+ newCh = newOffset + offset;+ } else {+ oldCh = oldOffset + offset;+ newCh = newOffset + offset;+ }+ break;+ } else {+ var len = $content.text().length;+ if ($content.hasClass("delete")) {+ oldOffset += len;+ } else if ($content.hasClass("insert")) {+ newOffset += len;+ } else {+ oldOffset += len;+ newOffset += len;+ }+ }+ }+ if ($nodeTd.hasClass("left")) {+ newLine = newCh = undefined;+ } else if ($nodeTd.hasClass("right")) {+ oldLine = oldCh = undefined;+ }+ return {+ oldLine: oldLine,+ oldCh: oldCh,+ newLine: newLine,+ newCh: newCh+ };+ }- var startCursor = getCursor($start, startOffset);- var endCursor = getCursor($end, endOffset);+ var startCursor = getCursor($start, startOffset);+ var endCursor = getCursor($end, endOffset);- if (startCursor.newLine && endCursor.newLine) {- callback("openSelectionPopup", Math.round(position.left), Math.round(position.top), false,- startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);- } else if (startCursor.oldLine && endCursor.oldLine) {- callback("openSelectionPopup", Math.round(position.left), Math.round(position.top), true,- startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);- } else {- showInvalidSelection();- return;- }- }, 100);+ if (startCursor.newLine && endCursor.newLine) {+ callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), false,+ startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);+ } else if (startCursor.oldLine && endCursor.oldLine) {+ callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), true,+ startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);+ } else {+ return showInvalidSelection();+ }});if (openComment) {@@ -466,33 +439,29 @@ gitplex.textdiff = {gitplex.textdiff.scroll($container, mark);}},- openSelectionPopup: function(containerId, position, mark, markUrl, loggedIn) {+ openSelectionPopover: function(containerId, position, mark, markUrl, loggedIn) {var $container = $("#" + containerId);- var permanentLinkCallback = function($permanentLink) {- $permanentLink.attr("href", markUrl);- $permanentLink.html("<i class='fa fa-link'></i> Permanent link of this selection");- };-- var commentLinkCallback = function($commentLink) {- $commentLink.html("<i class='fa fa-comment'></i> Add comment of this selection");- $commentLink.off("click");- $commentLink.attr("href", "javascript:void(0);");- if (loggedIn) {- $commentLink.click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- $container.data("callback")("addComment", mark.leftSide,- mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);- });- } else {- $commentLink.html("Log in to comment on selection");- }- };- $("#selection-popup").data("open")(position, permanentLinkCallback,- commentLinkCallback, $container[0]);+ var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");+ $content.children("a.permanent").attr("href", markUrl);+ if (loggedIn) {+ $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");+ $content.children("a.comment").click(function() {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ $container.data("callback")("addComment", mark.leftSide,+ mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);+ });+ } else {+ $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");+ }++ $container.selectionPopover("open", {+ position: position,+ content: $content+ });},expand: function(containerId, blockIndex, expandedHtml) {var $container = $("#" + containerId);@@ -855,7 +824,7 @@ gitplex.textdiff = {$container.removeData("openComment");$container.data("mark", mark);- $("#selection-popup").hide();+ $container.selectionPopover("close");window.getSelection().removeAllRanges();// continue to operate DOM in a timer to give browser a chance todiff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.jsindex e14ad15b50..db3dec1bc8 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js@@ -94,5 +94,5 @@ gitplex.revisionDiff = {}}$(function() {- $(window).on("scroll resize", gitplex.revisionDiff.position);+ $(window).on("scroll resize", gitplex.revisionDiff.reposition);});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 7ae9edf377..ca4664f6dc 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@@ -4,6 +4,7 @@$content.children("a").click(function() {console.log("clicked");});+ $content.children("a").after("<a></a>");$("body").append($content);</script></wicket:extend>\ No newline at end of file