Skip to content

Instantly share code, notes, and snippets.

@robertd
Last active August 29, 2015 14:15

Revisions

  1. robertd revised this gist Feb 20, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion example.js
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,6 @@ define([
    }, function (err) {
    toast.setType("error")
    .setMessage("Something went wrong")
    .setNewTimeout(5000);;
    .setNewTimeout(5000);
    });
    });
  2. robertd revised this gist Feb 20, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions example.js
    Original file line number Diff line number Diff line change
    @@ -10,9 +10,10 @@ define([
    }).then(function (data) {
    toast.setType("success")
    .setMessage("Successfully fetched " + response.length + " repositories.")
    .setNewTimeout();
    .setNewTimeout(5000);
    }, function (err) {
    toast.setType("error")
    .setMessage("Something went wrong");
    .setMessage("Something went wrong")
    .setNewTimeout(5000);;
    });
    });
  3. robertd revised this gist Feb 20, 2015. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    define([
    "notifier"
    "jquery"
    ], function (notifier, $) {
    /* ACME Demo */
    var toast = notifier.instance("info", "Fetching..."); // toastr insance that can be manipulated later

    $.ajax("/api/acme/repositories", {
    dataType: "json"
    }).then(function (data) {
    toast.setType("success")
    .setMessage("Successfully fetched " + response.length + " repositories.")
    .setNewTimeout();
    }, function (err) {
    toast.setType("error")
    .setMessage("Something went wrong");
    });
    });
  4. robertd renamed this gist Feb 20, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. robertd created this gist Feb 20, 2015.
    91 changes: 91 additions & 0 deletions Notifier
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    define([
    "jquery",
    "toastr"
    ], function ($, toastr) {

    toastr.options = {
    "closeButton": false,
    "debug": false,
    "progressBar": false,
    "positionClass": "toast-bottom-right",
    "preventDuplicates": false,
    "onclick": null,
    "showDuration": "300",
    "hideDuration": "1000",
    "timeOut": "3000",
    "extendedTimeOut": "1000",
    "showEasing": "swing",
    "hideEasing": "linear",
    "showMethod": "fadeIn",
    "hideMethod": "fadeOut"
    };

    var success = function (msg, options, title) {
    options = options || {};
    title = title || "";
    toastr.success(msg, title, options);
    };

    var info = function (msg, options, title) {
    options = options || {};
    title = title || "";
    toastr.info(msg, title, options);
    };

    var error = function (msg, options, title) {
    options = options || {};
    title = title || "";
    toastr.error(msg, title, options);
    };

    var warning = function (msg, options, title) {
    options = options || {};
    title = title || "";
    toastr.warning(msg, title, options);
    };

    var clear = function () {
    toastr.clear();
    };

    var instance = function (type, msg) {
    var _instance = toastr[type](msg, null, {
    timeOut: 0
    });

    var setMessage = function (msg) {
    _instance.text(msg);
    return this;
    };

    var setType = function (type) {
    $(_instance).removeClass(function (index, css) {
    return (css.match(/(^|\s)toast-\S+/g) || []).join(' ');
    }).addClass("toast-" + type);
    return this;
    };

    var setNewTimeout = function (timeout) {
    timeout = timeout || 3000;
    setTimeout(function(){
    _instance.remove();
    }, timeout);
    return this;
    };

    return {
    setMessage: setMessage,
    setType: setType,
    setNewTimeout: setNewTimeout
    };
    };

    return {
    success: success,
    info: info,
    error: error,
    warning: warning,
    clear: clear,
    instance: instance
    };
    });