index.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
  6. <title>SweetAlert</title>
  7. <link rel="stylesheet" href="example/example.css">
  8. <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
  9. <!-- This is what you need -->
  10. <script src="dist/sweetalert-dev.js"></script>
  11. <link rel="stylesheet" href="dist/sweetalert.css">
  12. <!--.......................-->
  13. </head>
  14. <body>
  15. <h1>Sweet Alert</h1>
  16. <h2>A beautiful replacement for JavaScript's "Alert"</h2>
  17. <button class="download">Download</button>
  18. <!-- What does it do? -->
  19. <h3>So... What does it do?</h3>
  20. <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>sweetAlert</strong>.</p>
  21. <div class="showcase normal">
  22. <h4>Normal alert</h4>
  23. <button>Show error message</button>
  24. <h5>Code:</h5>
  25. <pre><span class="attr">alert</span>(<span class="str">"Oops... Something went wrong!"</span>);
  26. </pre>
  27. <div class="vs-icon"></div>
  28. </div>
  29. <div class="showcase sweet">
  30. <h4>Sweet Alert</h4>
  31. <button>Show error message</button>
  32. <h5>Code:</h5>
  33. <pre><span class="attr">sweetAlert</span>(<span class="str">"Oops..."</span>, <span class="str">"Something went wrong!"</span>, <span class="str">"error"</span>);</pre>
  34. </div>
  35. <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>
  36. <!-- Examples -->
  37. <h3>More examples</h3>
  38. <p class="center">In these examples, we're using the shorthand function <strong>swal</strong> to call sweetAlert.</p>
  39. <ul class="examples">
  40. <li class="message">
  41. <div class="ui">
  42. <p>A basic message</p>
  43. <button>Try me!</button>
  44. </div>
  45. <pre><span class="attr">swal</span>(<span class="str">"Here's a message!"</span>)</pre>
  46. </li>
  47. <li class="title-text">
  48. <div class="ui">
  49. <p>A title with a text under</p>
  50. <button>Try me!</button>
  51. </div>
  52. <pre><span class="attr">swal</span>(<span class="str">"Here's a message!"</span>, <span class="str">"It's pretty, isn't it?"</span>)</pre>
  53. </li>
  54. <li class="success">
  55. <div class="ui">
  56. <p>A success message!</p>
  57. <button>Try me!</button>
  58. </div>
  59. <pre><span class="attr">swal</span>(<span class="str">"Good job!"</span>, <span class="str">"You clicked the button!"</span>, <span class="str">"success"</span>)</pre>
  60. </li>
  61. <li class="warning confirm">
  62. <div class="ui">
  63. <p>A warning message, with a function attached to the "Confirm"-button...</p>
  64. <button>Try me!</button>
  65. </div>
  66. <pre><span class="attr">swal</span>({
  67. &nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
  68. &nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
  69. &nbsp;&nbsp;type: <span class="str">"warning"</span>,
  70. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  71. &nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
  72. &nbsp;&nbsp;confirmButtonText: <span class="str">"Yes, delete it!"</span>,
  73. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>
  74. },
  75. <span class="func"><i>function</i></span>(){
  76. &nbsp;&nbsp;<span class="attr">swal</span>(<span class="str">"Deleted!"</span>, <span class="str">"Your imaginary file has been deleted."</span>, <span class="str">"success"</span>);
  77. });</pre>
  78. </li>
  79. <li class="warning cancel">
  80. <div class="ui">
  81. <p>... and by passing a parameter, you can execute something else for "Cancel".</p>
  82. <button>Try me!</button>
  83. </div>
  84. <pre><span class="attr">swal</span>({
  85. &nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
  86. &nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
  87. &nbsp;&nbsp;type: <span class="str">"warning"</span>,
  88. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  89. &nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
  90. &nbsp;&nbsp;confirmButtonText: <span class="str">"Yes, delete it!"</span>,
  91. &nbsp;&nbsp;cancelButtonText: <span class="str">"No, cancel plx!"</span>,
  92. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>,
  93. &nbsp;&nbsp;closeOnCancel: <span class="val">false</span>
  94. },
  95. <span class="func"><i>function</i></span>(isConfirm){
  96. &nbsp;&nbsp;<span class="tag">if</span> (isConfirm) {
  97. &nbsp;&nbsp;&nbsp;&nbsp;<span class="attr">swal</span>(<span class="str">"Deleted!"</span>, <span class="str">"Your imaginary file has been deleted."</span>, <span class="str">"success"</span>);
  98. &nbsp;&nbsp;} <span class="tag">else</span> {
  99. &nbsp;&nbsp;&nbsp;&nbsp;<span class="attr">swal</span>(<span class="str">"Cancelled"</span>, <span class="str">"Your imaginary file is safe :)"</span>, <span class="str">"error"</span>);
  100. &nbsp;&nbsp;}
  101. });</pre>
  102. </li>
  103. <li class="custom-icon">
  104. <div class="ui">
  105. <p>A message with a custom icon</p>
  106. <button>Try me!</button>
  107. </div>
  108. <pre><span class="attr">swal</span>({
  109. &nbsp;&nbsp;title: <span class="str">"Sweet!"</span>,
  110. &nbsp;&nbsp;text: <span class="str">"Here's a custom image."</span>,
  111. &nbsp;&nbsp;imageUrl: <span class="str">"images/thumbs-up.jpg"</span>
  112. });</pre>
  113. </li>
  114. <li class="message-html">
  115. <div class="ui">
  116. <p>An HTML message</p>
  117. <button>Try me!</button>
  118. </div>
  119. <pre><span class="attr">swal</span>({
  120. &nbsp;&nbsp;title: <span class="str">"HTML &lt;small&gt;Title&lt;/small&gt;!"</span>,
  121. &nbsp;&nbsp;text: <span class="str">"A custom &lt;span style="color:#F8BB86"&gt;html&lt;span&gt; message."</span>,
  122. &nbsp;&nbsp;html: <span class="val">true</span>
  123. });</pre>
  124. </li>
  125. <li class="timer">
  126. <div class="ui">
  127. <p>A message with auto close timer</p>
  128. <button>Try me!</button>
  129. </div>
  130. <pre><span class="attr">swal</span>({
  131. &nbsp;&nbsp;title: <span class="str">"Auto close alert!"</span>,
  132. &nbsp;&nbsp;text: <span class="str">"I will close in 2 seconds."</span>,
  133. &nbsp;&nbsp;timer: <span class="val">2000</span>,
  134. &nbsp;&nbsp;showConfirmButton: <span class="val">false</span>
  135. });</pre>
  136. </li>
  137. <li class="input">
  138. <div class="ui">
  139. <p>A replacement for the "prompt" function</p>
  140. <button>Try me!</button>
  141. </div>
  142. <pre><span class="attr">swal</span>({
  143. &nbsp;&nbsp;title: <span class="str">"An input!"</span>,
  144. &nbsp;&nbsp;text: <span class="str">"Write something interesting:"</span>,
  145. &nbsp;&nbsp;type: <span class="str">"input"</span>,
  146. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  147. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>,
  148. &nbsp;&nbsp;animation: <span class="str">"slide-from-top"</span>,
  149. &nbsp;&nbsp;inputPlaceholder: <span class="str">"Write something"</span>
  150. },
  151. <span class="func"><i>function</i></span>(<span class="arg">inputValue</span>){
  152. &nbsp;&nbsp;<span class="tag">if</span> (inputValue <span class="tag">===</span> <span class="val">false</span>) <span class="tag">return</span> <span class="val">false</span>;
  153. &nbsp;&nbsp;
  154. &nbsp;&nbsp;<span class="tag">if</span> (inputValue <span class="tag">===</span> <span class="str">""</span>) {
  155. &nbsp;&nbsp;&nbsp;&nbsp;swal<span class="tag">.</span><span class="attr">showInputError</span>(<span class="str">"You need to write something!"</span>);
  156. &nbsp;&nbsp;&nbsp;&nbsp;<span class="tag">return</span> <span class="val">false</span>
  157. &nbsp;&nbsp;}
  158. &nbsp;&nbsp;
  159. &nbsp;&nbsp;<span class="attr">swal</span>(<span class="str">"Nice!"</span>, <span class="str">"You wrote: "</span> + inputValue, <span class="str">"success"</span>);
  160. });</pre>
  161. </li>
  162. <li class="ajax">
  163. <div class="ui">
  164. <p>With a loader (for AJAX request for example)</p>
  165. <button>Try me!</button>
  166. </div>
  167. <pre><span class="attr">swal</span>({
  168. &nbsp;&nbsp;title: <span class="str">"Ajax request example"</span>,
  169. &nbsp;&nbsp;text: <span class="str">"Submit to run ajax request"</span>,
  170. &nbsp;&nbsp;type: <span class="str">"info"</span>,
  171. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  172. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>,
  173. &nbsp;&nbsp;showLoaderOnConfirm: <span class="val">true</span>,
  174. },
  175. <span class="func"><i>function</i></span>(){
  176. &nbsp;&nbsp;<span class="attr">setTimeout</span>(<span class="func"><i>function</i></span>(){
  177. &nbsp;&nbsp;&nbsp;&nbsp;<span class="attr">swal</span>(<span class="str">"Ajax request finished!"</span>);
  178. &nbsp;&nbsp;}, <span class="val">2000</span>);
  179. });</pre>
  180. </li>
  181. <li class="theme">
  182. <div class="ui">
  183. <p>You can also change the theme of SweetAlert!</p>
  184. <button>Try me!</button>
  185. </div>
  186. <pre>&lt;<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"stylesheet"</span> <span class="tag">type</span>=<span class="str">"text/css"</span> <span class="tag">href</span>=<span class="str">"dist/sweetalert.css"</span>&gt;
  187. &lt;<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"stylesheet"</span> <span class="tag">type</span>=<span class="str">"text/css"</span> <span class="tag">href</span>=<span class="str">"themes/twitter.css"</span>&gt;</pre>
  188. </li>
  189. </ul>
  190. <!-- Download & Install -->
  191. <h3 id="download-section">Download & install</h3>
  192. <div class="center-container">
  193. <p class="center"><b>Method 1:</b> Install through bower:</p>
  194. <pre class="center">$ bower install sweetalert</pre>
  195. </div>
  196. <div class="center-container">
  197. <p class="center"><b>Method 2:</b> Install through NPM:</p>
  198. <pre class="center">$ npm install sweetalert</pre>
  199. </div>
  200. <p class="center"><b>Method 3:</b> Download the sweetAlert <strong>CSS</strong> and <strong>JavaScript</strong> files.</p>
  201. <a class="button" href="https://github.com/t4t5/sweetalert/archive/master.zip" download>Download files</a>
  202. <ol>
  203. <li>
  204. <p>Initialize the plugin by referencing the necessary files:</p>
  205. <pre>&lt;<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"dist/sweetalert.min.js"</span>&gt;&lt;/<span class="tag">script</span>&gt;
  206. &lt;<span class="tag">link</span> <span class="attr">rel</span>=<span class="str">"stylesheet"</span> <span class="tag">type</span>=<span class="str">"text/css"</span> <span class="tag">href</span>=<span class="str">"dist/sweetalert.css"</span>&gt;</pre>
  207. </li>
  208. <li>
  209. <p>Call the sweetAlert-function after the page has loaded</p>
  210. <pre><span class="attr">swal</span>({
  211. &nbsp;&nbsp;title: <span class="str">"Error!"</span>,
  212. &nbsp;&nbsp;text: <span class="str">"Here's my error message!"</span>,
  213. &nbsp;&nbsp;type: <span class="str">"error"</span>,
  214. &nbsp;&nbsp;confirmButtonText: <span class="str">"Cool"</span>
  215. });
  216. </pre>
  217. </li>
  218. </ol>
  219. <!-- Configuration -->
  220. <h3>Configuration</h3>
  221. <p class="center">Here are the keys that you can use if you pass an object into sweetAlert:</p>
  222. <table>
  223. <tr class="titles">
  224. <th>
  225. <div class="border-left"></div>
  226. Argument
  227. </th>
  228. <th>Default value</th>
  229. <th>
  230. <div class="border-right"></div>
  231. Description
  232. </th>
  233. </tr>
  234. <tr>
  235. <td><b>title</b></td>
  236. <td><i>null (required)</i></td>
  237. <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>
  238. </tr>
  239. <tr>
  240. <td><b>text</b></td>
  241. <td><i>null</i></td>
  242. <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>
  243. </tr>
  244. <tr>
  245. <td><b>type</b></td>
  246. <td><i>null</i></td>
  247. <td>The type of the modal. SweetAlert 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>. You can also set it as "<strong>input</strong>" to get a prompt modal. It can either be put in the object under the key "type" or passed as the third parameter of the function.</td>
  248. </tr>
  249. <tr>
  250. <td><b>allowEscapeKey</b></td>
  251. <td><i>true</i></td>
  252. <td>If set to <strong>true</strong>, the user can dismiss the modal by pressing the Escape key.</td>
  253. </tr>
  254. <tr>
  255. <td><b>customClass</b></td>
  256. <td><i>null</i></td>
  257. <td>A custom CSS class for the modal. It can be added to the object under the key "customClass".</td>
  258. </tr>
  259. <tr>
  260. <td><b>allowOutsideClick</b></td>
  261. <td><i>false</i></td>
  262. <td>If set to <strong>true</strong>, the user can dismiss the modal by clicking outside it.</td>
  263. </tr>
  264. <tr>
  265. <td><b>showCancelButton</b></td>
  266. <td><i>false</i></td>
  267. <td>If set to <strong>true</strong>, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.</td>
  268. </tr>
  269. <tr>
  270. <td><b>showConfirmButton</b></td>
  271. <td><i>true</i></td>
  272. <td>If set to <strong>false</strong>, the "OK/Confirm"-button will be hidden. Make sure you set a timer or set allowOutsideClick to true when using this, in order not to annoy the user.</td>
  273. </tr>
  274. <tr>
  275. <td><b>confirmButtonText</b></td>
  276. <td><i>"OK"</i></td>
  277. <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>
  278. </tr>
  279. <tr>
  280. <td><b>confirmButtonColor</b></td>
  281. <td><i>"#AEDEF4"</i></td>
  282. <td>Use this to change the background color of the "Confirm"-button (must be a HEX value).</td>
  283. </tr>
  284. <tr>
  285. <td><b>cancelButtonText</b></td>
  286. <td><i>"Cancel"</i></td>
  287. <td>Use this to change the text on the "Cancel"-button.</td>
  288. </tr>
  289. <tr>
  290. <td><b>closeOnConfirm</b></td>
  291. <td><i>true</i></td>
  292. <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 SweetAlert.</td>
  293. </tr>
  294. <tr>
  295. <td><b>closeOnCancel</b></td>
  296. <td><i>true</i></td>
  297. <td>Same as closeOnConfirm, but for the cancel button.</td>
  298. </tr>
  299. <tr>
  300. <td><b>imageUrl</b></td>
  301. <td><i>null</i></td>
  302. <td>Add a customized icon for the modal. Should contain a string with the path to the image.</td>
  303. </tr>
  304. <tr>
  305. <td><b>imageSize</b></td>
  306. <td><i>"80x80"</i></td>
  307. <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>
  308. </tr>
  309. <tr>
  310. <td><b>timer</b></td>
  311. <td><i>null</i></td>
  312. <td>Auto close timer of the modal. Set in ms (milliseconds).</td>
  313. </tr>
  314. <tr>
  315. <td><b>html</b></td>
  316. <td><i>false</i></td>
  317. <td>If set to true, will not escape title and text parameters. (Set to false if you're worried about XSS attacks.)</td>
  318. </tr>
  319. <tr>
  320. <td><b>animation</b></td>
  321. <td><i>true</i></td>
  322. <td>If set to <strong>false</strong>, the modal's animation will be disabled. Possible (string) values : <strong>pop</strong> (default when animation set to true), <strong>slide-from-top</strong>, <strong>slide-from-bottom</strong></td>
  323. </tr>
  324. <tr>
  325. <td><b>inputType</b></td>
  326. <td><i>"text"</i></td>
  327. <td>Change the type of the input field when using <strong>type: "input"</strong> (this can be useful if you want users to type in their password for example).</td>
  328. </tr>
  329. <tr>
  330. <td><b>inputPlaceholder</b></td>
  331. <td><i>null</i></td>
  332. <td>When using the input-type, you can specify a placeholder to help the user.</td>
  333. </tr>
  334. <tr>
  335. <td><b>inputValue</b></td>
  336. <td><i>null</i></td>
  337. <td>Specify a default text value that you want your input to show when using <strong>type: "input"</strong></td>
  338. </tr>
  339. <tr>
  340. <td><b>showLoaderOnConfirm</b></td>
  341. <td><i>false</i></td>
  342. <td>Set to <strong>true</strong> to disable the buttons and show that something is loading.</td>
  343. </tr>
  344. </table>
  345. <!-- Methods -->
  346. <h3>Methods</h3>
  347. <p class="center">SweetAlert also comes with some simple methods that you can call:</p>
  348. <table>
  349. <tr class="titles">
  350. <th>
  351. <div class="border-left"></div>
  352. Function
  353. </th>
  354. <th>Example</th>
  355. <th>
  356. <div class="border-right"></div>
  357. Description
  358. </th>
  359. </tr>
  360. <tr>
  361. <td>setDefaults</td>
  362. <td><i>swal.setDefaults({ confirmButtonColor: '#0000' });</i></td>
  363. <td>If you end up using a lot of the same settings when calling SweetAlert, you can use setDefaults at the start of your program to set them once and for all!</td>
  364. </tr>
  365. <tr>
  366. <td>close</td>
  367. <td><i>swal.close();</i></td>
  368. <td>Close the currently open SweetAlert programatically.</td>
  369. </tr>
  370. <tr>
  371. <td>showInputError</td>
  372. <td><i>swal.showInputError("Invalid email!");</i></td>
  373. <td>Show an error message after validating the input field, if the user's data is bad</td>
  374. </tr>
  375. <tr>
  376. <td>enableButtons, disableButtons</td>
  377. <td><i>swal.disableButtons();</i></td>
  378. <td>Disable or enable the user to click on the cancel and confirm buttons.</td>
  379. </tr>
  380. </table>
  381. <!-- Contribute -->
  382. <h3>Contribute</h3>
  383. <p>SweetAlert 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>
  384. <p>Feel free to fork SweetAlert on <a href="https://github.com/t4t5/sweetalert" class="github">GitHub</a> if you have any features that you want to add!</p>
  385. <footer>
  386. <span class="te-logo">TE</span> • <script>document.write(new Date().getFullYear())</script>
  387. </footer>
  388. <script>
  389. document.querySelector('button.download').onclick = function(){
  390. $("html, body").animate({ scrollTop: $("#download-section").offset().top }, 1000);
  391. };
  392. document.querySelector('.showcase.normal button').onclick = function(){
  393. alert("Oops... Something went wrong!");
  394. };
  395. document.querySelector('.showcase.sweet button').onclick = function(){
  396. swal("Oops...", "Something went wrong!", "error");
  397. };
  398. document.querySelector('ul.examples li.message button').onclick = function(){
  399. swal("Here's a message!");
  400. };
  401. document.querySelector('ul.examples li.timer button').onclick = function(){
  402. swal({
  403. title: "Auto close alert!",
  404. text: "I will close in 2 seconds.",
  405. timer: 2000,
  406. showConfirmButton: false
  407. });
  408. };
  409. document.querySelector('ul.examples li.title-text button').onclick = function(){
  410. swal("Here's a message!", "It's pretty, isn't it?");
  411. };
  412. document.querySelector('ul.examples li.success button').onclick = function(){
  413. swal("Good job!", "You clicked the button!", "success");
  414. };
  415. document.querySelector('ul.examples li.warning.confirm button').onclick = function(){
  416. swal({
  417. title: "Are you sure?",
  418. text: "You will not be able to recover this imaginary file!",
  419. type: "warning",
  420. showCancelButton: true,
  421. confirmButtonColor: '#DD6B55',
  422. confirmButtonText: 'Yes, delete it!',
  423. closeOnConfirm: false
  424. },
  425. function(){
  426. swal("Deleted!", "Your imaginary file has been deleted!", "success");
  427. });
  428. };
  429. document.querySelector('ul.examples li.warning.cancel button').onclick = function(){
  430. swal({
  431. title: "Are you sure?",
  432. text: "You will not be able to recover this imaginary file!",
  433. type: "warning",
  434. showCancelButton: true,
  435. confirmButtonColor: '#DD6B55',
  436. confirmButtonText: 'Yes, delete it!',
  437. cancelButtonText: "No, cancel plx!",
  438. closeOnConfirm: false,
  439. closeOnCancel: false
  440. },
  441. function(isConfirm){
  442. if (isConfirm){
  443. swal("Deleted!", "Your imaginary file has been deleted!", "success");
  444. } else {
  445. swal("Cancelled", "Your imaginary file is safe :)", "error");
  446. }
  447. });
  448. };
  449. document.querySelector('ul.examples li.custom-icon button').onclick = function(){
  450. swal({
  451. title: "Sweet!",
  452. text: "Here's a custom image.",
  453. imageUrl: 'example/images/thumbs-up.jpg'
  454. });
  455. };
  456. document.querySelector('ul.examples li.message-html button').onclick = function(){
  457. swal({
  458. title: "HTML <small>Title</small>!",
  459. text: 'A custom <span style="color:#F8BB86">html<span> message.',
  460. html: true
  461. });
  462. };
  463. document.querySelector('ul.examples li.input button').onclick = function(){
  464. swal({
  465. title: "An input!",
  466. text: 'Write something interesting:',
  467. type: 'input',
  468. showCancelButton: true,
  469. closeOnConfirm: false,
  470. animation: "slide-from-top",
  471. inputPlaceholder: "Write something",
  472. },
  473. function(inputValue){
  474. if (inputValue === false) return false;
  475. if (inputValue === "") {
  476. swal.showInputError("You need to write something!");
  477. return false;
  478. }
  479. swal("Nice!", 'You wrote: ' + inputValue, "success");
  480. });
  481. };
  482. document.querySelector('ul.examples li.theme button').onclick = function() {
  483. swal({
  484. title: "Themes!",
  485. text: "Here's the Twitter theme for SweetAlert!",
  486. confirmButtonText: "Cool!",
  487. customClass: 'twitter'
  488. });
  489. };
  490. document.querySelector('ul.examples li.ajax button').onclick = function() {
  491. swal({
  492. title: 'Ajax request example',
  493. text: 'Submit to run ajax request',
  494. type: 'info',
  495. showCancelButton: true,
  496. closeOnConfirm: false,
  497. showLoaderOnConfirm: true,
  498. }, function(){
  499. setTimeout(function() {
  500. swal('Ajax request finished!');
  501. }, 2000);
  502. });
  503. };
  504. </script>
  505. </body>
  506. </html>