-
Notifications
You must be signed in to change notification settings - Fork 46
/
js_dialogs.html
136 lines (102 loc) · 6.45 KB
/
js_dialogs.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
---
layout: admin
title: Javascript - Dialogs
section: js
module: js_dialogs
header:
icon: web_asset
title: Dialogs
description: Dialogs are content that are not originally visible on a page but show up with extra information if needed. The transitions should make the appearance of the dialog make sense and not jarring to the user.
javascripts:
- js/pages/js_dialogs.js
---
<section id="js_dialogs">
<!-- ###### -->
<!-- Toasts -->
<!-- ###### -->
<div class="row">
<div class="col s12">
<h4 class="main-text lighten-1">Toasts</h4>
<p>Materialize provides an easy way for you to send unobtrusive alerts to your users through toasts. These toasts are also placed and sized responsively, try it out by clicking the button below on different device sizes.</p>
<a class="waves-effect waves-light btn" onclick="Materialize.toast('I am a toast', 4000)">Toast!</a>
<p>To do this, call the Materialize.toast() function programatically in JavaScript.</p>
<pre>
<code class="language-javascript">
// Materialize.toast(message, displayLength, className, completeCallback);
Materialize.toast('I am a toast!', 4000) // 4000 is the duration of the toast
</code>
</pre>
<p>One way to add this into your application is to add this as an onclick event to a button</p>
<pre>
<code class="language-markup">
<a class="btn" onclick="Materialize.toast('I am a toast', 4000)">Toast!</a>
</code>
</pre>
<h5 class="margin-top-35">Custom HTML</h5>
<p>You can pass in an HTML String as the first argument as well. Take a look at the example below, where we pass in text as well as a flat button. If you call an external function instead of in-line JavaScript, you will not need to escape quotation marks. </p>
<a class="waves-effect waves-light btn" onclick="$.CustomToast().displayCustomHTMLToast()">Toast with Action</a>
<pre>
<code class="language-javascript">
var $toastContent = $('<span>I am toast content</span>');
Materialize.toast($toastContent, 5000);
</code>
</pre>
<h5 class="margin-top-35">Callback</h5>
<p>You can have the toast callback a function when it has been dismissed</p>
<a class="btn" onclick="Materialize.toast('I am a toast', 4000,'',function(){alert('Your toast was dismissed')})">Toast!</a>
<pre>
<code class="language-markup">
<a class="btn" onclick="Materialize.toast('I am a toast', 4000,'',function(){alert('Your toast was dismissed')})">Toast!</a>
</code>
</pre>
<h5 class="margin-top-35">Styling Toasts</h5>
<p>We've added the ability to customize your toasts easily. You can pass in classes as an optional parameter into the toast function. We've added a rounded class for you, but you can create your own CSS classes and apply them to toasts. Checkout out our full example below.</p>
<a class="waves-effect waves-light btn" onclick="Materialize.toast('I am a toast!', 3000, 'rounded')">Round Toast!</a>
<pre>
<code class="language-javascript">
Materialize.toast('I am a toast!', 3000, 'rounded') // 'rounded' is the class I'm applying to the toast
</code>
</pre>
</div>
</div>
<!-- ######## -->
<!-- Tooltips -->
<!-- ######## -->
<div class="row">
<div class="col s12">
<h4 class="main-text lighten-1">Tooltips</h4>
<p>Tooltips are small, interactive, textual hints for mainly graphical elements. When using icons for actions you can use a tooltip to give people clarification on its function.</p>
<div class="row">
<a class="btn tooltipped col s4 offset-s4 l2" data-position="bottom" data-delay="50" data-tooltip="I am tooltip"> Bottom</a>
<a class="btn tooltipped col s4 offset-s4 l2 offset-l1" data-position="top" data-delay="50" data-tooltip="I am tooltip"> Top</a>
<a class="btn tooltipped col s4 offset-s4 l2 offset-l1" data-position="left" data-delay="50" data-tooltip="I am tooltip"> Left</a>
<a class="btn tooltipped col s4 offset-s4 l2 offset-l1" data-position="right" data-delay="50" data-tooltip="I am tooltip"> Right</a>
</div>
<p>Add the Tooltipped class to your element and add either top, bottom, left, right on data-tooltip to control the position.</p>
<pre>
<code class="language-markup">
<!-- data-position can be : bottom, top, left, or right -->
<!-- data-delay controls delay before tooltip shows (in milliseconds)-->
<a class="btn tooltipped" data-position="bottom" data-delay="50" data-tooltip="I am tooltip">Hover me!</a>
</code>
</pre>
<h5 class="margin-top-35">Initialization</h5>
<p>Tooltips are initialized automatically, but if you have dynamically added tooltips, you will need to initialize them.</p>
<pre>
<code class="language-javascript">
$(document).ready(function(){
$('.tooltipped').tooltip({delay: 50});
});
</code>
</pre>
<h5 class="margin-top-35">Removal</h5>
<p>To remove the tooltip from the button, pass in <code class="language-javascript">'remove'</code> as the option to the tooltip function</p>
<pre>
<code class="language-javascript">
// This will remove the tooltip functionality for the buttons on this page
$('.tooltipped').tooltip('remove');
</code>
</pre>
</div>
</div>
</section>