Last active
August 29, 2015 14:15
-
-
Save robertd/b00979aef4454217737d to your computer and use it in GitHub Desktop.
Notifier powered by ToastrJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(5000); | |
}, function (err) { | |
toast.setType("error") | |
.setMessage("Something went wrong") | |
.setNewTimeout(5000); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment