index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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.css">
  8. <!-- This is what you need -->
  9. <script src="../lib/sweet-alert.min.js"></script>
  10. <link rel="stylesheet" href="../lib/sweet-alert.css">
  11. <!--.......................-->
  12. </head>
  13. <body>
  14. <h1>Sweet Alert</h1>
  15. <h2>A beautiful replacement for Javascript's "Alert"</h2>
  16. <button class="download">Download</button>
  17. <!-- What does it do? -->
  18. <h3>So... What does it do?</h3>
  19. <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>
  20. <div class="showcase normal">
  21. <h4>Normal alert</h4>
  22. <button>Show error message</button>
  23. <h5>Code:</h5>
  24. <pre><span class="func">alert</span>(<span class="str">"Oops... Something went wrong!"</span>);
  25. </pre>
  26. <div class="vs-icon"></div>
  27. </div>
  28. <div class="showcase sweet">
  29. <h4>Sweet Alert</h4>
  30. <button>Show error message</button>
  31. <h5>Code:</h5>
  32. <pre>sweetAlert(<span class="str">"Oops..."</span>, <span class="str">"Something went wrong!"</span>, <span class="str">"error"</span>);</pre>
  33. </div>
  34. <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>
  35. <!-- Examples -->
  36. <h3>More examples</h3>
  37. <p class="center">In these examples, we're using the shorthand function <strong>swal</strong> to call sweetAlert.</p>
  38. <ul class="examples">
  39. <li class="message">
  40. <div class="ui">
  41. <p>A basic message</p>
  42. <button>Try me!</button>
  43. </div>
  44. <pre>swal(<span class="str">"Here's a message!"</span>)</pre>
  45. </li>
  46. <li class="title-text">
  47. <div class="ui">
  48. <p>A title with a text under</p>
  49. <button>Try me!</button>
  50. </div>
  51. <pre>swal(<span class="str">"Here's a message!"</span>, <span class="str">"It's pretty, isn't it?"</span>)</pre>
  52. </li>
  53. <li class="success">
  54. <div class="ui">
  55. <p>A success message!</p>
  56. <button>Try me!</button>
  57. </div>
  58. <pre>swal(<span class="str">"Good job!"</span>, <span class="str">"You clicked the button!"</span>, <span class="str">"success"</span>)</pre>
  59. </li>
  60. <li class="warning confirm">
  61. <div class="ui">
  62. <p>A warning message, with a function attached to the "Confirm"-button...</p>
  63. <button>Try me!</button>
  64. </div>
  65. <pre>swal({
  66. &nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
  67. &nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
  68. &nbsp;&nbsp;type: <span class="str">"warning"</span>,
  69. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  70. &nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
  71. &nbsp;&nbsp;confirmButtonText: <span class="str">"Yes, delete it!"</span>,
  72. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>
  73. },
  74. <span class="func"><i>function</i></span>(){
  75. &nbsp;&nbsp;<span class="func">swal</span>(<span class="str">"Deleted!"</span>, <span class="str">"Your imaginary file has been deleted."</span>, <span class="str">"success"</span>);
  76. });</pre>
  77. </li>
  78. <li class="warning cancel">
  79. <div class="ui">
  80. <p>... and by passing a parameter, you can execute something else for "Cancel".</p>
  81. <button>Try me!</button>
  82. </div>
  83. <pre>swal({
  84. &nbsp;&nbsp;title: <span class="str">"Are you sure?"</span>,
  85. &nbsp;&nbsp;text: <span class="str">"You will not be able to recover this imaginary file!"</span>,
  86. &nbsp;&nbsp;type: <span class="str">"warning"</span>,
  87. &nbsp;&nbsp;showCancelButton: <span class="val">true</span>,
  88. &nbsp;&nbsp;confirmButtonColor: <span class="str">"#DD6B55"</span>,
  89. &nbsp;&nbsp;confirmButtonText: <span class="str">"Yes, delete it!"</span>,
  90. &nbsp;&nbsp;cancelButtonText: <span class="str">"No, cancel plx!"</span>,
  91. &nbsp;&nbsp;closeOnConfirm: <span class="val">false</span>,
  92. &nbsp;&nbsp;closeOnCancel: <span class="val">false</span>
  93. },
  94. <span class="func"><i>function</i></span>(isConfirm){
  95. &nbsp;&nbsp;<span class="tag">if</span> (isConfirm) {
  96. &nbsp;&nbsp;&nbsp;&nbsp;<span class="func">swal</span>(<span class="str">"Deleted!"</span>, <span class="str">"Your imaginary file has been deleted."</span>, <span class="str">"success"</span>);
  97. &nbsp;&nbsp;} <span class="tag">else</span> {
  98. &nbsp;&nbsp;&nbsp;&nbsp;<span class="func">swal</span>(<span class="str">"Cancelled"</span>, <span class="str">"Your imaginary file is safe :)"</span>, <span class="str">"error"</span>);
  99. &nbsp;&nbsp;}
  100. });</pre>
  101. </li>
  102. <li class="custom-icon">
  103. <div class="ui">
  104. <p>A message with a custom icon</p>
  105. <button>Try me!</button>
  106. </div>
  107. <pre>swal({
  108. &nbsp;&nbsp;title: <span class="str">"Sweet!"</span>,
  109. &nbsp;&nbsp;text: <span class="str">"Here's a custom image."</span>,
  110. &nbsp;&nbsp;imageUrl: <span class="str">"images/thumbs-up.jpg"</span>
  111. });</pre>
  112. </li>
  113. <li class="message-html">
  114. <div class="ui">
  115. <p>An HTML message</p>
  116. <button>Try me!</button>
  117. </div>
  118. <pre>swal({
  119. &nbsp;&nbsp;title: <span class="str">"HTML &lt;small&gt;Title&lt;/small&gt;!"</span>,
  120. &nbsp;&nbsp;text: <span class="str">"A custom &lt;span style="color:#F8BB86"&gt;html&lt;span&gt; message."</span>,
  121. &nbsp;&nbsp;html: <span class="str">true</span>
  122. });</pre>
  123. </li>
  124. <li class="timer">
  125. <div class="ui">
  126. <p>A message with auto close timer</p>
  127. <button>Try me!</button>
  128. </div>
  129. <pre>swal({
  130. &nbsp;&nbsp;title: <span class="str">"Auto close alert!"</span>,
  131. &nbsp;&nbsp;text: <span class="str">"I will close in 2 seconds."</span>,
  132. &nbsp;&nbsp;timer: <span class="str">2000</span>,
  133. &nbsp;&nbsp;showConfirmButton: <span class="str">false</span>
  134. });</pre>
  135. </li>
  136. </ul>
  137. <!-- Download & Install -->
  138. <h3 id="download-section">Download & install</h3>
  139. <div class="center-container">
  140. <p class="center"><b>Method 1:</b> Install through bower:</p>
  141. <pre class="center">$ bower install sweetalert</pre>
  142. </div>
  143. <p class="center"><b>Method 2:</b> Download the sweetAlert <strong>CSS</strong> and <strong>JavaScript</strong> files.</p>
  144. <a class="button" href="https://github.com/t4t5/sweetalert/archive/master.zip" download>Download files</a>
  145. <ol>
  146. <li>
  147. <p>Initialize the plugin by referencing the necessary files:</p>
  148. <pre>&lt;<span class="tag">script</span> <span class="attr">src</span>=<span class="str">"lib/sweet-alert.min.js"</span>&gt;&lt;/<span class="tag">script</span>&gt;
  149. &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">"lib/sweet-alert.css"</span>&gt;</pre>
  150. </li>
  151. <li>
  152. <p>Call the sweetAlert-function after the page has loaded</p>
  153. <pre>swal({
  154. &nbsp;&nbsp;title: <span class="str">"Error!"</span>,
  155. &nbsp;&nbsp;text: <span class="str">"Here's my error message!"</span>,
  156. &nbsp;&nbsp;type: <span class="str">"error"</span>,
  157. &nbsp;&nbsp;confirmButtonText: <span class="str">"Cool"</span>
  158. });
  159. </pre>
  160. </li>
  161. </ol>
  162. <!-- Configuration -->
  163. <h3>Configuration</h3>
  164. <p class="center">Here are the keys that you can use if you pass an object into sweetAlert:</p>
  165. <table>
  166. <tr class="titles">
  167. <th>
  168. <div class="border-left"></div>
  169. Argument
  170. </th>
  171. <th>Default value</th>
  172. <th>
  173. <div class="border-right"></div>
  174. Description
  175. </th>
  176. </tr>
  177. <tr>
  178. <td><b>title</b></td>
  179. <td><i>null (required)</i></td>
  180. <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>
  181. </tr>
  182. <tr>
  183. <td><b>text</b></td>
  184. <td><i>null</i></td>
  185. <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>
  186. </tr>
  187. <tr>
  188. <td><b>type</b></td>
  189. <td><i>null</i></td>
  190. <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>. It can either be put in the array under the key "type" or passed as the third parameter of the function.</td>
  191. </tr>
  192. <tr>
  193. <td><b>allowEscapeKey</b></td>
  194. <td><i>true</i></td>
  195. <td>If set to <strong>true</strong>, the user can dismiss the modal by pressing the Escape key.</td>
  196. </tr>
  197. <tr>
  198. <td><b>customClass</b></td>
  199. <td><i>null</i></td>
  200. <td>A custom CSS class for the modal. It can be added to the object under the key "customClass".</td>
  201. </tr>
  202. <tr>
  203. <td><b>allowOutsideClick</b></td>
  204. <td><i>false</i></td>
  205. <td>If set to <strong>true</strong>, the user can dismiss the modal by clicking outside it.</td>
  206. </tr>
  207. <tr>
  208. <td><b>showCancelButton</b></td>
  209. <td><i>false</i></td>
  210. <td>If set to <strong>true</strong>, a "Cancel"-button will be shown, which the user can click on to dismiss the modal.</td>
  211. </tr>
  212. <tr>
  213. <td><b>showConfirmButton</b></td>
  214. <td><i>true</i></td>
  215. <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>
  216. </tr>
  217. <tr>
  218. <td><b>confirmButtonText</b></td>
  219. <td><i>"OK"</i></td>
  220. <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>
  221. </tr>
  222. <tr>
  223. <td><b>confirmButtonColor</b></td>
  224. <td><i>"#AEDEF4"</i></td>
  225. <td>Use this to change the background color of the "Confirm"-button (must be a HEX value).</td>
  226. </tr>
  227. <tr>
  228. <td><b>cancelButtonText</b></td>
  229. <td><i>"Cancel"</i></td>
  230. <td>Use this to change the text on the "Cancel"-button.</td>
  231. </tr>
  232. <tr>
  233. <td><b>closeOnConfirm</b></td>
  234. <td><i>true</i></td>
  235. <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>
  236. </tr>
  237. <tr>
  238. <td><b>imageUrl</b></td>
  239. <td><i>null</i></td>
  240. <td>Add a customized icon for the modal. Should contain a string with the path to the image.</td>
  241. </tr>
  242. <tr>
  243. <td><b>imageSize</b></td>
  244. <td><i>"80x80"</i></td>
  245. <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>
  246. </tr>
  247. <tr>
  248. <td><b>timer</b></td>
  249. <td><i>null</i></td>
  250. <td>Auto close timer of the modal. Set in ms (milliseconds).</td>
  251. </tr>
  252. <tr>
  253. <td><b>html</b></td>
  254. <td><i>false</i></td>
  255. <td>If set to true, will not escape title and text parameters. (Set to false if you're worried about XSS attacks.)</td>
  256. </tr>
  257. <tr>
  258. <td><b>animation</b></td>
  259. <td><i>true</i></td>
  260. <td>If set to <strong>false</strong>, the modal's animation will be disabled.</td>
  261. </tr>
  262. </table>
  263. <!-- Methods -->
  264. <h3>Methods</h3>
  265. <p class="center">SweetAlert also comes with some simple methods that you can call:</p>
  266. <table>
  267. <tr class="titles">
  268. <th>
  269. <div class="border-left"></div>
  270. Function
  271. </th>
  272. <th>Example</th>
  273. <th>
  274. <div class="border-right"></div>
  275. Description
  276. </th>
  277. </tr>
  278. <tr>
  279. <td>setDefaults</td>
  280. <td><i>swal.setDefaults({ confirmButtonColor: '#0000' });</i></td>
  281. <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>
  282. </tr>
  283. <tr>
  284. <td>close</td>
  285. <td><i>swal.close();</i></td>
  286. <td>Close the currently open SweetAlert programatically.</td>
  287. </tr>
  288. </table>
  289. <!-- Contribute -->
  290. <h3>Contribute</h3>
  291. <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>
  292. <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>
  293. <footer>
  294. <span class="te-logo">TE</span> • <script>document.write(new Date().getFullYear())</script>
  295. </footer>
  296. <script>
  297. document.querySelector('button.download').onclick = function(){
  298. $("html, body").animate({ scrollTop: $("#download-section").offset().top }, 1000);
  299. };
  300. document.querySelector('.showcase.normal button').onclick = function(){
  301. alert("Oops... Something went wrong!");
  302. };
  303. document.querySelector('.showcase.sweet button').onclick = function(){
  304. swal("Oops...", "Something went wrong!", "error");
  305. };
  306. document.querySelector('ul.examples li.message button').onclick = function(){
  307. swal("Here's a message!");
  308. };
  309. document.querySelector('ul.examples li.timer button').onclick = function(){
  310. swal({
  311. title: "Auto close alert!",
  312. text: "I will close in 2 seconds.",
  313. timer: 2000,
  314. showConfirmButton: false
  315. });
  316. };
  317. document.querySelector('ul.examples li.title-text button').onclick = function(){
  318. swal("Here's a message!", "It's pretty, isn't it?");
  319. };
  320. document.querySelector('ul.examples li.success button').onclick = function(){
  321. swal("Good job!", "You clicked the button!", "success");
  322. };
  323. document.querySelector('ul.examples li.warning.confirm button').onclick = function(){
  324. swal({
  325. title: "Are you sure?",
  326. text: "You will not be able to recover this imaginary file!",
  327. type: "warning",
  328. showCancelButton: true,
  329. confirmButtonColor: '#DD6B55',
  330. confirmButtonText: 'Yes, delete it!',
  331. closeOnConfirm: false
  332. },
  333. function(){
  334. swal("Deleted!", "Your imaginary file has been deleted!", "success");
  335. });
  336. };
  337. document.querySelector('ul.examples li.warning.cancel button').onclick = function(){
  338. swal({
  339. title: "Are you sure?",
  340. text: "You will not be able to recover this imaginary file!",
  341. type: "warning",
  342. showCancelButton: true,
  343. confirmButtonColor: '#DD6B55',
  344. confirmButtonText: 'Yes, delete it!',
  345. cancelButtonText: "No, cancel plx!",
  346. closeOnConfirm: false,
  347. closeOnCancel: false
  348. },
  349. function(isConfirm){
  350. if (isConfirm){
  351. swal("Deleted!", "Your imaginary file has been deleted!", "success");
  352. } else {
  353. swal("Cancelled", "Your imaginary file is safe :)", "error");
  354. }
  355. });
  356. };
  357. document.querySelector('ul.examples li.custom-icon button').onclick = function(){
  358. swal({
  359. title: "Sweet!",
  360. text: "Here's a custom image.",
  361. imageUrl: 'images/thumbs-up.jpg'
  362. });
  363. };
  364. document.querySelector('ul.examples li.message-html button').onclick = function(){
  365. swal({
  366. title: "HTML <small>Title</small>!",
  367. text: 'A custom <span style="color:#F8BB86">html<span> message.',
  368. html: true
  369. });
  370. };
  371. </script>
  372. </body>
  373. </html>