-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.html
172 lines (150 loc) · 4.89 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!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.3.2/css/bootstrap.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.3.2/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>