From 21170a2aa8e09d4ceef9d64950df857e62cfb8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Thu, 30 Mar 2017 18:58:56 +0200 Subject: [PATCH] Renamed few paramateters (Now they are named positively). Documentation! --- static/alert.js | 39 +++++++++++++++++++++------------------ static/compiler.js | 2 -- static/editor.js | 2 -- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/static/alert.js b/static/alert.js index e8bab8644..5f60464f6 100644 --- a/static/alert.js +++ b/static/alert.js @@ -59,35 +59,38 @@ define(function (require) { /* Options parameter: * group: What group this notification is from. Sets data-group's value. Default: none - * noCollapse: If set to true, other notifications with the same group will not be removed before sending this. (Note that this only has any effect if group is set). Default: false + * collapseSimilar: If set to true, other notifications with the same group will be removed before sending this. (Note that this only has any effect if group is set). Default: true * alertClass: Space separated classes to give to the notification div element. Default: none - * noAutoDismiss: If set to true, the notification will not fade out nor be removed automatically. Default: false (This element will be dissmised) - * dismissTime: If allowed by noAutoDismiss, controls how long the notification will be visible before being automatically removed. Default: 5000ms + * autoDismiss: If set to true, the notification will fade out and be removed automatically. Default: true + * dismissTime: If allowed by autoDismiss, controls how long the notification will be visible before being automatically removed. Default: 5000ms. Min: 1000ms */ Alert.prototype.notify = function (body, options) { - var modal = $('#notifications'); - if (!modal) return; + var container = $('#notifications'); + if (!container) return; var newElement = $(''); - if (options) { - if (options.group) { - if (!options.noCollapse) { - modal.find('[data-group="' + options.group + '"]').remove(); - } - newElement.attr('data-group', options.group); - } - if (options.alertClass) { - newElement.addClass(options.alertClass); + if (!options) options = {}; + // Set defaults + options.collapseSimilar = ("collapseSimilar" in options) ? options.collapseSimilar : true; // Collapse similars by default + options.autoDismiss = ("autoDismiss" in options) ? options.autoDismiss : true; // autoDismiss by default + options.dismissTime = options.dismissTime ? max(1000, options.dismissTime) : 5000; // Dismiss this after 5000ms by default + if (options.group) { + if (options.collapseSimilar) { + // Only collapsing if a group has been specified + container.find('[data-group="' + options.group + '"]').remove(); } + newElement.attr('data-group', options.group); // Add the group to the data-group } - modal.append(newElement); - if (!options || !options.noAutoDismiss) { - // Dismiss this after dismissTime + if (options.alertClass) { // If we want a custom class, apply it + newElement.addClass(options.alertClass); + } + if (options.autoDismiss) { // Dismiss this after dismissTime setTimeout(function () { newElement.fadeOut('slow', function() { newElement.remove(); }); - }, options && options.dismissTime ? options.dismissTime : 5000); + }, options.dismissTime); } + container.append(newElement); // Add the new notification to the container }; Alert.prototype.onYesNoHide = function (evt) { diff --git a/static/compiler.js b/static/compiler.js index 4e1e474ac..623bc2b28 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -608,9 +608,7 @@ define(function (require) { } else { new Alert().notify('This token was not found in the documentation.
Only Intel x86 opcodes supported for now.',{ group: "notokenindocs", - noCollapse: false, alertClass: "notification-error", - noAutoDismiss: false, dismissTime: 3000 }); } diff --git a/static/editor.js b/static/editor.js index c4fc1a6a6..37c65042d 100644 --- a/static/editor.js +++ b/static/editor.js @@ -110,9 +110,7 @@ define(function (require) { }); new Alert().notify('Compile on code change has been toggled ' + (this.settings.compileOnChange ? 'ON' : 'OFF'), { group: "togglecompile", - noCollapse: false, alertClass: this.settings.compileOnChange ? "notification-on" : "notification-off", - noAutoDismiss: false, dismissTime: 3000 }); }, this)