Skip to content

The Unified and Autonomous Development Platform

fix bug of comment dialog not positioning well sometimes

robin shineb79b5654509f
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js
index 3ee3d81c41..cd115953e4 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/page/common.js
@@ -1,502 +1,500 @@
-/**************************************************************
- * Define common javascript functions and setups here.
- *
- **************************************************************/
-
-var pmease = {};
-String.prototype.escape = function() {
- return (this + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
-};
-pmease.commons = {
- setupCollapse: function(triggerId, targetId) {
- var trigger = $("#" + triggerId);
- var target = $("#" + targetId);
-
- // This script can still be called if CollapseBehavior is added to a
- // a component enclosed in an invisible wicket:enclosure. So we
- // should check if relevant element exists.
- if (!trigger[0] || !target[0])
- return;
-
- target[0].trigger = trigger[0];
-
- target.on("shown.bs.collapse hidden.bs.collapse", function() {
- var $floating = target.closest(".floating");
- if ($floating.length != 0) {
- var borderTop = $(window).scrollTop();
- var borderBottom = borderTop + $(window).height();
- var borderLeft = $(window).scrollLeft();
- var borderRight = borderLeft + $(window).width();
-
- var left = $floating.position().left;
- var top = $floating.position().top;
- var width = $floating.outerWidth();
- var height = $floating.outerHeight();
-
- if (left < borderLeft || left + width > borderRight
- || top < borderTop || top + height > borderBottom) {
- if ($floating.data("alignment"))
- $floating.align($floating.data("alignment"));
- }
- }
-
- });
- trigger.click(function() {
- if (target[0].collapsibleIds == undefined) {
- if (!target.hasClass("in")) {
- target.collapse("show");
- $(target[0].trigger).removeClass("collapsed");
- } else {
- target.collapse("hide");
- $(target[0].trigger).addClass("collapsed");
- }
- } else if (!target.hasClass("in")) {
- for (var i in target[0].collapsibleIds) {
- var collapsible = $("#" + target[0].collapsibleIds[i]);
- if (collapsible.hasClass("in")) {
- collapsible.collapse("hide");
- $(collapsible[0].trigger).addClass("collapsed");
- }
- }
- target.collapse("show");
- $(target[0].trigger).removeClass("collapsed");
- }
- });
- },
-
- setupAccordion: function(accordionId) {
- var accordion = $("#" + accordionId);
- var collapsibleIds = new Array();
- accordion.find(".collapse:not(#" + accordionId + " .collapse .collapse, #" + accordionId + " .accordion .collapse)").each(function() {
- collapsibleIds.push(this.id);
- });
- if (collapsibleIds[0]) {
- var collapsible = $("#" + collapsibleIds[0]);
- collapsible.removeClass("collapse");
- collapsible.addClass("in");
- }
- for (var i in collapsibleIds) {
- var collapsible = $("#" + collapsibleIds[i]);
- if (i == 0) {
- $(collapsible[0].trigger).removeClass("collapsed");
- collapsible.removeClass("collapse");
- collapsible.addClass("in");
- } else {
- $(collapsible[0].trigger).addClass("collapsed");
- }
- collapsible[0].collapsibleIds = collapsibleIds;
- }
- },
-
- editable: {
- adjustReflectionEditor: function(editorId) {
- var editor = $("#" + editorId);
- var input = editor.find(".value>input[type=checkbox]");
- input.parent().prev("label.name").addClass("pull-left");
- input.after("<div style='clear:both;'/>")
-
- input = editor.find(".value>div>input[type=checkbox]");
- input.parent().parent().prev("label.name").addClass("pull-left");
- input.after("<div style='clear:both;'/>")
- }
- },
-
- form: {
- /*
- * This function can be called to mark enclosing form of specified element dirty. It should be
- * called if underlying data has been changed but no form fields are updated, for instance
- * when sorting the elements inside a form.
- */
- markDirty: function($forms) {
- $forms.addClass("dirty").each(function() {
- pmease.commons.form.dirtyChanged($(this));
- });
- },
- markClean: function($forms) {
- $forms.removeClass("dirty").each(function() {
- pmease.commons.form.dirtyChanged($(this));
- });
- },
- removeDirty: function(triggerId, $forms) {
- $(function() {
- var $trigger = $("#" + triggerId);
-
- var previousClick;
-
- var handlers = $._data($trigger[0], 'events').click;
-
- $.each(handlers, function(i,f) {
- previousClick = f.handler;
- return false;
- });
-
- $trigger.unbind('click');
-
- $trigger.click(function(event){
- pmease.commons.form.markClean($forms);
- previousClick(event);
- });
- });
- },
- trackDirty: function(form) {
- var $form = $(form);
- if ($form.find(".dirty-aware").length != 0 || $form.hasClass("leave-confirm")) {
- $form.areYouSure({
- "silent": !$form.hasClass("leave-confirm"),
- "addRemoveFieldsMarksDirty": true,
- change: function() {
- pmease.commons.form.dirtyChanged($(this));
- }
- });
- if ($form.find(".has-error").length != 0) {
- $form.addClass("dirty");
- }
- pmease.commons.form.dirtyChanged($form);
- }
- },
- dirtyChanged: function($form) {
- $dirtyAware = $form.find(".dirty-aware");
- if ($dirtyAware.length != 0) {
- if ($form.hasClass("dirty")) {
- $dirtyAware.removeAttr("disabled");
- } else {
- $dirtyAware.attr("disabled", "disabled");
- }
- }
- },
- setupDirtyCheck: function() {
- $("form").each(function() {
- pmease.commons.form.trackDirty(this);
- });
-
- $(document).on("elementReplaced", function(event, componentId) {
- var $component = $("#" + componentId);
- var $forms = $component.find("form");
- if ($component.is("form"))
- $forms = $forms.add($component);
- $forms.each(function() {
- pmease.commons.form.trackDirty(this);
- });
- $component.closest("form.ays-inited").not($component).trigger("checkform.areYouSure");
- });
-
- if (Wicket && Wicket.Ajax) {
- var processAjaxResponse = Wicket.Ajax.Call.prototype.processAjaxResponse;
- Wicket.Ajax.Call.prototype.processAjaxResponse = function (data, textStatus, jqXHR, context) {
- if (jqXHR.readyState === 4) {
- var redirectUrl;
- try {
- redirectUrl = jqXHR.getResponseHeader('Ajax-Location');
- } catch (ignore) { // might happen in older mozilla
- }
-
- if (typeof(redirectUrl) !== "undefined" && redirectUrl !== null && redirectUrl !== "") {
- $("form.leave-confirm").removeClass("dirty");
- }
- }
- processAjaxResponse.call(this, data, textStatus, jqXHR, context);
- }
- }
- },
- confirmLeave: function(containerId) {
- var $container;
- if (containerId)
- $container = $("#" + containerId);
- else
- $container = $(document);
- var dirty = "form.leave-confirm.dirty";
- if ($container.is(dirty) || $container.find(dirty).length != 0)
- return confirm("There are unsaved changes, do you want to discard and continue?");
- else
- return true;
- }
- },
- setupAutoSize: function() {
- autosize($("textarea"));
- $(document).on("elementReplaced", function(event, componentId) {
- var $component = $("#" + componentId);
- var $textarea = $component.find("textarea");
- if ($component.is("textarea"))
- $textarea = $textarea.add($component);
- autosize($textarea);
- });
- },
- setupAjaxLoadingIndicator: function() {
- $("#ajax-loading-overlay").click(function(e) {
- e.stopPropagation();
- });
-
- Wicket.Event.subscribe('/ajax/call/beforeSend', function() {
- var $ajaxLoadingIndicator = $("#ajax-loading-indicator");
- if ($ajaxLoadingIndicator[0].timer)
- clearTimeout($ajaxLoadingIndicator[0].timer);
- $ajaxLoadingIndicator[0].timer = setTimeout(function() {
- if (!$ajaxLoadingIndicator.is(":visible") && $(".ajax-indicator:visible").length == 0)
- $ajaxLoadingIndicator.show();
- }, 2000);
- });
-
- Wicket.Event.subscribe('/ajax/call/complete', function() {
- var $ajaxLoadingIndicator = $("#ajax-loading-indicator");
- if ($ajaxLoadingIndicator[0].timer) {
- clearTimeout($ajaxLoadingIndicator[0].timer);
- $ajaxLoadingIndicator[0].timer = null;
- }
- $ajaxLoadingIndicator.hide();
- });
- },
-
- focus: {
- $components: null,
-
- focusOn: function(componentId) {
- if (componentId)
- pmease.commons.focus.doFocus($("#" + componentId));
- pmease.commons.focus.$components = null;
- },
-
- doFocus: function($containers) {
- var $inError = $containers.find(".has-error:first .focusable");
- if ($inError.length != 0) {
- $inError.focus();
- } else {
- $containers.find(".focusable:visible").each(function() {
- var $this = $(this);
- if ($this.parents(".nofocus").length == 0) {
- $this.focus();
- return false;
- }
- });
- }
- },
-
- setupAutoFocus: function() {
- if (typeof(Wicket) != "undefined" && typeof(Wicket.Focus) != "undefined") {
- var wicketSetFocusOnId = Wicket.Focus.setFocusOnId;
- Wicket.Focus.setFocusOnId = function(componentId) {
- pmease.commons.focus.focusOn(componentId);
- wicketSetFocusOnId(componentId);
- }
- }
-
- Wicket.Event.subscribe('/ajax/call/beforeSend', function() {
- pmease.commons.focus.$components = $();
- });
- Wicket.Event.subscribe('/ajax/call/complete', function() {
- if (pmease.commons.focus.$components != null)
- pmease.commons.focus.doFocus(pmease.commons.focus.$components);
- });
-
- pmease.commons.focus.doFocus($(document));
-
- $(document).on("elementReplaced", function(event, componentId) {
- if (pmease.commons.focus.$components != null)
- pmease.commons.focus.$components = pmease.commons.focus.$components.add("#" + componentId);
- });
- },
-
- },
-
- // Disable specified button if value of specified input is blank
- disableIfBlank: function(inputId, buttonId) {
- var $input = $("#" + inputId);
- $input.bind("input propertychange keyup", function() {
- var value = $(this).val();
- var $button = $("#" + buttonId);
- if (value.trim().length != 0)
- $button.removeAttr("disabled");
- else
- $button.attr("disabled", "disabled");
- });
- $input.trigger("input");
- },
-
- autoHeight: function(targetSelector, bottomOffset) {
- var adjustHeight = function() {
- $(targetSelector).css("max-height", $(document).scrollTop() + $(window).height()
- - $(targetSelector).offset().top - bottomOffset + "px");
- };
- adjustHeight();
- $(window).resize(adjustHeight);
- $(window).scroll(adjustHeight);
- },
-
- showSessionFeedback: function() {
- if ($("#session-feedback li").length != 0) {
- var feedback = $("#session-feedback");
- var x = ($(window).width() - feedback.outerWidth()) / 2;
- feedback.css("left", x+$(window).scrollLeft());
- feedback.css("top", $(window).scrollTop());
- feedback.slideDown("slow");
-
- var body = $("body");
- if (body[0].hideCatchAllFeedbackTimer) {
- clearTimeout(body[0].hideCatchAllFeedbackTimer);
- }
- body[0].hideCatchAllFeedbackTimer = setTimeout(function() {
- $("#session-feedback").slideUp();
- }, 5000);
- }
- },
-
- backToTop: function(backToTop) {
- var $backToTop = $(backToTop);
- $backToTop.hide();
- $(window).scroll(function(){
- if ($(window).scrollTop()>500)
- $backToTop.fadeIn(1000);
- else
- $backToTop.fadeOut(1000);
- });
- $backToTop.click(function(){
- $("body, html").animate({scrollTop:0}, 700);
- return false;
- });
- },
-
- choiceFormatter: {
- id: {
- formatSelection: function(choice) {
- return choice.id;
- },
-
- formatResult: function(choice) {
- return choice.id;
- },
-
- escapeMarkup: function(m) {
- return m;
- }
- }
- },
-
- websocket: {
- setupCallback: function() {
- Wicket.Event.subscribe("/websocket/message", function(jqEvent, message) {
- if (message == "RenderCallback")
- Wicket.WebSocket.send(message);
- else if (message == "ErrorMessage")
- $("#websocket-error").show();
- });
- Wicket.Event.subscribe("/websocket/open", function(jqEvent) {
- Wicket.WebSocket.send("ConnectCallback");
- });
- }
- },
-
- history: {
- getHashlessUrl: function(url) {
- var index = url.indexOf('#');
- if (index != -1)
- return url.substring(0, index);
- else
- return url;
- },
- init: function(callback) {
- // Use a timeout here solve the problem that Safari (and previous versions of Chrome)
- // fires event "onpopstate" on initial page load and this causes the page to reload
- // infinitely
- setTimeout(function() {
- window.onpopstate = function(event) {
- if (pmease.commons.history.getHashlessUrl(window.location.href)
- != pmease.commons.history.getHashlessUrl(pmease.commons.history.current.url)) {
- if (pmease.commons.form.confirmLeave()) {
- if (!event.state || !event.state.data) {
- location.reload();
- } else {
- callback(event.state.data);
- pmease.commons.history.current = {
- state: event.state,
- url: window.location.href
- };
- }
- } else {
- /*
- * In case we want to stay in the page, we should also re-push previous url
- * as url has already been changed when user hits back/forward button
- */
- history.pushState(pmease.commons.history.current.state, '' ,
- pmease.commons.history.current.url);
- }
- }
- };
- }, 100);
-
- pmease.commons.history.current = {
- url: window.location.href
- };
- },
- pushState: function(url, data) {
- $(".autofit:visible").first().trigger("storeViewState");
- var state = {data: data};
- pmease.commons.history.current = {state: state, url: url};
- history.pushState(state, '', url);
- setTimeout(function() {
- pmease.commons.history.setVisited();
- }, 100);
- },
- /*
- * visited flag is used to determine whether or not a page is newly visited
- * or loaded via back/forward button. If loaded via back/forward button we
- * will not respect scroll flag (such as mark param in url) and let browser
- * scroll to original position for better usage experience
- */
- setVisited: function() {
- var state = history.state;
- if (!state)
- state = {};
- if (!state.loaded) {
- var newState = {viewState: state.viewState, data: state.data, visited: true};
- history.replaceState(newState, '', window.location.href);
- pmease.commons.history.current = {
- state: newState,
- url: window.location.href
- };
- }
- },
- isVisited: function() {
- return history.state && history.state.visited;
- },
- setViewState: function(viewState) {
- var state = history.state;
- if (!state)
- state = {};
- var newState = {viewState: viewState, data: state.data, visited: state.visited};
- history.replaceState(newState, '', window.location.href );
- pmease.commons.history.current = {
- state: newState,
- url: window.location.href
- };
- },
- getViewState: function() {
- if (history.state && history.state.viewState)
- return history.state.viewState;
- else
- return undefined;
- }
- },
- isDevice: function() {
- var ua = navigator.userAgent.toLowerCase();
- return ua.indexOf("android") != -1
- || ua.indexOf("iphone") != -1
- || ua.indexOf("ipad") != -1
- || ua.indexOf("windows phone") != -1;
- }
-};
-
-$(function() {
- pmease.commons.setupAutoSize();
- pmease.commons.setupAjaxLoadingIndicator();
- pmease.commons.form.setupDirtyCheck();
- pmease.commons.focus.setupAutoFocus();
- pmease.commons.websocket.setupCallback();
-});
-
-$(window).load(function() {
- pmease.commons.history.setVisited();
-});
-$(window).on("beforeunload", function() {
- $(".autofit:visible").first().trigger("storeViewState");
-});
-
-console.log("nanade");
\ No newline at end of file
+/**************************************************************
+ * Define common javascript functions and setups here.
+ *
+ **************************************************************/
+
+var pmease = {};
+String.prototype.escape = function() {
+ return (this + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
+};
+pmease.commons = {
+ setupCollapse: function(triggerId, targetId) {
+ var trigger = $("#" + triggerId);
+ var target = $("#" + targetId);
+
+ // This script can still be called if CollapseBehavior is added to a
+ // a component enclosed in an invisible wicket:enclosure. So we
+ // should check if relevant element exists.
+ if (!trigger[0] || !target[0])
+ return;
+
+ target[0].trigger = trigger[0];
+
+ target.on("shown.bs.collapse hidden.bs.collapse", function() {
+ var $floating = target.closest(".floating");
+ if ($floating.length != 0) {
+ var borderTop = $(window).scrollTop();
+ var borderBottom = borderTop + $(window).height();
+ var borderLeft = $(window).scrollLeft();
+ var borderRight = borderLeft + $(window).width();
+
+ var left = $floating.position().left;
+ var top = $floating.position().top;
+ var width = $floating.outerWidth();
+ var height = $floating.outerHeight();
+
+ if (left < borderLeft || left + width > borderRight
+ || top < borderTop || top + height > borderBottom) {
+ if ($floating.data("alignment"))
+ $floating.align($floating.data("alignment"));
+ }
+ }
+
+ });
+ trigger.click(function() {
+ if (target[0].collapsibleIds == undefined) {
+ if (!target.hasClass("in")) {
+ target.collapse("show");
+ $(target[0].trigger).removeClass("collapsed");
+ } else {
+ target.collapse("hide");
+ $(target[0].trigger).addClass("collapsed");
+ }
+ } else if (!target.hasClass("in")) {
+ for (var i in target[0].collapsibleIds) {
+ var collapsible = $("#" + target[0].collapsibleIds[i]);
+ if (collapsible.hasClass("in")) {
+ collapsible.collapse("hide");
+ $(collapsible[0].trigger).addClass("collapsed");
+ }
+ }
+ target.collapse("show");
+ $(target[0].trigger).removeClass("collapsed");
+ }
+ });
+ },
+
+ setupAccordion: function(accordionId) {
+ var accordion = $("#" + accordionId);
+ var collapsibleIds = new Array();
+ accordion.find(".collapse:not(#" + accordionId + " .collapse .collapse, #" + accordionId + " .accordion .collapse)").each(function() {
+ collapsibleIds.push(this.id);
+ });
+ if (collapsibleIds[0]) {
+ var collapsible = $("#" + collapsibleIds[0]);
+ collapsible.removeClass("collapse");
+ collapsible.addClass("in");
+ }
+ for (var i in collapsibleIds) {
+ var collapsible = $("#" + collapsibleIds[i]);
+ if (i == 0) {
+ $(collapsible[0].trigger).removeClass("collapsed");
+ collapsible.removeClass("collapse");
+ collapsible.addClass("in");
+ } else {
+ $(collapsible[0].trigger).addClass("collapsed");
+ }
+ collapsible[0].collapsibleIds = collapsibleIds;
+ }
+ },
+
+ editable: {
+ adjustReflectionEditor: function(editorId) {
+ var editor = $("#" + editorId);
+ var input = editor.find(".value>input[type=checkbox]");
+ input.parent().prev("label.name").addClass("pull-left");
+ input.after("<div style='clear:both;'/>")
+
+ input = editor.find(".value>div>input[type=checkbox]");
+ input.parent().parent().prev("label.name").addClass("pull-left");
+ input.after("<div style='clear:both;'/>")
+ }
+ },
+
+ form: {
+ /*
+ * This function can be called to mark enclosing form of specified element dirty. It should be
+ * called if underlying data has been changed but no form fields are updated, for instance
+ * when sorting the elements inside a form.
+ */
+ markDirty: function($forms) {
+ $forms.addClass("dirty").each(function() {
+ pmease.commons.form.dirtyChanged($(this));
+ });
+ },
+ markClean: function($forms) {
+ $forms.removeClass("dirty").each(function() {
+ pmease.commons.form.dirtyChanged($(this));
+ });
+ },
+ removeDirty: function(triggerId, $forms) {
+ $(function() {
+ var $trigger = $("#" + triggerId);
+
+ var previousClick;
+
+ var handlers = $._data($trigger[0], 'events').click;
+
+ $.each(handlers, function(i,f) {
+ previousClick = f.handler;
+ return false;
+ });
+
+ $trigger.unbind('click');
+
+ $trigger.click(function(event){
+ pmease.commons.form.markClean($forms);
+ previousClick(event);
+ });
+ });
+ },
+ trackDirty: function(form) {
+ var $form = $(form);
+ if ($form.find(".dirty-aware").length != 0 || $form.hasClass("leave-confirm")) {
+ $form.areYouSure({
+ "silent": !$form.hasClass("leave-confirm"),
+ "addRemoveFieldsMarksDirty": true,
+ change: function() {
+ pmease.commons.form.dirtyChanged($(this));
+ }
+ });
+ if ($form.find(".has-error").length != 0) {
+ $form.addClass("dirty");
+ }
+ pmease.commons.form.dirtyChanged($form);
+ }
+ },
+ dirtyChanged: function($form) {
+ $dirtyAware = $form.find(".dirty-aware");
+ if ($dirtyAware.length != 0) {
+ if ($form.hasClass("dirty")) {
+ $dirtyAware.removeAttr("disabled");
+ } else {
+ $dirtyAware.attr("disabled", "disabled");
+ }
+ }
+ },
+ setupDirtyCheck: function() {
+ $("form").each(function() {
+ pmease.commons.form.trackDirty(this);
+ });
+
+ $(document).on("elementReplaced", function(event, componentId) {
+ var $component = $("#" + componentId);
+ var $forms = $component.find("form");
+ if ($component.is("form"))
+ $forms = $forms.add($component);
+ $forms.each(function() {
+ pmease.commons.form.trackDirty(this);
+ });
+ $component.closest("form.ays-inited").not($component).trigger("checkform.areYouSure");
+ });
+
+ if (Wicket && Wicket.Ajax) {
+ var processAjaxResponse = Wicket.Ajax.Call.prototype.processAjaxResponse;
+ Wicket.Ajax.Call.prototype.processAjaxResponse = function (data, textStatus, jqXHR, context) {
+ if (jqXHR.readyState === 4) {
+ var redirectUrl;
+ try {
+ redirectUrl = jqXHR.getResponseHeader('Ajax-Location');
+ } catch (ignore) { // might happen in older mozilla
+ }
+
+ if (typeof(redirectUrl) !== "undefined" && redirectUrl !== null && redirectUrl !== "") {
+ $("form.leave-confirm").removeClass("dirty");
+ }
+ }
+ processAjaxResponse.call(this, data, textStatus, jqXHR, context);
+ }
+ }
+ },
+ confirmLeave: function(containerId) {
+ var $container;
+ if (containerId)
+ $container = $("#" + containerId);
+ else
+ $container = $(document);
+ var dirty = "form.leave-confirm.dirty";
+ if ($container.is(dirty) || $container.find(dirty).length != 0)
+ return confirm("There are unsaved changes, do you want to discard and continue?");
+ else
+ return true;
+ }
+ },
+ setupAutoSize: function() {
+ autosize($("textarea"));
+ $(document).on("elementReplaced", function(event, componentId) {
+ var $component = $("#" + componentId);
+ var $textarea = $component.find("textarea");
+ if ($component.is("textarea"))
+ $textarea = $textarea.add($component);
+ autosize($textarea);
+ });
+ },
+ setupAjaxLoadingIndicator: function() {
+ $("#ajax-loading-overlay").click(function(e) {
+ e.stopPropagation();
+ });
+
+ Wicket.Event.subscribe('/ajax/call/beforeSend', function() {
+ var $ajaxLoadingIndicator = $("#ajax-loading-indicator");
+ if ($ajaxLoadingIndicator[0].timer)
+ clearTimeout($ajaxLoadingIndicator[0].timer);
+ $ajaxLoadingIndicator[0].timer = setTimeout(function() {
+ if (!$ajaxLoadingIndicator.is(":visible") && $(".ajax-indicator:visible").length == 0)
+ $ajaxLoadingIndicator.show();
+ }, 2000);
+ });
+
+ Wicket.Event.subscribe('/ajax/call/complete', function() {
+ var $ajaxLoadingIndicator = $("#ajax-loading-indicator");
+ if ($ajaxLoadingIndicator[0].timer) {
+ clearTimeout($ajaxLoadingIndicator[0].timer);
+ $ajaxLoadingIndicator[0].timer = null;
+ }
+ $ajaxLoadingIndicator.hide();
+ });
+ },
+
+ focus: {
+ $components: null,
+
+ focusOn: function(componentId) {
+ if (componentId)
+ pmease.commons.focus.doFocus($("#" + componentId));
+ pmease.commons.focus.$components = null;
+ },
+
+ doFocus: function($containers) {
+ var $inError = $containers.find(".has-error:first .focusable");
+ if ($inError.length != 0) {
+ $inError.focus();
+ } else {
+ $containers.find(".focusable:visible").each(function() {
+ var $this = $(this);
+ if ($this.parents(".nofocus").length == 0) {
+ $this.focus();
+ return false;
+ }
+ });
+ }
+ },
+
+ setupAutoFocus: function() {
+ if (typeof(Wicket) != "undefined" && typeof(Wicket.Focus) != "undefined") {
+ var wicketSetFocusOnId = Wicket.Focus.setFocusOnId;
+ Wicket.Focus.setFocusOnId = function(componentId) {
+ pmease.commons.focus.focusOn(componentId);
+ wicketSetFocusOnId(componentId);
+ }
+ }
+
+ Wicket.Event.subscribe('/ajax/call/beforeSend', function() {
+ pmease.commons.focus.$components = $();
+ });
+ Wicket.Event.subscribe('/ajax/call/complete', function() {
+ if (pmease.commons.focus.$components != null)
+ pmease.commons.focus.doFocus(pmease.commons.focus.$components);
+ });
+
+ pmease.commons.focus.doFocus($(document));
+
+ $(document).on("elementReplaced", function(event, componentId) {
+ if (pmease.commons.focus.$components != null)
+ pmease.commons.focus.$components = pmease.commons.focus.$components.add("#" + componentId);
+ });
+ },
+
+ },
+
+ // Disable specified button if value of specified input is blank
+ disableIfBlank: function(inputId, buttonId) {
+ var $input = $("#" + inputId);
+ $input.bind("input propertychange keyup", function() {
+ var value = $(this).val();
+ var $button = $("#" + buttonId);
+ if (value.trim().length != 0)
+ $button.removeAttr("disabled");
+ else
+ $button.attr("disabled", "disabled");
+ });
+ $input.trigger("input");
+ },
+
+ autoHeight: function(targetSelector, bottomOffset) {
+ var adjustHeight = function() {
+ $(targetSelector).css("max-height", $(document).scrollTop() + $(window).height()
+ - $(targetSelector).offset().top - bottomOffset + "px");
+ };
+ adjustHeight();
+ $(window).resize(adjustHeight);
+ $(window).scroll(adjustHeight);
+ },
+
+ showSessionFeedback: function() {
+ if ($("#session-feedback li").length != 0) {
+ var feedback = $("#session-feedback");
+ var x = ($(window).width() - feedback.outerWidth()) / 2;
+ feedback.css("left", x+$(window).scrollLeft());
+ feedback.css("top", $(window).scrollTop());
+ feedback.slideDown("slow");
+
+ var body = $("body");
+ if (body[0].hideCatchAllFeedbackTimer) {
+ clearTimeout(body[0].hideCatchAllFeedbackTimer);
+ }
+ body[0].hideCatchAllFeedbackTimer = setTimeout(function() {
+ $("#session-feedback").slideUp();
+ }, 5000);
+ }
+ },
+
+ backToTop: function(backToTop) {
+ var $backToTop = $(backToTop);
+ $backToTop.hide();
+ $(window).scroll(function(){
+ if ($(window).scrollTop()>500)
+ $backToTop.fadeIn(1000);
+ else
+ $backToTop.fadeOut(1000);
+ });
+ $backToTop.click(function(){
+ $("body, html").animate({scrollTop:0}, 700);
+ return false;
+ });
+ },
+
+ choiceFormatter: {
+ id: {
+ formatSelection: function(choice) {
+ return choice.id;
+ },
+
+ formatResult: function(choice) {
+ return choice.id;
+ },
+
+ escapeMarkup: function(m) {
+ return m;
+ }
+ }
+ },
+
+ websocket: {
+ setupCallback: function() {
+ Wicket.Event.subscribe("/websocket/message", function(jqEvent, message) {
+ if (message == "RenderCallback")
+ Wicket.WebSocket.send(message);
+ else if (message == "ErrorMessage")
+ $("#websocket-error").show();
+ });
+ Wicket.Event.subscribe("/websocket/open", function(jqEvent) {
+ Wicket.WebSocket.send("ConnectCallback");
+ });
+ }
+ },
+
+ history: {
+ getHashlessUrl: function(url) {
+ var index = url.indexOf('#');
+ if (index != -1)
+ return url.substring(0, index);
+ else
+ return url;
+ },
+ init: function(callback) {
+ // Use a timeout here solve the problem that Safari (and previous versions of Chrome)
+ // fires event "onpopstate" on initial page load and this causes the page to reload
+ // infinitely
+ setTimeout(function() {
+ window.onpopstate = function(event) {
+ if (pmease.commons.history.getHashlessUrl(window.location.href)
+ != pmease.commons.history.getHashlessUrl(pmease.commons.history.current.url)) {
+ if (pmease.commons.form.confirmLeave()) {
+ if (!event.state || !event.state.data) {
+ location.reload();
+ } else {
+ callback(event.state.data);
+ pmease.commons.history.current = {
+ state: event.state,
+ url: window.location.href
+ };
+ }
+ } else {
+ /*
+ * In case we want to stay in the page, we should also re-push previous url
+ * as url has already been changed when user hits back/forward button
+ */
+ history.pushState(pmease.commons.history.current.state, '' ,
+ pmease.commons.history.current.url);
+ }
+ }
+ };
+ }, 100);
+
+ pmease.commons.history.current = {
+ url: window.location.href
+ };
+ },
+ pushState: function(url, data) {
+ $(".autofit:visible").first().trigger("storeViewState");
+ var state = {data: data};
+ pmease.commons.history.current = {state: state, url: url};
+ history.pushState(state, '', url);
+ setTimeout(function() {
+ pmease.commons.history.setVisited();
+ }, 100);
+ },
+ /*
+ * visited flag is used to determine whether or not a page is newly visited
+ * or loaded via back/forward button. If loaded via back/forward button we
+ * will not respect scroll flag (such as mark param in url) and let browser
+ * scroll to original position for better usage experience
+ */
+ setVisited: function() {
+ var state = history.state;
+ if (!state)
+ state = {};
+ if (!state.loaded) {
+ var newState = {viewState: state.viewState, data: state.data, visited: true};
+ history.replaceState(newState, '', window.location.href);
+ pmease.commons.history.current = {
+ state: newState,
+ url: window.location.href
+ };
+ }
+ },
+ isVisited: function() {
+ return history.state && history.state.visited;
+ },
+ setViewState: function(viewState) {
+ var state = history.state;
+ if (!state)
+ state = {};
+ var newState = {viewState: viewState, data: state.data, visited: state.visited};
+ history.replaceState(newState, '', window.location.href );
+ pmease.commons.history.current = {
+ state: newState,
+ url: window.location.href
+ };
+ },
+ getViewState: function() {
+ if (history.state && history.state.viewState)
+ return history.state.viewState;
+ else
+ return undefined;
+ }
+ },
+ isDevice: function() {
+ var ua = navigator.userAgent.toLowerCase();
+ return ua.indexOf("android") != -1
+ || ua.indexOf("iphone") != -1
+ || ua.indexOf("ipad") != -1
+ || ua.indexOf("windows phone") != -1;
+ }
+};
+
+$(function() {
+ pmease.commons.setupAutoSize();
+ pmease.commons.setupAjaxLoadingIndicator();
+ pmease.commons.form.setupDirtyCheck();
+ pmease.commons.focus.setupAutoFocus();
+ pmease.commons.websocket.setupCallback();
+});
+
+$(window).load(function() {
+ pmease.commons.history.setVisited();
+});
+$(window).on("beforeunload", function() {
+ $(".autofit:visible").first().trigger("storeViewState");
+});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/commitgraph/commit-graph.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/commitgraph/commit-graph.js
index 0edfb74b35..e09ccf0edb 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/commitgraph/commit-graph.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/commitgraph/commit-graph.js
@@ -1,435 +1,435 @@
-gitplex.commitgraph = {
- render: function(containerId, commits) {
- var $container = $("#" + containerId);
- $container.prepend("<svg class='commit-graph'></svg>");
- var $graph = $container.children("svg");
- gitplex.commitgraph.populateData($graph, commits);
- gitplex.commitgraph.drawGraph($graph);
-
- var paper = Snap($graph[0]);
- function getCommitDot(e) {
- var $target = $(e.target);
- if (!$target.hasClass("commit") || !$target.is("li"))
- $target = $target.closest("li.commit");
- var index = $target.attr("class").split(" ").pop().split("-").pop();
- return paper.select("#" + containerId + "-commit-dot-" + index);
- }
- var $commits = $graph.next("ul").find("li.commit");
- $commits.off("mouseenter");
- $commits.off("mouseleave");
- $commits.mouseenter(function(e) {
- getCommitDot(e).attr("strokeWidth", 3);
- });
- $commits.mouseleave(function(e) {
- getCommitDot(e).attr("strokeWidth", 0);
- });
- },
-
- /*
- * commits is an array of ordered commit object, and the commit object is itself a
- * list of parent indexes
- */
- populateData: function($graph, commits) {
- var columnsLimit = 12;
-
- var colorsLimit = 12;
-
- /*
- * rows store the map of line to row. A line represents a child->parent relationship.
- * For instance line(1,5) represents the line from commit at row 1 (the child ) to
- * commit at row 5 (the parent). In case child row index equals parent row index,
- * the line represents a commit.
- *
- */
- var rows = [];
- var parent2children = {};
- var colors = {};
-
- var colorStack = [];
- function getSortedLines(row, reverse) {
- var lines = [];
- var keys = Object.keys(row);
- for (var i in keys)
- lines.push(keys[i]);
-
- lines.sort(function(x, y) {
- if (reverse)
- return row[y] - row[x];
- else
- return row[x] - row[y];
- });
- return lines;
- }
-
- function fromKey(lineKey) {
- return lineKey.split(',').map(function(item) {
- return parseInt(item, 10);
- });
- }
-
- function toKey(line) {
- return line[0] + "," + line[1];
- }
-
- function assignColor(lineKey) {
- var color = colors[lineKey];
- if (color == undefined) {
- if (colorStack.length == 0) {
- for (var i=colorsLimit; i>=1; i--)
- colorStack.push(i);
- }
- color = colorStack.pop();
- colors[lineKey] = color;
- }
- return color;
- }
-
- for (var i in commits) {
- commits[i] = commits[i][1];
- var parents = commits[i];
- for (var j in parents) {
- var parent = parents[j];
- var children = parent2children[parent];
- if (children == undefined) {
- children = [];
- parent2children[parent] = children;
- }
- children.push(i);
- }
- }
-
- for (var rowIndex in commits) {
- var row = {};
- if (rowIndex == 0) {
- row["0,0"] = 0;
- } else {
- var parents = commits[rowIndex-1];
- // special line represents the commit at rowIndex itself
- var commitLineKey = toKey([rowIndex, rowIndex]);
- var lastRow = rows[rowIndex-1];
- var column = 0;
- var linesOfLastRow = getSortedLines(lastRow, false);
- for (var i in linesOfLastRow) {
- var lineOfLastRow = fromKey(linesOfLastRow[i]);
- if (lineOfLastRow[1] < 0) // line is cutted due to max columns limitation
- continue;
- if (lineOfLastRow[1] != lineOfLastRow[0]) { // not a commit point
- // line not started from last row, in this case, the line
- // only occupies a column when it goes through current row
- if (lineOfLastRow[1] == rowIndex) {
- if (row[commitLineKey] == undefined)
- row[commitLineKey] = column++;
- } else {
- row[toKey(lineOfLastRow)] = column++;
- }
- } else {
- for (var j in parents) {
- var parent = parents[j];
- if (parent == rowIndex) {
- if (row[commitLineKey] == undefined)
- row[commitLineKey] = column++;
- } else {
- row[toKey([rowIndex-1, parent])] = column++;
- }
- }
- }
- }
-
- if (row[commitLineKey] == undefined)
- row[commitLineKey] = column++;
- if (column > columnsLimit) {
- var reversedLines = getSortedLines(row, true);
- for (var i in reversedLines) {
- var line = fromKey(reversedLines[i]);
- if (line[0] == rowIndex-1) {
- var cuttedLine = [line[0], line[1]*-1];
- var lineKey = toKey(line);
- var lineColumn = row[lineKey];
- delete row[lineKey];
- row[toKey(cuttedLine)] = lineColumn;
- column--;
- if (column == columnsLimit)
- break;
- }
- }
- if (column != columnsLimit)
- throw "Error calculating commit graph at row " + rowIndex;
- }
-
- var cuttedLines = [];
- var children = parent2children[rowIndex];
- if (children) {
- for (var i in children) {
- var child = children[i];
- if (child != rowIndex-1) {
- var line = [child, rowIndex];
- var cuttedLine = [child, rowIndex*-1];
- var lineKey = toKey(line);
- var cuttedLineKey = toKey(cuttedLine);
- if (lastRow[lineKey] == undefined) {
- if (lastRow[cuttedLineKey] != undefined) {
- var cuttedLineColumn = lastRow[cuttedLineKey];
- delete lastRow[cuttedLineKey];
- lastRow[lineKey] = cuttedLineColumn;
- } else {
- cuttedLines.push(cuttedLine);
- }
- }
- }
- }
- }
- if (cuttedLines.length != 0) {
- // for every disappeared line, we need to make them appear again in last row
- // so that end part of the line can be drawn from last row to this row.
- // Below code find column in last row to insert these appeared lines, and
- // we want to make sure that this column can result in minimum line crossovers.
- var commitColumn = row[commitLineKey];
- var insertColumn = 0;
- for (var i=linesOfLastRow.length-1; i>=0; i--) {
- var lineOfLastRowKey = linesOfLastRow[i];
- var lineOfLastRow = fromKey(lineOfLastRowKey);
- if (lineOfLastRow[0] == lineOfLastRow[1]) {
- var found = false;
- for (var j in parents) {
- var parent = parents[j];
- var lineKey = toKey([rowIndex-1, parent]);
- var lineColumn = row[lineKey];
- if (lineColumn != undefined) {
- if (lineColumn<commitColumn) {
- found = true;
- break;
- }
- } else {
- lineKey = toKey([rowIndex-1, parent*-1]);
- lineColumn = row[lineKey];
- if (lineColumn != undefined && lineColumn<commitColumn) {
- found = true;
- break;
- }
- }
- }
- if (found) {
- insertColumn = i;
- break;
- }
- } else {
- var lineColumn = row[lineOfLastRowKey];
- if (lineColumn!=undefined && lineColumn<commitColumn) {
- insertColumn = i;
- break;
- }
- }
- }
- column = insertColumn+1;
- for (var i in cuttedLines)
- lastRow[toKey(cuttedLines[i])] = column++;
- for (var i=insertColumn+1; i<linesOfLastRow.length; i++)
- lastRow[linesOfLastRow[i]] = column++;
- }
- }
- rows.push(row);
- }
- for (var i=1; i<rows.length; i++) {
- var row = rows[i];
- var lastRow = rows[i-1];
- var lines = getSortedLines(row, false);
- var lastLines = getSortedLines(lastRow, true);
-
- var recycledColors = [];
-
- for (var j in lines) {
- var line = fromKey(lines[j]);
- if (line[0] == line[1]) {
- for (var k in lastLines) {
- var lastLine = fromKey(lastLines[k]);
- if (lastLine[0] == lastLine[1]) {
- if (commits[i-1].indexOf(i) != -1)
- recycledColors.push(assignColor(toKey([i-1, i])));
- } else if (lastLine[1] == i) {
- recycledColors.push(assignColor(toKey(lastLine)));
- } else if (lastLine[1]*-1 == i) {
- recycledColors.push(assignColor(toKey([lastLine[0], i])));
- }
- }
- } else {
- if (line[1] < 0)
- assignColor(toKey([line[0], line[1]*-1]));
- else
- assignColor(toKey(line));
- }
- }
- for (var j in recycledColors)
- colorStack.push(recycledColors[j]);
- }
-
- $graph.data("rows", rows);
- $graph.data("commits", commits);
- $graph.data("parent2children", parent2children);
- $graph.data("colors", colors);
- },
- drawGraph: function($graph) {
- var columnWidth = 12;
- var topOffset = 22;
- var rightOffset = 12;
- var dotSize = 3;
-
- var dotColorClass = "commit-dot-color";
- var lineColorClass = "commit-line-color";
-
- var rows = $graph.data("rows");
- var commits = $graph.data("commits");
- var parent2children = $graph.data("parent2children");
- var colors = $graph.data("colors");;
-
- var maxColumns = 0;
- for (var i in rows) {
- var columns = Object.keys(rows[i]).length;
- if (columns > maxColumns)
- maxColumns = columns;
- }
-
- function fromKey(lineKey) {
- return lineKey.split(',').map(function(item) {
- return parseInt(item, 10);
- });
- }
-
- function toKey(line) {
- return line[0] + "," + line[1];
- }
-
- var $container = $graph.parent();
- var $list = $container.children("ul");
- var containerTop = $container.offset().top - topOffset;
-
- function getTop(row) {
- return $list.find(".commit-item-"+row).offset().top - containerTop;
- }
-
- function getLeft(column) {
- return column*columnWidth + columnWidth/2;
- }
-
- $list.css("margin-left", maxColumns*columnWidth+rightOffset);
-
- $graph.empty();
- $graph.height($list.outerHeight());
- $graph.width(maxColumns*columnWidth);
- var paper = Snap($graph[0]);
-
- for (var i=0; i<commits.length; i++) {
- var parents = commits[i];
- var row = rows[i];
-
- var column = row[toKey([i, i])];
- var left = getLeft(column);
- var top = getTop(i);
-
- if (i != commits.length-1) {
- var nextRow = rows[i+1];
- var nextTop = getTop(i+1);
- for (var lineKey in row) {
- var line = fromKey(lineKey);
- column = row[lineKey];
-
- function drawLine(nextColumn, color, upArrow, downArrow) {
- if (nextColumn != undefined) {
- var arrowOffset = 10;
- var arrowWidth = 4;
- var arrowHeight = 8;
- var left = getLeft(column);
- var nextLeft = getLeft(nextColumn);
- var line = paper.line(left, top, nextLeft, nextTop);
- line.addClass("commit-line");
- line.addClass(lineColorClass + color);
- var arrow;
- if (upArrow) {
- arrow = paper.path("M" + left + " " + top + "l0 -" + arrowOffset
- + "l-" + arrowWidth + " " + arrowHeight + "m" + arrowWidth*2
- + " 0l-" + arrowWidth + " -" + arrowHeight);
- } else if (downArrow) {
- arrow = paper.path("M" + nextLeft + " " + nextTop + "l0 " + arrowOffset
- + "l-" + arrowWidth + " -" + arrowHeight + "m" + arrowWidth*2
- + " 0l-" + arrowWidth + " " + arrowHeight);
- }
- if (arrow) {
- arrow.addClass("commit-line");
- arrow.addClass(lineColorClass + color);
- }
- }
- }
-
- if (line[0] == line[1]) {
- for (var j in parents) {
- var parent = parents[j];
- if (parent == i+1) {
- drawLine(nextRow[toKey([i+1, i+1])], colors[toKey([i, i+1])]);
- } else {
- var nextLineKey = toKey([i, parent]);
- var nextColumn = nextRow[nextLineKey];
- if (nextColumn != undefined) {
- drawLine(nextColumn, colors[nextLineKey], false, false);
- } else {
- var nextCuttedLineKey = toKey([i, -1*parent]);
- drawLine(nextRow[nextCuttedLineKey], colors[nextLineKey], false, true);
- }
- }
- }
- } else {
- if (line[1] < 0) {
- if (line[1]*-1 == i+1) {
- var nextColumn = nextRow[toKey([i+1, i+1])];
- drawLine(nextColumn, colors[toKey([line[0], i+1])], true, false);
- }
- } else if (line[1] == i+1){
- var nextColumn = nextRow[toKey([i+1, i+1])];
- drawLine(nextColumn, colors[lineKey], false, false);
- } else {
- drawLine(nextRow[lineKey], colors[lineKey], false, false);
- }
- }
- }
- }
- }
-
- for (var i in commits) {
- var parents = commits[i];
- var row = rows[i];
-
- var column = row[toKey([i, i])];
- var left = getLeft(column);
- var top = getTop(i);
- var circle = paper.circle(left, top, dotSize);
- circle.addClass("commit-dot");
- if (parents.length != 0) {
- circle.addClass(dotColorClass + colors[toKey([i, parents[0]])]);
- } else {
- var children = parent2children[i];
- if (children && children.length != 0)
- circle.addClass(dotColorClass + colors[toKey([children[0], i])]);
- }
- circle.attr("id", $graph.parent().attr("id") + "-commit-dot-" + i);
- circle.mouseover(function() {
- this.attr("strokeWidth", 4);
- var index = this.attr("id").split("-").pop();
- $list.find(".commit-item-" + index).addClass("hover");
- });
- circle.mouseout(function() {
- this.attr("strokeWidth", 0);
- var index = this.attr("id").split("-").pop();
- $list.find(".commit-item-" + index).removeClass("hover");
- });
- }
-
- }
-};
-$(function() {
- if ($(".commit-graph").length != 0) {
- $(window).resize(function(e) {
- e.stopPropagation();
- $(".commit-graph").each(function() {
- gitplex.commitgraph.drawGraph($(this));
- });
- });
- }
-});
+gitplex.commitgraph = {
+ render: function(containerId, commits) {
+ var $container = $("#" + containerId);
+ $container.prepend("<svg class='commit-graph'></svg>");
+ var $graph = $container.children("svg");
+ gitplex.commitgraph.populateData($graph, commits);
+ gitplex.commitgraph.drawGraph($graph);
+
+ var paper = Snap($graph[0]);
+ function getCommitDot(e) {
+ var $target = $(e.target);
+ if (!$target.hasClass("commit") || !$target.is("li"))
+ $target = $target.closest("li.commit");
+ var index = $target.attr("class").split(" ").pop().split("-").pop();
+ return paper.select("#" + containerId + "-commit-dot-" + index);
+ }
+ var $commits = $graph.next("ul").find("li.commit");
+ $commits.off("mouseenter");
+ $commits.off("mouseleave");
+ $commits.mouseenter(function(e) {
+ getCommitDot(e).attr("strokeWidth", 3);
+ });
+ $commits.mouseleave(function(e) {
+ getCommitDot(e).attr("strokeWidth", 0);
+ });
+ },
+
+ /*
+ * commits is an array of ordered commit object, and the commit object is itself a
+ * list of parent indexes
+ */
+ populateData: function($graph, commits) {
+ var columnsLimit = 12;
+
+ var colorsLimit = 12;
+
+ /*
+ * rows store the map of line to row. A line represents a child->parent relationship.
+ * For instance line(1,5) represents the line from commit at row 1 (the child ) to
+ * commit at row 5 (the parent). In case child row index equals parent row index,
+ * the line represents a commit.
+ *
+ */
+ var rows = [];
+ var parent2children = {};
+ var colors = {};
+
+ var colorStack = [];
+ function getSortedLines(row, reverse) {
+ var lines = [];
+ var keys = Object.keys(row);
+ for (var i in keys)
+ lines.push(keys[i]);
+
+ lines.sort(function(x, y) {
+ if (reverse)
+ return row[y] - row[x];
+ else
+ return row[x] - row[y];
+ });
+ return lines;
+ }
+
+ function fromKey(lineKey) {
+ return lineKey.split(',').map(function(item) {
+ return parseInt(item, 10);
+ });
+ }
+
+ function toKey(line) {
+ return line[0] + "," + line[1];
+ }
+
+ function assignColor(lineKey) {
+ var color = colors[lineKey];
+ if (color == undefined) {
+ if (colorStack.length == 0) {
+ for (var i=colorsLimit; i>=1; i--)
+ colorStack.push(i);
+ }
+ color = colorStack.pop();
+ colors[lineKey] = color;
+ }
+ return color;
+ }
+
+ for (var i in commits) {
+ commits[i] = commits[i][1];
+ var parents = commits[i];
+ for (var j in parents) {
+ var parent = parents[j];
+ var children = parent2children[parent];
+ if (children == undefined) {
+ children = [];
+ parent2children[parent] = children;
+ }
+ children.push(i);
+ }
+ }
+
+ for (var rowIndex in commits) {
+ var row = {};
+ if (rowIndex == 0) {
+ row["0,0"] = 0;
+ } else {
+ var parents = commits[rowIndex-1];
+ // special line represents the commit at rowIndex itself
+ var commitLineKey = toKey([rowIndex, rowIndex]);
+ var lastRow = rows[rowIndex-1];
+ var column = 0;
+ var linesOfLastRow = getSortedLines(lastRow, false);
+ for (var i in linesOfLastRow) {
+ var lineOfLastRow = fromKey(linesOfLastRow[i]);
+ if (lineOfLastRow[1] < 0) // line is cutted due to max columns limitation
+ continue;
+ if (lineOfLastRow[1] != lineOfLastRow[0]) { // not a commit point
+ // line not started from last row, in this case, the line
+ // only occupies a column when it goes through current row
+ if (lineOfLastRow[1] == rowIndex) {
+ if (row[commitLineKey] == undefined)
+ row[commitLineKey] = column++;
+ } else {
+ row[toKey(lineOfLastRow)] = column++;
+ }
+ } else {
+ for (var j in parents) {
+ var parent = parents[j];
+ if (parent == rowIndex) {
+ if (row[commitLineKey] == undefined)
+ row[commitLineKey] = column++;
+ } else {
+ row[toKey([rowIndex-1, parent])] = column++;
+ }
+ }
+ }
+ }
+
+ if (row[commitLineKey] == undefined)
+ row[commitLineKey] = column++;
+ if (column > columnsLimit) {
+ var reversedLines = getSortedLines(row, true);
+ for (var i in reversedLines) {
+ var line = fromKey(reversedLines[i]);
+ if (line[0] == rowIndex-1) {
+ var cuttedLine = [line[0], line[1]*-1];
+ var lineKey = toKey(line);
+ var lineColumn = row[lineKey];
+ delete row[lineKey];
+ row[toKey(cuttedLine)] = lineColumn;
+ column--;
+ if (column == columnsLimit)
+ break;
+ }
+ }
+ if (column != columnsLimit)
+ throw "Error calculating commit graph at row " + rowIndex;
+ }
+
+ var cuttedLines = [];
+ var children = parent2children[rowIndex];
+ if (children) {
+ for (var i in children) {
+ var child = children[i];
+ if (child != rowIndex-1) {
+ var line = [child, rowIndex];
+ var cuttedLine = [child, rowIndex*-1];
+ var lineKey = toKey(line);
+ var cuttedLineKey = toKey(cuttedLine);
+ if (lastRow[lineKey] == undefined) {
+ if (lastRow[cuttedLineKey] != undefined) {
+ var cuttedLineColumn = lastRow[cuttedLineKey];
+ delete lastRow[cuttedLineKey];
+ lastRow[lineKey] = cuttedLineColumn;
+ } else {
+ cuttedLines.push(cuttedLine);
+ }
+ }
+ }
+ }
+ }
+ if (cuttedLines.length != 0) {
+ // for every disappeared line, we need to make them appear again in last row
+ // so that end part of the line can be drawn from last row to this row.
+ // Below code find column in last row to insert these appeared lines, and
+ // we want to make sure that this column can result in minimum line crossovers.
+ var commitColumn = row[commitLineKey];
+ var insertColumn = 0;
+ for (var i=linesOfLastRow.length-1; i>=0; i--) {
+ var lineOfLastRowKey = linesOfLastRow[i];
+ var lineOfLastRow = fromKey(lineOfLastRowKey);
+ if (lineOfLastRow[0] == lineOfLastRow[1]) {
+ var found = false;
+ for (var j in parents) {
+ var parent = parents[j];
+ var lineKey = toKey([rowIndex-1, parent]);
+ var lineColumn = row[lineKey];
+ if (lineColumn != undefined) {
+ if (lineColumn<commitColumn) {
+ found = true;
+ break;
+ }
+ } else {
+ lineKey = toKey([rowIndex-1, parent*-1]);
+ lineColumn = row[lineKey];
+ if (lineColumn != undefined && lineColumn<commitColumn) {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (found) {
+ insertColumn = i;
+ break;
+ }
+ } else {
+ var lineColumn = row[lineOfLastRowKey];
+ if (lineColumn!=undefined && lineColumn<commitColumn) {
+ insertColumn = i;
+ break;
+ }
+ }
+ }
+ column = insertColumn+1;
+ for (var i in cuttedLines)
+ lastRow[toKey(cuttedLines[i])] = column++;
+ for (var i=insertColumn+1; i<linesOfLastRow.length; i++)
+ lastRow[linesOfLastRow[i]] = column++;
+ }
+ }
+ rows.push(row);
+ }
+ for (var i=1; i<rows.length; i++) {
+ var row = rows[i];
+ var lastRow = rows[i-1];
+ var lines = getSortedLines(row, false);
+ var lastLines = getSortedLines(lastRow, true);
+
+ var recycledColors = [];
+
+ for (var j in lines) {
+ var line = fromKey(lines[j]);
+ if (line[0] == line[1]) {
+ for (var k in lastLines) {
+ var lastLine = fromKey(lastLines[k]);
+ if (lastLine[0] == lastLine[1]) {
+ if (commits[i-1].indexOf(i) != -1)
+ recycledColors.push(assignColor(toKey([i-1, i])));
+ } else if (lastLine[1] == i) {
+ recycledColors.push(assignColor(toKey(lastLine)));
+ } else if (lastLine[1]*-1 == i) {
+ recycledColors.push(assignColor(toKey([lastLine[0], i])));
+ }
+ }
+ } else {
+ if (line[1] < 0)
+ assignColor(toKey([line[0], line[1]*-1]));
+ else
+ assignColor(toKey(line));
+ }
+ }
+ for (var j in recycledColors)
+ colorStack.push(recycledColors[j]);
+ }
+
+ $graph.data("rows", rows);
+ $graph.data("commits", commits);
+ $graph.data("parent2children", parent2children);
+ $graph.data("colors", colors);
+ },
+ drawGraph: function($graph) {
+ var columnWidth = 12;
+ var topOffset = 22;
+ var rightOffset = 12;
+ var dotSize = 3;
+
+ var dotColorClass = "commit-dot-color";
+ var lineColorClass = "commit-line-color";
+
+ var rows = $graph.data("rows");
+ var commits = $graph.data("commits");
+ var parent2children = $graph.data("parent2children");
+ var colors = $graph.data("colors");;
+
+ var maxColumns = 0;
+ for (var i in rows) {
+ var columns = Object.keys(rows[i]).length;
+ if (columns > maxColumns)
+ maxColumns = columns;
+ }
+
+ function fromKey(lineKey) {
+ return lineKey.split(',').map(function(item) {
+ return parseInt(item, 10);
+ });
+ }
+
+ function toKey(line) {
+ return line[0] + "," + line[1];
+ }
+
+ var $container = $graph.parent();
+ var $list = $container.children("ul");
+ var containerTop = $container.offset().top - topOffset;
+
+ function getTop(row) {
+ return $list.find(".commit-item-"+row).offset().top - containerTop;
+ }
+
+ function getLeft(column) {
+ return column*columnWidth + columnWidth/2;
+ }
+
+ $list.css("margin-left", maxColumns*columnWidth+rightOffset);
+
+ $graph.empty();
+ $graph.height($list.outerHeight());
+ $graph.width(maxColumns*columnWidth);
+ var paper = Snap($graph[0]);
+
+ for (var i=0; i<commits.length; i++) {
+ var parents = commits[i];
+ var row = rows[i];
+
+ var column = row[toKey([i, i])];
+ var left = getLeft(column);
+ var top = getTop(i);
+
+ if (i != commits.length-1) {
+ var nextRow = rows[i+1];
+ var nextTop = getTop(i+1);
+ for (var lineKey in row) {
+ var line = fromKey(lineKey);
+ column = row[lineKey];
+
+ function drawLine(nextColumn, color, upArrow, downArrow) {
+ if (nextColumn != undefined) {
+ var arrowOffset = 10;
+ var arrowWidth = 4;
+ var arrowHeight = 8;
+ var left = getLeft(column);
+ var nextLeft = getLeft(nextColumn);
+ var line = paper.line(left, top, nextLeft, nextTop);
+ line.addClass("commit-line");
+ line.addClass(lineColorClass + color);
+ var arrow;
+ if (upArrow) {
+ arrow = paper.path("M" + left + " " + top + "l0 -" + arrowOffset
+ + "l-" + arrowWidth + " " + arrowHeight + "m" + arrowWidth*2
+ + " 0l-" + arrowWidth + " -" + arrowHeight);
+ } else if (downArrow) {
+ arrow = paper.path("M" + nextLeft + " " + nextTop + "l0 " + arrowOffset
+ + "l-" + arrowWidth + " -" + arrowHeight + "m" + arrowWidth*2
+ + " 0l-" + arrowWidth + " " + arrowHeight);
+ }
+ if (arrow) {
+ arrow.addClass("commit-line");
+ arrow.addClass(lineColorClass + color);
+ }
+ }
+ }
+
+ if (line[0] == line[1]) {
+ for (var j in parents) {
+ var parent = parents[j];
+ if (parent == i+1) {
+ drawLine(nextRow[toKey([i+1, i+1])], colors[toKey([i, i+1])]);
+ } else {
+ var nextLineKey = toKey([i, parent]);
+ var nextColumn = nextRow[nextLineKey];
+ if (nextColumn != undefined) {
+ drawLine(nextColumn, colors[nextLineKey], false, false);
+ } else {
+ var nextCuttedLineKey = toKey([i, -1*parent]);
+ drawLine(nextRow[nextCuttedLineKey], colors[nextLineKey], false, true);
+ }
+ }
+ }
+ } else {
+ if (line[1] < 0) {
+ if (line[1]*-1 == i+1) {
+ var nextColumn = nextRow[toKey([i+1, i+1])];
+ drawLine(nextColumn, colors[toKey([line[0], i+1])], true, false);
+ }
+ } else if (line[1] == i+1){
+ var nextColumn = nextRow[toKey([i+1, i+1])];
+ drawLine(nextColumn, colors[lineKey], false, false);
+ } else {
+ drawLine(nextRow[lineKey], colors[lineKey], false, false);
+ }
+ }
+ }
+ }
+ }
+
+ for (var i in commits) {
+ var parents = commits[i];
+ var row = rows[i];
+
+ var column = row[toKey([i, i])];
+ var left = getLeft(column);
+ var top = getTop(i);
+ var circle = paper.circle(left, top, dotSize);
+ circle.addClass("commit-dot");
+ if (parents.length != 0) {
+ circle.addClass(dotColorClass + colors[toKey([i, parents[0]])]);
+ } else {
+ var children = parent2children[i];
+ if (children && children.length != 0)
+ circle.addClass(dotColorClass + colors[toKey([children[0], i])]);
+ }
+ circle.attr("id", $graph.parent().attr("id") + "-commit-dot-" + i);
+ circle.mouseover(function() {
+ this.attr("strokeWidth", 4);
+ var index = this.attr("id").split("-").pop();
+ $list.find(".commit-item-" + index).addClass("hover");
+ });
+ circle.mouseout(function() {
+ this.attr("strokeWidth", 0);
+ var index = this.attr("id").split("-").pop();
+ $list.find(".commit-item-" + index).removeClass("hover");
+ });
+ }
+
+ }
+};
+$(function() {
+ $(window).resize(function(e) {
+ if ($(".commit-graph").length == 0)
+ return;
+ e.stopPropagation();
+ $(".commit-graph").each(function() {
+ gitplex.commitgraph.drawGraph($(this));
+ });
+ });
+});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
index c1b3ff47b1..ca4ead89ce 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
@@ -18,6 +18,9 @@ gitplex.revisionDiff = {
gitplex.revisionDiff.reposition();
},
reposition: function(e) {
+ if ($(".revision-diff>.body>.detail").length == 0)
+ return;
+
if (e) {
e.stopPropagation();
if (e.target && $(e.target).hasClass("ui-resizable"))
@@ -93,6 +96,5 @@ gitplex.revisionDiff = {
}
};
$(function() {
- if ($(".revision-diff>.body>.detail").length != 0)
- $(window).on("scroll resize", gitplex.revisionDiff.reposition);
+ $(window).on("scroll resize", gitplex.revisionDiff.reposition);
});