173 lines
5 KiB
HTML
173 lines
5 KiB
HTML
<!doctype html>
|
|
<html lang=en>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
|
|
<title>jQuery Toaster Plugin Demo</title>
|
|
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
|
|
|
|
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
|
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
|
<!--[if lt IE 9]>
|
|
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
|
|
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
|
|
<![endif]-->
|
|
</head>
|
|
<body>
|
|
<div class="container" role="main">
|
|
<div class="jumbotron">
|
|
<h1>jQuery Toaster Demo</h1>
|
|
<p>A random toast messages will pop up every second starting when the page loads. Use the buttons below to stop and start these toast messages.</p>
|
|
<p>
|
|
<button type="button" id="btnstart" class="btn btn-primary btn-lg" role="button">Start</button>
|
|
<button type="button" id="btnstop" class="btn btn-danger btn-lg" role="button">Stop</button>
|
|
</p>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-12 col-lg-12">
|
|
<div class="panel panel-info">
|
|
<div class="panel-heading">
|
|
<h3 class="panel-title">Make Your Own Toast</h3>
|
|
</div>
|
|
<div class="panel-body">
|
|
<p>Use the fields below to generate your own toast!</p>
|
|
<form id="preptoast" role="form" class="form-inline">
|
|
<div class="form-group">
|
|
<label class="sr-only" for="toastPriority">Toast Priority</label>
|
|
<select class="form-control" id="toastPriority" placeholder="Priority">
|
|
<option><use default></option>
|
|
<option value="success">success</option>
|
|
<option value="info">info</option>
|
|
<option value="warning">warning</option>
|
|
<option value="danger">danger</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="sr-only" for="toastTitle">Toast Title</label>
|
|
<input type="text" class="form-control" id="toastTitle" placeholder="Title">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="sr-only" for="toastMessage">Toast Message</label>
|
|
<input type="text" class="form-control" id="toastMessage" placeholder="Message">
|
|
</div>
|
|
<div class="form-group">
|
|
<button type="submit" class="btn btn-primary">Make Toast</button>
|
|
</div>
|
|
</form>
|
|
<br>
|
|
<p>Code:</p>
|
|
<div id="toastCode"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--[if IE]>
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
|
|
<![endif]-->
|
|
|
|
<!--[if !IE]>-->
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
|
<!--<![endif]-->
|
|
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
|
<script src="./jquery.toaster.js"></script>
|
|
<script>
|
|
var interval;
|
|
var codetmpl = "<code>%codeobj%</code><br><code>%codestr%</code>";
|
|
|
|
$(document).ready(function ()
|
|
{
|
|
randomToast();
|
|
|
|
$('#btnstart').click(start);
|
|
$('#btnstop').click(stop);
|
|
$('#preptoast').on('submit', maketoast);
|
|
|
|
start();
|
|
});
|
|
|
|
function start ()
|
|
{
|
|
if (!interval)
|
|
{
|
|
interval = setInterval(function ()
|
|
{
|
|
randomToast();
|
|
}, 1500);
|
|
}
|
|
this.blur();
|
|
}
|
|
|
|
function stop ()
|
|
{
|
|
if (interval)
|
|
{
|
|
clearInterval(interval);
|
|
interval = false;
|
|
}
|
|
this.blur();
|
|
}
|
|
|
|
function randomToast ()
|
|
{
|
|
var priority = 'success';
|
|
var title = 'Success';
|
|
var message = 'It worked!';
|
|
|
|
$.toaster({ priority : priority, title : title, message : message });
|
|
}
|
|
|
|
function maketoast (evt)
|
|
{
|
|
evt.preventDefault();
|
|
|
|
var options =
|
|
{
|
|
priority : $('#toastPriority').val() || null,
|
|
title : $('#toastTitle').val() || null,
|
|
message : $('#toastMessage').val() || 'A message is required'
|
|
};
|
|
|
|
if (options.priority === '<use default>')
|
|
{
|
|
options.priority = null;
|
|
}
|
|
|
|
var codeobj = [];
|
|
var codestr = [];
|
|
|
|
var labels = ['message', 'title', 'priority'];
|
|
for (var i = 0, l = labels.length; i < l; i += 1)
|
|
{
|
|
if (options[labels[i]] !== null)
|
|
{
|
|
codeobj.push([labels[i], "'" + options[labels[i]] + "'"].join(' : '));
|
|
}
|
|
|
|
codestr.push((options[labels[i]] !== null) ? "'" + options[labels[i]] + "'" : 'null');
|
|
}
|
|
|
|
if (codestr[2] === 'null')
|
|
{
|
|
codestr.pop();
|
|
if (codestr[1] === 'null')
|
|
{
|
|
codestr.pop();
|
|
}
|
|
}
|
|
|
|
codeobj = "$.toaster({ " + codeobj.join(", ") + " });"
|
|
codestr = "$.toaster(" + codestr.join(", ") + ");"
|
|
|
|
$('#toastCode').html(codetmpl.replace('%codeobj%', codeobj).replace('%codestr%', codestr));
|
|
$.toaster(options);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|