From c4d31b70a0c4419df51f91b5b4fc138b0548ce74 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 3 May 2018 16:07:55 +0200 Subject: [PATCH] clicking twice on tool tip button doesn't open windo twice --- .../src/main/js/gui/leftPanel/GuiUtils.js | 36 ++++++++++--------- .../test/js/gui/leftPanel/GuiUtils-test.js | 24 ++++++++++--- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js index e06c530724..59be27c9c7 100644 --- a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js +++ b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js @@ -674,23 +674,27 @@ GuiUtils.prototype.createHelpButton = function (toolTip, useXss) { content: '<span class="ui-icon ui-icon-help" style="margin-left: -0.5em;"/>', xss: false }); + var helpDialogDiv = undefined; helpTipButton.onclick = function () { - var helpDialogDiv = Functions.createElement({ - type: "div", - content: helpContent, - xss: false - }); - $(helpDialogDiv).dialog({ - close: function () { - $(this).dialog('destroy').remove(); - }, - position: { - my: "left top", - at: "left bottom", - of: helpTipButton - } - }); - $('.ui-dialog').find("a").blur(); + if (helpDialogDiv === undefined) { + helpDialogDiv = Functions.createElement({ + type: "div", + content: helpContent, + xss: false + }); + $(helpDialogDiv).dialog({ + close: function () { + $(this).dialog('destroy').remove(); + helpDialogDiv = undefined; + }, + position: { + my: "left top", + at: "left bottom", + of: helpTipButton + } + }); + $('.ui-dialog').find("a").blur(); + } }; return helpTipButton; }; diff --git a/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js b/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js index d8194e12f8..078ec940fa 100644 --- a/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js +++ b/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js @@ -195,11 +195,25 @@ describe('GuiUtils', function () { }); }); - it('createHelpButton', function () { - var guiUtils = new GuiUtils(helper.getConfiguration()); - var button = guiUtils.createHelpButton("test tooltip"); - button.onclick(); - $(".ui-dialog-titlebar-close").click(); + describe('createHelpButton', function () { + it('default', function () { + var guiUtils = new GuiUtils(helper.getConfiguration()); + var button = guiUtils.createHelpButton("test tooltip"); + button.onclick(); + $(".ui-dialog-titlebar-close").click(); + }); + it('click twice', function () { + var guiUtils = new GuiUtils(helper.getConfiguration()); + var button = guiUtils.createHelpButton("test tooltip"); + button.onclick(); + // noinspection JSJQueryEfficiency + var counts = $("div").length; + button.onclick(); + // noinspection JSJQueryEfficiency + var counts2 = $("div").length; + assert.equal(counts, counts2); + $(".ui-dialog-titlebar-close").click(); + }); }); describe('createAnnotationList', function () { -- GitLab