From 666c8dcf00559cef71db64d6aa5e207077073d2c Mon Sep 17 00:00:00 2001 From: Rafael Ostertag Date: Thu, 10 Aug 2017 14:36:18 +0200 Subject: [PATCH 1/3] WIP commit. --- javascript/src/Alert.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/javascript/src/Alert.js b/javascript/src/Alert.js index 0bdf82b1..75820de5 100644 --- a/javascript/src/Alert.js +++ b/javascript/src/Alert.js @@ -19,11 +19,7 @@ var QfqNS = QfqNS || {}; /** * Display a message. * - * Display one message on a page. Several instances can be used per page, which results in messages being - * stacked, with the latest message being at the bottom. - * - * The first instance displaying a message will append an `alert container` to the body. The last message being - * dismissed will remove the `alert container`. A typical call sequence might look like: + * A typical call sequence might look like: * * var alert = new QfqNS.Alert({ * message: "Text being displayed", -- GitLab From 4858edcd45d1e2c8f2da8748472a213fe221ee8f Mon Sep 17 00:00:00 2001 From: Rafael Ostertag Date: Fri, 11 Aug 2017 11:28:09 +0200 Subject: [PATCH 2/3] Implemented https://project.math.uzh.ch/issues/4143 --- javascript/src/Alert.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/javascript/src/Alert.js b/javascript/src/Alert.js index 75820de5..d86c95f3 100644 --- a/javascript/src/Alert.js +++ b/javascript/src/Alert.js @@ -111,20 +111,24 @@ var QfqNS = QfqNS || {}; this.timerId = null; this.eventEmitter = new EventEmitter(); - }; n.Alert.prototype.on = n.EventEmitter.onMixin; + n.Alert.constants = { + alertContainerId: "qfqAlertContainer", + alertContainerSelector: "#qfqAlertContainer", + jQueryAlertRemoveEventName: "qfqalert.remove:" + }; /** * * @private */ n.Alert.prototype.makeAlertContainerSingleton = function () { - var alertContainer = $("#qfqAlertContainer"); + var alertContainer = $(n.Alert.constants.alertContainerSelector); if (alertContainer.length === 0) { // No container so far, create one - alertContainer = $("
").attr("id", "qfqAlertContainer"); + alertContainer = $("
").attr("id", n.Alert.constants.alertContainerId); $("body").append(alertContainer); } @@ -137,14 +141,14 @@ var QfqNS = QfqNS || {}; * @private */ n.Alert.prototype.countAlertsInAlertContainer = function () { - return $("#qfqAlertContainer > div").length; + return $(n.Alert.constants.alertContainerSelector + " > div").length; }; /** * @private */ n.Alert.prototype.removeAlertContainer = function () { - $("#qfqAlertContainer").remove(); + $(n.Alert.constants.alertContainerSelector).remove(); }; /** @@ -195,13 +199,19 @@ var QfqNS = QfqNS || {}; return $buttons; }; + /** + * @public + */ n.Alert.prototype.show = function () { + var $alertContainer; if (this.shown) { // We only allow showing once return; } - var $alertContainer = this.makeAlertContainerSingleton(); + $(n.Alert.constants.alertContainerSelector + " > div").trigger(n.Alert.constants.jQueryAlertRemoveEventName); + + $alertContainer = this.makeAlertContainerSingleton(); if (this.modal) { this.$modalDiv = $("
"); this.$modalDiv.css('width', Math.max(document.documentElement.clientWidth, window.innerWidth || 0)); @@ -223,6 +233,9 @@ var QfqNS = QfqNS || {}; } else { // Click on the message anywhere will remove the message this.$alertDiv.click(this.removeAlert.bind(this)); + // Allows to remove all alerts that do not require user interaction programmatically. Yes, we could send + // the "click" event, but we want to communicate our intention clearly. + this.$alertDiv.on(n.Alert.constants.jQueryAlertRemoveEventName, this.removeAlert.bind(this)); } if (this.modal) { -- GitLab From 64c6af6eddb2d7bf7ceb8a79e4cb52d3ae29b4d2 Mon Sep 17 00:00:00 2001 From: Rafael Ostertag Date: Fri, 11 Aug 2017 12:01:01 +0200 Subject: [PATCH 3/3] Updated comment. --- javascript/src/Alert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/src/Alert.js b/javascript/src/Alert.js index d86c95f3..0579c790 100644 --- a/javascript/src/Alert.js +++ b/javascript/src/Alert.js @@ -233,7 +233,7 @@ var QfqNS = QfqNS || {}; } else { // Click on the message anywhere will remove the message this.$alertDiv.click(this.removeAlert.bind(this)); - // Allows to remove all alerts that do not require user interaction programmatically. Yes, we could send + // Allows to remove all alerts that do not require user interaction, programmatically. Yes, we could send // the "click" event, but we want to communicate our intention clearly. this.$alertDiv.on(n.Alert.constants.jQueryAlertRemoveEventName, this.removeAlert.bind(this)); } -- GitLab