-
Notifications
You must be signed in to change notification settings - Fork 15
/
alerts.html
91 lines (83 loc) · 3.53 KB
/
alerts.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
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../../css/bootstrap.css" />
<link rel="stylesheet" href="../../css/admin.css" />
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function alertType() {
return $('#alert-type-input').val();
}
function isDismissable() {
return $('#is-dismissable-input').is(':checked');
}
function alertShortcode() {
return '[bs_notification type="' + alertType() + '" dismissible="' + isDismissable() + '"]Your content here.[/bs_notification]';
}
function renderAlertPreview() {
var closebutton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>';
var template = '<div class="alert alert-' + alertType() + '" role="alert">Your content here.' + (isDismissable()? closebutton: '') + '</div>'
$('#alert-demo').html(template);
}
function insertShortcode(event) {
top.tinymce.activeEditor.insertContent(alertShortcode());
top.tinymce.activeEditor.windowManager.close();
event.preventDefault();
}
function showResetButton() {
$('#reset-button').show();
}
function resetPreview() {
$('#reset-button').hide();
renderAlertPreview();
}
$('#alert-type-input').on('change', renderAlertPreview);
$('#is-dismissable-input').on('change', renderAlertPreview);
$('#alert-form').on('submit', insertShortcode);
// I think Boostrap's custom event "closed.bs.alert" fails to bubble up
// so we'll just listen for the actual click on the close button
$('#alert-demo').on('click', '.close', showResetButton);
$('#reset-button').on('click', resetPreview);
resetPreview();
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-6">
<h4>Options</h4>
<form id="alert-form">
<div class="form-group">
<select id="alert-type-input" class="form-control">
<option value="success">Success</option>
<option value="warning">Warning</option>
<option value="info">Info</option>
<option value="danger">Danger</option>
</select>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input id="is-dismissable-input" type="checkbox" checked> Dismissable?
</label>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">Insert Alert Shortcode</button>
</div>
</form>
</div>
<div class="col-xs-6">
<h4>Preview</h4>
<div id="alert-demo"></div>
<button id="reset-button" class="btn btn-warning">Oops, I guess I needed that</button>
</div>
</div>
</div>
</div>
</body>
</html>