| 9 |
lars |
1 |
var UIToastr = function () {
|
|
|
2 |
|
|
|
3 |
return {
|
|
|
4 |
//main function to initiate the module
|
|
|
5 |
init: function () {
|
|
|
6 |
|
|
|
7 |
var i = -1,
|
|
|
8 |
toastCount = 0,
|
|
|
9 |
$toastlast,
|
|
|
10 |
getMessage = function () {
|
|
|
11 |
var msgs = ['Hello, some notification sample goes here',
|
|
|
12 |
'<div><input class="form-control input-small" value="textbox"/> <a href="http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes" target="_blank">Check this out</a></div><div><button type="button" id="okBtn" class="btn blue">Close me</button><button type="button" id="surpriseBtn" class="btn default" style="margin: 0 8px 0 8px">Surprise me</button></div>',
|
|
|
13 |
'Did you like this one ? :)',
|
|
|
14 |
'Totally Awesome!!!',
|
|
|
15 |
'Yeah, this is the Metronic!',
|
|
|
16 |
'Explore the power of App. Purchase it now!'
|
|
|
17 |
];
|
|
|
18 |
i++;
|
|
|
19 |
if (i === msgs.length) {
|
|
|
20 |
i = 0;
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
return msgs[i];
|
|
|
24 |
};
|
|
|
25 |
|
|
|
26 |
$('#showtoast').click(function () {
|
|
|
27 |
var shortCutFunction = $("#toastTypeGroup input:checked").val();
|
|
|
28 |
var msg = $('#message').val();
|
|
|
29 |
var title = $('#title').val() || '';
|
|
|
30 |
var $showDuration = $('#showDuration');
|
|
|
31 |
var $hideDuration = $('#hideDuration');
|
|
|
32 |
var $timeOut = $('#timeOut');
|
|
|
33 |
var $extendedTimeOut = $('#extendedTimeOut');
|
|
|
34 |
var $showEasing = $('#showEasing');
|
|
|
35 |
var $hideEasing = $('#hideEasing');
|
|
|
36 |
var $showMethod = $('#showMethod');
|
|
|
37 |
var $hideMethod = $('#hideMethod');
|
|
|
38 |
var toastIndex = toastCount++;
|
|
|
39 |
|
|
|
40 |
toastr.options = {
|
|
|
41 |
closeButton: $('#closeButton').prop('checked'),
|
|
|
42 |
debug: $('#debugInfo').prop('checked'),
|
|
|
43 |
positionClass: $('#positionGroup input:checked').val() || 'toast-top-right',
|
|
|
44 |
onclick: null
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
if ($('#addBehaviorOnToastClick').prop('checked')) {
|
|
|
48 |
toastr.options.onclick = function () {
|
|
|
49 |
alert('You can perform some custom action after a toast goes away');
|
|
|
50 |
};
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if ($showDuration.val().length) {
|
|
|
54 |
toastr.options.showDuration = $showDuration.val();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if ($hideDuration.val().length) {
|
|
|
58 |
toastr.options.hideDuration = $hideDuration.val();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
if ($timeOut.val().length) {
|
|
|
62 |
toastr.options.timeOut = $timeOut.val();
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
if ($extendedTimeOut.val().length) {
|
|
|
66 |
toastr.options.extendedTimeOut = $extendedTimeOut.val();
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
if ($showEasing.val().length) {
|
|
|
70 |
toastr.options.showEasing = $showEasing.val();
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
if ($hideEasing.val().length) {
|
|
|
74 |
toastr.options.hideEasing = $hideEasing.val();
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
if ($showMethod.val().length) {
|
|
|
78 |
toastr.options.showMethod = $showMethod.val();
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
if ($hideMethod.val().length) {
|
|
|
82 |
toastr.options.hideMethod = $hideMethod.val();
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
if (!msg) {
|
|
|
86 |
msg = getMessage();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
$("#toastrOptions").text("Command: toastr[" + shortCutFunction + "](\"" + msg + (title ? "\", \"" + title : '') + "\")\n\ntoastr.options = " + JSON.stringify(toastr.options, null, 2));
|
|
|
90 |
|
|
|
91 |
var $toast = toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists
|
|
|
92 |
$toastlast = $toast;
|
|
|
93 |
if ($toast.find('#okBtn').length) {
|
|
|
94 |
$toast.delegate('#okBtn', 'click', function () {
|
|
|
95 |
alert('you clicked me. i was toast #' + toastIndex + '. goodbye!');
|
|
|
96 |
$toast.remove();
|
|
|
97 |
});
|
|
|
98 |
}
|
|
|
99 |
if ($toast.find('#surpriseBtn').length) {
|
|
|
100 |
$toast.delegate('#surpriseBtn', 'click', function () {
|
|
|
101 |
alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.');
|
|
|
102 |
});
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
$('#clearlasttoast').click(function () {
|
|
|
106 |
toastr.clear($toastlast);
|
|
|
107 |
});
|
|
|
108 |
});
|
|
|
109 |
$('#cleartoasts').click(function () {
|
|
|
110 |
toastr.clear();
|
|
|
111 |
});
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
};
|
|
|
116 |
|
|
|
117 |
}();
|
|
|
118 |
|
|
|
119 |
jQuery(document).ready(function() {
|
|
|
120 |
UIToastr.init();
|
|
|
121 |
});
|