-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
430 lines (358 loc) · 16.1 KB
/
demo.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<title>x-swal</title>
<script src="../platform/platform.js"></script>
<link rel="import" href="x-swal.html">
<link rel="stylesheet" href="../sweetalert/example/example.css">
<style>
table th{
width: 90px;
}
.obj{
color: #1BA7EE;
}
</style>
</head>
<body unresolved>
<h1>x-swal</h1>
<h2>A beautiful replacement for Javascript's "Alert"</h2>
<!-- What does it do? -->
<h3>So... What does it do?</h3>
<p>Here’s a comparison of a standard error message. The first one uses the built-in <strong>alert</strong>-function, while the second is using <strong>x-swal</strong>.</p>
<div class="showcase normal">
<h4>Normal alert</h4>
<button>Show error message</button>
<h5>Code:</h5>
<pre><span class="func">alert</span>(<span class="str">"Oops... Something went wrong!"</span>);
</pre>
<div class="vs-icon"></div>
</div>
<div class="showcase sweet">
<h4>Sweet Alert Polymer</h4>
<button>Show error message</button>
<x-swal id="one" type="error" auto>
<title>Oops...</title>
<text>Something went wrong!</text>
</x-swal>
<h5>Code:</h5>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"error"</span>>
<<span class="tag">title</span>>Oops...</<span class="tag">title</span>>
<<span class="tag">text</span>>Something went wrong!</<span class="tag">text</span>>
</<span class="tag">x-swal</span>>
</pre>
</div>
<p>Pretty cool huh? SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. It's even highly customizeable, as you can see below!</p>
<!-- Examples -->
<h3>More examples</h3>
<p class="center">In these examples, we're using the shorthand function <strong>swal</strong> to call x-swal.</p>
<ul class="examples">
<li class="message">
<div class="ui">
<p>A basic message</p>
<button>Try me!</button>
</div>
<pre>
<<span class="tag">x-swal</span>>
<<span class="tag">title</span>>Here's a message!</<span class="tag">title</span>>
</<span class="tag">x-swal</span>>
</pre>
<x-swal id="2" type="error">
<title>Here's a message!</title>
</x-swal>
</li>
<li class="title-text">
<div class="ui">
<p>A title with a text under</p>
<button>Try me!</button>
</div>
<pre>
<<span class="tag">x-swal</span>>
<<span class="tag">title</span>>Here's a message!</<span class="tag">title</span>>
<<span class="tag">text</span>>It's pretty, isn't it?</<span class="tag">text</span>>
</<span class="tag">x-swal</span>>
</pre>
<x-swal id="3">
<title>Here's a message!</title>
<text>It's pretty, isn't it?</text>
</x-swal>
</li>
<li class="success">
<div class="ui">
<p>A success message!</p>
<button>Try me!</button>
</div>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"success"</span>>
<<span class="tag">title</span>>Something went wrong!</<span class="tag">title</span>>
<<span class="tag">text</span>>Oops...</<span class="tag">text</span>>
</<span class="tag">x-swal</span>>
</pre>
<x-swal id="4" type="success">
<title>Something went wrong!</title>
<text>Oops...</text>
</x-swal>
</li>
<li class="warning confirm">
<div class="ui">
<p>A warning message, with a function attached to the "Confirm"-button...</p>
<button>Try me!</button>
<x-swal id="5" type="warning" showCancelButton="false" closeOnConfirm="true" >
<title>Are you sure?</title>
<text>Your will not be able to recover this imaginary file!</text>
<confirm color="#DD6B55">Yes, delete it!</confirm>
</x-swal>
</div>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"warning"</span> <span class="attr">showCancelButton</span>=<span class="str">"true"</span> <span class="attr">closeOnConfirm</span>=<span class="str">"false"</span>>
<<span class="tag">title</span>>Are you sure?</<span class="tag">title</span>>
<<span class="tag">text</span>>Your will not be able to recover this imaginary file!</<span class="tag">text</span>>
<<span class="tag">confirm</span> <span class="attr">color</span>=<span class="str">"#DD6B55"</span>>Yes, delete it!
</<span class="tag">confirm</span>>
</<span class="tag">x-swal</span>>
</pre>
</li>
<li class="warning cancel">
<div class="ui">
<p>... and by passing a parameter, you can execute something else for "Cancel".</p>
<button>Try me!</button>
<x-swal id="6" type="warning" showCancelButton="true" closeOnConfirm="false" closeOnCancel="false" >
<title>Are you sure?</title>
<text>Your will not be able to recover this imaginary file!</text>
<confirm color="#DD6B55">Yes, delete it!</confirm>
<cancel>No, cancel plx!</cancel>
</x-swal>
</div>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"warning"</span> <span class="attr">showCancelButton</span>=<span class="str">"true"</span> <span class="attr">closeOnConfirm</span>=<span class="str">"false"</span> <span class="attr">closeOnCancel</span>=<span class="str">"false"</span>>
<<span class="tag">title</span>>Are you sure?</<span class="tag">title</span>>
<<span class="tag">text</span>>Your will not be able to recover this imaginary file!</<span class="tag">text</span>>
<<span class="tag">confirm</span> <span class="attr">color</span>=<span class="str">"#DD6B55"</span>>
Yes, delete it!
</<span class="tag">confirm</span>>
<<span class="tag">cancel</span>>No, cancel plx!</<span class="tag">cancel</span>>
</<span class="tag">x-swal</span>>
<<span class="tag">script</span>>
<span class="func">var</span> <span class="var">alert</span> = <span class="obj">document</span>.querySelector(<span class="str">'x-swal'</span>);
alert.addEventListener(<span class="str">'confirmation'</span>, <span class="func">function</span> (isConfirm) {
<span class="tag">if</span>(isConfirm){
alert.title = <span class="str">"Deleted!"</span>;
alert.text = <span class="str">"Your imaginary file has been deleted."</span>;
alert.type = <span class="str">"success"</span>;
}<span class="tag">else</span>{
alert.title = <span class="str">"Cancelled!"</span>;
alert.text = <span class="str">"Your imaginary file is safe :)"</span>;
alert.type = <span class="str">"error"</span>;
}
alert.active();
});
</<span class="tag">script</span>>
</pre>
</li>
<li class="custom-icon">
<div class="ui">
<p>A message with a custom icon</p>
<button>Try me!</button>
<x-swal id="7" type="success" >
<title>Something went wrong!</title>
<text>Oops...</text>
<img src="../sweetalert/example/images/thumbs-up.jpg">
</x-swal>
</div>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"success"</span>>
<<span class="tag">title</span>>Something went wrong!</<span class="tag">title</span>>
<<span class="tag">text</span>>Oops...</<span class="tag">text</span>>
<<span class="tag">img</span> <span class="attr">src</span>=<span class="str">"images/thumbs-up.jpg"</span>/>
</<span class="tag">x-swal</span>>
</pre>
</li>
</ul>
<!-- Download & Install -->
<h3 id="download-section">Download & install</h3>
<div class="center-container">
<p class="center"><b>Method 1:</b> Install through bower:</p>
<pre class="center">$ bower install x-swall</pre>
</div>
<p class="center"><b>Method 2:</b> Download the x-swal<strong>CSS</strong> and <strong>JavaScript</strong> files.</p>
<a class="button" href="https://github.com/ruben96/x-swal/archive/master.zip" download>Download files</a>
<ol>
<li>
<p>Initialize the plugin by referencing the necessary files:</p>
<pre>
<!-- Optional polyfill-->
<<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"../platform/platform.js"</span> />
<!--Element-->
<<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"import"</span> <span class="tag">href</span>=<span class="str">"../x-swal/x-swal.html"</span>></pre>
</li>
<li>
<p>Call the x-swal after the page has loaded</p>
<pre>
<<span class="tag">x-swal</span> <span class="attr">type</span>=<span class="str">"error"</span>>
<<span class="tag">title</span>>Error!</<span class="tag">title</span>>
<<span class="tag">text</span>>Here's my error message!</<span class="tag">text</span>>
<<span class="tag">confirm</span>>
Yes, delete it!
</<span class="tag">confirm</span>>
</<span class="tag">x-swal</span>>
</pre>
</li>
</ol>
<!-- Configuration -->
<h3>Configuration</h3>
<p class="center">Here are the content that you can use if you pass an element into x-swall element:</p>
<table>
<tr class="titles">
<th>
<div class="border-left"></div>
Element
</th>
<th>Default value</th>
<th>
<div class="border-right"></div>
Description
</th>
</tr>
<tr>
<td><b>title</b></td>
<td><i>null (required)</i></td>
<td>The title of the modal. It can either be added to the object under the key "title" or passed as the first parameter of the function.</td>
</tr>
<tr>
<td><b>text</b></td>
<td><i>null</i></td>
<td>A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function.</td>
</tr>
<tr>
<td><b>confirm</b></td>
<td><i>"OK"</i></td>
<td>Use this to change the text on the "Confirm"-button. If showCancelButton is set as true, the confirm button will automatically show "Confirm" instead of "OK".</td>
</tr>
<tr>
<td><b>cancel</b></td>
<td><i>"Cancel"</i></td>
<td>Use this to change the text on the "Cancel"-button.</td>
</tr>
<tr>
<td><b>img</b></td>
<td><i>null</i></td>
<td>Add a customized icon for the modal. Should contain the src with the path to the image.</td>
</tr>
<!-- <tr>
<td><b>imageSize</b></td>
<td><i>"80x80"</i></td>
<td>If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height.</td>
</tr> -->
</table>
<p class="center">Here are the attributes that you can use into x-swall element:</p>
<table>
<tr class="titles">
<th>
<div class="border-left"></div>
Attributes
</th>
<th>Default value</th>
<th>
<div class="border-right"></div>
Description
</th>
</tr>
<tr>
<td><b>type</b></td>
<td><i>null</i></td>
<td>The type of the modal. x-swal comes with 4 built-in types which will show a corresponding icon animation: "<strong>warning</strong>", "<strong>error</strong>", "<strong>success</strong>" and "<strong>info"</strong>. It can either be put in the array under the key "type" or passed as the third parameter of the function.</td>
</tr>
<tr>
<td><b>allowOutsideClick</b></td>
<td><i>false</i></td>
<td>If set to <strong>true</strong>, the user can dismiss the modal by clicking outside it.</td>
</tr>
<tr>
<td><b>showCancelButton</b></td>
<td><i>false</i></td>
<td>If set to <strong>true</strong>, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.</td>
</tr>
<!-- <tr>
<td><b>confirmButtonColor</b></td>
<td><i>"#AEDEF4"</i></td>
<td>Use this to change the background color of the "Confirm"-button (must be a HEX value).</td>
</tr> -->
<tr>
<td><b>closeOnConfirm</b></td>
<td><i>true</i></td>
<td>Set to <i>false</i> if you want the modal to stay open even if the user presses the "Confirm"-button. This is especially useful if the function attached to the "Confirm"-button is another x-swal.</td>
</tr>
<!-- <tr>
<td><b>imageSize</b></td>
<td><i>"80x80"</i></td>
<td>If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height.</td>
</tr> -->
</table>
<p class="center">Methods of the x-swal element: </p>
<table>
<tr class="titles">
<th>
<div class="border-left"></div>
Methods
</th>
<th>
<div class="border-right"></div>
Description
</th>
</tr>
<tr>
<td><b>active</b></td>
<td>
This method active the window alert.
</td>
</tr>
</table>
<!-- Information -->
<h3>Information</h3>
<p>x-swal is an implementation using polymer of the <a href="https://github.com/t4t5/sweetalert" target="_blank">SweetAlert</a> was created by <a href="http://tristanedwards.me" target="_blank">Tristan Edwards</a>, you can follow him on <a href="https://twitter.com/t4t5" target="_blank" class="twitter">Twitter</a> or <a href="https://dribbble.com/tristanedwards" target="_blank" class="dribbble">Dribbble</a> for updates and other cool projects!</p>
<!-- Contribute -->
<h3>Contribute</h3>
<p>x-swal was created by <a href="https://github.com/ruben96" target="_blank">Rubén Cid</a>, you can follow him on <a href="https://twitter.com/GNUrub" target="_blank" class="twitter">Twitter</a>
<p>Feel free to fork x-swal on <a href="https://github.com/ruben96/x-swal" class="github">GitHub</a> if you have any features that you want to add!</p>
<footer>
<span class="te-logo">TE</span> • 2014
</footer>
<script>
document.querySelector('.showcase.normal button').onclick = function(){
alert("Oops... Something went wrong!");
};
document.querySelector('.showcase.sweet button').onclick = function(){
document.querySelector('.showcase.sweet x-swal').active();
};
document.querySelector('ul.examples li.message button').onclick = function(){
document.querySelector('ul.examples li.message x-swal').active();
};
document.querySelector('ul.examples li.title-text button').onclick = function(){
document.querySelector('ul.examples li.title-text x-swal').active();
};
document.querySelector('ul.examples li.success button').onclick = function(){
document.querySelector('ul.examples li.success x-swal').active();
};
document.querySelector('ul.examples li.warning.confirm button').onclick = function(){
var alert = document.querySelector('ul.examples li.warning.confirm x-swal');
alert.active(function(){
});
};
document.querySelector('ul.examples li.warning.cancel button').onclick = function(){
var alert = document.querySelector('ul.examples li.warning.cancel x-swal');
alert.active(function(status){
if (status) {
}else{
}
});
};
document.querySelector('ul.examples li.custom-icon button').onclick = function(){
document.querySelector('ul.examples li.custom-icon x-swal').active();
};
</script>
</body>
</html>