| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8" /> |
| 5 |
<title>toastr examples</title> |
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> |
| 7 |
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"> |
| 8 |
<link href="build/toastr.css" rel="stylesheet" type="text/css" /> |
| 9 |
<style> |
| 10 |
.row { |
| 11 |
margin-left: 0; |
| 12 |
} |
| 13 |
</style> |
| 14 |
</head> |
| 15 |
|
| 16 |
<body class="container"> |
| 17 |
<section class="row"> |
| 18 |
<h1>toastr</h1> |
| 19 |
|
| 20 |
<div class="well row"> |
| 21 |
<div class="row"> |
| 22 |
<div class="span4"> |
| 23 |
<div class="control-group"> |
| 24 |
<div class="controls"> |
| 25 |
<label class="control-label" for="title">Title</label> |
| 26 |
<input id="title" type="text" class="input-large" placeholder="Enter a title ..." /> |
| 27 |
<label class="control-label" for="message">Message</label> |
| 28 |
<textarea class="input-large" id="message" rows="3" placeholder="Enter a message ..."></textarea> |
| 29 |
</div> |
| 30 |
</div> |
| 31 |
<div class="control-group"> |
| 32 |
<div class="controls"> |
| 33 |
<label class="checkbox" for="closeButton"> |
| 34 |
<input id="closeButton" type="checkbox" value="checked" class="input-mini" />Close Button |
| 35 |
</label> |
| 36 |
</div> |
| 37 |
<div class="controls"> |
| 38 |
<label class="checkbox" for="addBehaviorOnToastClick"> |
| 39 |
<input id="addBehaviorOnToastClick" type="checkbox" value="checked" class="input-mini" />Add behavior on toast click |
| 40 |
</label> |
| 41 |
</div> |
| 42 |
<div class="controls"> |
| 43 |
<label class="checkbox" for="addBehaviorOnToastCloseClick"> |
| 44 |
<input disabled id="addBehaviorOnToastCloseClick" type="checkbox" value="checked" class="input-mini" />Add behavior on toast close button click |
| 45 |
</label> |
| 46 |
</div> |
| 47 |
<div class="controls"> |
| 48 |
<label class="checkbox" for="debugInfo"> |
| 49 |
<input id="debugInfo" type="checkbox" value="checked" class="input-mini" />Debug |
| 50 |
</label> |
| 51 |
</div> |
| 52 |
<div class="controls"> |
| 53 |
<label class="checkbox" for="progressBar"> |
| 54 |
<input id="progressBar" type="checkbox" value="checked" class="input-mini" />Progress Bar |
| 55 |
</label> |
| 56 |
</div> |
| 57 |
<div class="controls"> |
| 58 |
<label class="checkbox" for="rtl"> |
| 59 |
<input id="rtl" type="checkbox" value="checked" class="input-mini" />Right-To-Left |
| 60 |
</label> |
| 61 |
</div> |
| 62 |
<div class="controls"> |
| 63 |
<label class="checkbox" for="preventDuplicates"> |
| 64 |
<input id="preventDuplicates" type="checkbox" value="checked" class="input-mini" />Prevent Duplicates |
| 65 |
</label> |
| 66 |
</div> |
| 67 |
<div class="controls"> |
| 68 |
<label class="checkbox" for="addClear"> |
| 69 |
<input id="addClear" type="checkbox" value="checked" class="input-mini" />Add button to force clearing a toast, ignoring focus |
| 70 |
</label> |
| 71 |
</div> |
| 72 |
<div class="controls"> |
| 73 |
<label class="checkbox" for="newestOnTop"> |
| 74 |
<input id="newestOnTop" type="checkbox" value="checked" class="input-mini" />Newest on top |
| 75 |
</label> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
</div> |
| 79 |
|
| 80 |
<div class="span2"> |
| 81 |
<div class="control-group" id="toastTypeGroup"> |
| 82 |
<div class="controls"> |
| 83 |
<label>Toast Type</label> |
| 84 |
<label class="radio"> |
| 85 |
<input type="radio" name="toasts" value="success" checked />Success |
| 86 |
</label> |
| 87 |
<label class="radio"> |
| 88 |
<input type="radio" name="toasts" value="info" />Info |
| 89 |
</label> |
| 90 |
<label class="radio"> |
| 91 |
<input type="radio" name="toasts" value="warning" />Warning |
| 92 |
</label> |
| 93 |
<label class="radio"> |
| 94 |
<input type="radio" name="toasts" value="error" />Error |
| 95 |
</label> |
| 96 |
</div> |
| 97 |
</div> |
| 98 |
<div class="control-group" id="positionGroup"> |
| 99 |
<div class="controls"> |
| 100 |
<label>Position</label> |
| 101 |
<label class="radio"> |
| 102 |
<input type="radio" name="positions" value="toast-top-right" checked />Top Right |
| 103 |
</label> |
| 104 |
<label class="radio"> |
| 105 |
<input type="radio" name="positions" value="toast-bottom-right" />Bottom Right |
| 106 |
</label> |
| 107 |
<label class="radio"> |
| 108 |
<input type="radio" name="positions" value="toast-bottom-left" />Bottom Left |
| 109 |
</label> |
| 110 |
<label class="radio"> |
| 111 |
<input type="radio" name="positions" value="toast-top-left" />Top Left |
| 112 |
</label> |
| 113 |
<label class="radio"> |
| 114 |
<input type="radio" name="positions" value="toast-top-full-width" />Top Full Width |
| 115 |
</label> |
| 116 |
<label class="radio"> |
| 117 |
<input type="radio" name="positions" value="toast-bottom-full-width" />Bottom Full Width |
| 118 |
</label> |
| 119 |
<label class="radio"> |
| 120 |
<input type="radio" name="positions" value="toast-top-center" />Top Center |
| 121 |
</label> |
| 122 |
<label class="radio"> |
| 123 |
<input type="radio" name="positions" value="toast-bottom-center" />Bottom Center |
| 124 |
</label> |
| 125 |
</div> |
| 126 |
</div> |
| 127 |
</div> |
| 128 |
|
| 129 |
<div class="span2"> |
| 130 |
<div class="control-group"> |
| 131 |
<div class="controls"> |
| 132 |
<label class="control-label" for="showEasing">Show Easing</label> |
| 133 |
<input id="showEasing" type="text" placeholder="swing, linear" class="input-mini" value="swing" /> |
| 134 |
|
| 135 |
<label class="control-label" for="hideEasing">Hide Easing</label> |
| 136 |
<input id="hideEasing" type="text" placeholder="swing, linear" class="input-mini" value="linear" /> |
| 137 |
|
| 138 |
<label class="control-label" for="showMethod">Show Method</label> |
| 139 |
<input id="showMethod" type="text" placeholder="show, fadeIn, slideDown" class="input-mini" value="fadeIn" /> |
| 140 |
|
| 141 |
<label class="control-label" for="hideMethod">Hide Method</label> |
| 142 |
<input id="hideMethod" type="text" placeholder="hide, fadeOut, slideUp" class="input-mini" value="fadeOut" /> |
| 143 |
</div> |
| 144 |
</div> |
| 145 |
</div> |
| 146 |
|
| 147 |
<div class="span3"> |
| 148 |
<div class="control-group"> |
| 149 |
<div class="controls"> |
| 150 |
<label class="control-label" for="showDuration">Show Duration</label> |
| 151 |
<input id="showDuration" type="number" placeholder="ms" class="input-mini" value="300" /> |
| 152 |
|
| 153 |
<label class="control-label" for="hideDuration">Hide Duration</label> |
| 154 |
<input id="hideDuration" type="number" placeholder="ms" class="input-mini" value="1000" /> |
| 155 |
|
| 156 |
<label class="control-label" for="timeOut">Time out</label> |
| 157 |
<input id="timeOut" type="number" placeholder="ms" class="input-mini" value="5000" /> |
| 158 |
|
| 159 |
<label class="control-label" for="extendedTimeOut">Extended time out</label> |
| 160 |
<input id="extendedTimeOut" type="number" placeholder="ms" class="input-mini" value="1000" /> |
| 161 |
</div> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
</div> |
| 165 |
|
| 166 |
<div class="row"> |
| 167 |
<button type="button" class="btn btn-primary" id="showtoast">Show Toast</button> |
| 168 |
<button type="button" class="btn btn-danger" id="cleartoasts">Clear Toasts</button> |
| 169 |
<button type="button" class="btn btn-danger" id="clearlasttoast">Clear Last Toast</button> |
| 170 |
</div> |
| 171 |
|
| 172 |
<div class="row" style='margin-top: 25px;'> |
| 173 |
<pre id='toastrOptions'></pre> |
| 174 |
</div> |
| 175 |
</div> |
| 176 |
</section> |
| 177 |
|
| 178 |
<footer class="row"> |
| 179 |
<h2>Links</h2> |
| 180 |
|
| 181 |
<ul> |
| 182 |
<li><a href="http://nuget.org/packages/toastr">NuGet</a></li> |
| 183 |
<li><a href="https://github.com/CodeSeven/toastr">GitHub</a></li> |
| 184 |
</ul> |
| 185 |
</footer> |
| 186 |
|
| 187 |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
| 188 |
<script src="toastr.js"></script> |
| 189 |
|
| 190 |
<script type="text/javascript"> |
| 191 |
$(function () { |
| 192 |
var i = -1; |
| 193 |
var toastCount = 0; |
| 194 |
var $toastlast; |
| 195 |
|
| 196 |
var getMessage = function () { |
| 197 |
var msgs = ['My name is Inigo Montoya. You killed my father. Prepare to die!', |
| 198 |
'<div><input class="input-small" value="textbox"/> <a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="surpriseBtn" class="btn" style="margin: 0 8px 0 8px">Surprise me</button></div>', |
| 199 |
'Are you the six fingered man?', |
| 200 |
'Inconceivable!', |
| 201 |
'I do not think that means what you think it means.', |
| 202 |
'Have fun storming the castle!' |
| 203 |
]; |
| 204 |
i++; |
| 205 |
if (i === msgs.length) { |
| 206 |
i = 0; |
| 207 |
} |
| 208 |
|
| 209 |
return msgs[i]; |
| 210 |
}; |
| 211 |
|
| 212 |
var getMessageWithClearButton = function (msg) { |
| 213 |
msg = msg ? msg : 'Clear itself?'; |
| 214 |
msg += '<br /><br /><button type="button" class="btn clear">Yes</button>'; |
| 215 |
return msg; |
| 216 |
}; |
| 217 |
|
| 218 |
$('#closeButton').click(function() { |
| 219 |
if($(this).is(':checked')) { |
| 220 |
$('#addBehaviorOnToastCloseClick').prop('disabled', false); |
| 221 |
} else { |
| 222 |
$('#addBehaviorOnToastCloseClick').prop('disabled', true); |
| 223 |
$('#addBehaviorOnToastCloseClick').prop('checked', false); |
| 224 |
} |
| 225 |
}); |
| 226 |
|
| 227 |
$('#showtoast').click(function () { |
| 228 |
var shortCutFunction = $("#toastTypeGroup input:radio:checked").val(); |
| 229 |
var msg = $('#message').val(); |
| 230 |
var title = $('#title').val() || ''; |
| 231 |
var $showDuration = $('#showDuration'); |
| 232 |
var $hideDuration = $('#hideDuration'); |
| 233 |
var $timeOut = $('#timeOut'); |
| 234 |
var $extendedTimeOut = $('#extendedTimeOut'); |
| 235 |
var $showEasing = $('#showEasing'); |
| 236 |
var $hideEasing = $('#hideEasing'); |
| 237 |
var $showMethod = $('#showMethod'); |
| 238 |
var $hideMethod = $('#hideMethod'); |
| 239 |
var toastIndex = toastCount++; |
| 240 |
var addClear = $('#addClear').prop('checked'); |
| 241 |
|
| 242 |
toastr.options = { |
| 243 |
closeButton: $('#closeButton').prop('checked'), |
| 244 |
debug: $('#debugInfo').prop('checked'), |
| 245 |
newestOnTop: $('#newestOnTop').prop('checked'), |
| 246 |
progressBar: $('#progressBar').prop('checked'), |
| 247 |
rtl: $('#rtl').prop('checked'), |
| 248 |
positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right', |
| 249 |
preventDuplicates: $('#preventDuplicates').prop('checked'), |
| 250 |
onclick: null |
| 251 |
}; |
| 252 |
|
| 253 |
if ($('#addBehaviorOnToastClick').prop('checked')) { |
| 254 |
toastr.options.onclick = function () { |
| 255 |
alert('You can perform some custom action after a toast goes away'); |
| 256 |
}; |
| 257 |
} |
| 258 |
|
| 259 |
if ($('#addBehaviorOnToastCloseClick').prop('checked')) { |
| 260 |
toastr.options.onCloseClick = function () { |
| 261 |
alert('You can perform some custom action when the close button is clicked'); |
| 262 |
}; |
| 263 |
} |
| 264 |
|
| 265 |
if ($showDuration.val().length) { |
| 266 |
toastr.options.showDuration = parseInt($showDuration.val()); |
| 267 |
} |
| 268 |
|
| 269 |
if ($hideDuration.val().length) { |
| 270 |
toastr.options.hideDuration = parseInt($hideDuration.val()); |
| 271 |
} |
| 272 |
|
| 273 |
if ($timeOut.val().length) { |
| 274 |
toastr.options.timeOut = addClear ? 0 : parseInt($timeOut.val()); |
| 275 |
} |
| 276 |
|
| 277 |
if ($extendedTimeOut.val().length) { |
| 278 |
toastr.options.extendedTimeOut = addClear ? 0 : parseInt($extendedTimeOut.val()); |
| 279 |
} |
| 280 |
|
| 281 |
if ($showEasing.val().length) { |
| 282 |
toastr.options.showEasing = $showEasing.val(); |
| 283 |
} |
| 284 |
|
| 285 |
if ($hideEasing.val().length) { |
| 286 |
toastr.options.hideEasing = $hideEasing.val(); |
| 287 |
} |
| 288 |
|
| 289 |
if ($showMethod.val().length) { |
| 290 |
toastr.options.showMethod = $showMethod.val(); |
| 291 |
} |
| 292 |
|
| 293 |
if ($hideMethod.val().length) { |
| 294 |
toastr.options.hideMethod = $hideMethod.val(); |
| 295 |
} |
| 296 |
|
| 297 |
if (addClear) { |
| 298 |
msg = getMessageWithClearButton(msg); |
| 299 |
toastr.options.tapToDismiss = false; |
| 300 |
} |
| 301 |
if (!msg) { |
| 302 |
msg = getMessage(); |
| 303 |
} |
| 304 |
|
| 305 |
$('#toastrOptions').text('Command: toastr["' |
| 306 |
+ shortCutFunction |
| 307 |
+ '"]("' |
| 308 |
+ msg |
| 309 |
+ (title ? '", "' + title : '') |
| 310 |
+ '")\n\ntoastr.options = ' |
| 311 |
+ JSON.stringify(toastr.options, null, 2) |
| 312 |
); |
| 313 |
|
| 314 |
var $toast = toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists |
| 315 |
$toastlast = $toast; |
| 316 |
|
| 317 |
if(typeof $toast === 'undefined'){ |
| 318 |
return; |
| 319 |
} |
| 320 |
|
| 321 |
if ($toast.find('#okBtn').length) { |
| 322 |
$toast.delegate('#okBtn', 'click', function () { |
| 323 |
alert('you clicked me. i was toast #' + toastIndex + '. goodbye!'); |
| 324 |
$toast.remove(); |
| 325 |
}); |
| 326 |
} |
| 327 |
if ($toast.find('#surpriseBtn').length) { |
| 328 |
$toast.delegate('#surpriseBtn', 'click', function () { |
| 329 |
alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.'); |
| 330 |
}); |
| 331 |
} |
| 332 |
if ($toast.find('.clear').length) { |
| 333 |
$toast.delegate('.clear', 'click', function () { |
| 334 |
toastr.clear($toast, { force: true }); |
| 335 |
}); |
| 336 |
} |
| 337 |
}); |
| 338 |
|
| 339 |
function getLastToast(){ |
| 340 |
return $toastlast; |
| 341 |
} |
| 342 |
$('#clearlasttoast').click(function () { |
| 343 |
toastr.clear(getLastToast()); |
| 344 |
}); |
| 345 |
$('#cleartoasts').click(function () { |
| 346 |
toastr.clear(); |
| 347 |
}); |
| 348 |
}) |
| 349 |
</script> |
| 350 |
</body> |
| 351 |
</html> |