Dialogs and Notification Logs using Jquery

Language

In this tutorial, we are going to learn about dialogs and notification logs using jquery. You can use this in your systems or projects. just download the source code.

Instructions

Link the css and js scipts

  1. <link rel="stylesheet" href="../themes/alertify.core.css" />
  2. <link rel="stylesheet" href="../themes/alertify.bootstrap.css" id="toggleCSS" />
  3. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  4. <script src="../lib/alertify.min.js"></script>

Writing the javascript code

  1. <script>
  2. function reset () {
  3. $("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
  4. alertify.set({
  5. labels : {
  6. ok : "OK",
  7. cancel : "Cancel"
  8. },
  9. delay : 5000,
  10. buttonReverse : false,
  11. buttonFocus : "ok"
  12. });
  13. }
  14.  
  15. // ==============================
  16. // Standard Dialogs
  17. $("#alert").on( 'click', function () {
  18. reset();
  19. alertify.alert("This is an alert dialog");
  20. return false;
  21. });
  22.  
  23. $("#confirm").on( 'click', function () {
  24. reset();
  25. alertify.confirm("This is a confirm dialog", function (e) {
  26. if (e) {
  27. alertify.success("You've clicked OK");
  28. } else {
  29. alertify.error("You've clicked Cancel");
  30. }
  31. });
  32. return false;
  33. });
  34.  
  35. $("#prompt").on( 'click', function () {
  36. reset();
  37. alertify.prompt("This is a prompt dialog", function (e, str) {
  38. if (e) {
  39. alertify.success("You've clicked OK and typed: " + str);
  40. } else {
  41. alertify.error("You've clicked Cancel");
  42. }
  43. }, "Default Value");
  44. return false;
  45. });
  46.  
  47. // ==============================
  48. // Ajax
  49. $("#ajax").on("click", function () {
  50. reset();
  51. alertify.confirm("Confirm?", function (e) {
  52. if (e) {
  53. alertify.alert("Successful AJAX after OK");
  54. } else {
  55. alertify.alert("Successful AJAX after Cancel");
  56. }
  57. });
  58. });
  59.  
  60. // ==============================
  61. // Standard Dialogs
  62. $("#notification").on( 'click', function () {
  63. reset();
  64. alertify.log("Standard log message");
  65. return false;
  66. });
  67.  
  68. $("#success").on( 'click', function () {
  69. reset();
  70. alertify.success("Success log message");
  71. return false;
  72. });
  73.  
  74. $("#error").on( 'click', function () {
  75. reset();
  76. alertify.error("Error log message");
  77. return false;
  78. });
  79.  
  80. // ==============================
  81. // Custom Properties
  82. $("#delay").on( 'click', function () {
  83. reset();
  84. alertify.set({ delay: 10000 });
  85. alertify.log("Hiding in 10 seconds");
  86. return false;
  87. });
  88.  
  89. $("#forever").on( 'click', function () {
  90. reset();
  91. alertify.log("Will stay until clicked", "", 0);
  92. return false;
  93. });
  94.  
  95. $("#labels").on( 'click', function () {
  96. reset();
  97. alertify.set({ labels: { ok: "Accept", cancel: "Deny" } });
  98. alertify.confirm("Confirm dialog with custom button labels", function (e) {
  99. if (e) {
  100. alertify.success("You've clicked OK");
  101. } else {
  102. alertify.error("You've clicked Cancel");
  103. }
  104. });
  105. return false;
  106. });
  107.  
  108. $("#focus").on( 'click', function () {
  109. reset();
  110. alertify.set({ buttonFocus: "cancel" });
  111. alertify.confirm("Confirm dialog with cancel button focused", function (e) {
  112. if (e) {
  113. alertify.success("You've clicked OK");
  114. } else {
  115. alertify.error("You've clicked Cancel");
  116. }
  117. });
  118. return false;
  119. });
  120.  
  121. $("#order").on( 'click', function () {
  122. reset();
  123. alertify.set({ buttonReverse: true });
  124. alertify.confirm("Confirm dialog with reversed button order", function (e) {
  125. if (e) {
  126. alertify.success("You've clicked OK");
  127. } else {
  128. alertify.error("You've clicked Cancel");
  129. }
  130. });
  131. return false;
  132. });
  133.  
  134. // ==============================
  135. // Custom Log
  136. $("#custom").on( 'click', function () {
  137. reset();
  138. alertify.custom = alertify.extend("custom");
  139. alertify.custom("I'm a custom log message");
  140. return false;
  141. });
  142.  
  143. // ==============================
  144. // Custom Themes
  145. $("#bootstrap").on( 'click', function () {
  146. reset();
  147. $("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
  148. alertify.prompt("Prompt dialog with bootstrap theme", function (e) {
  149. if (e) {
  150. alertify.success("You've clicked OK");
  151. } else {
  152. alertify.error("You've clicked Cancel");
  153. }
  154. }, "Default Value");
  155. return false;
  156. });
  157. </script>

Writing the HTML code

  1. <table border="1px" cellpadding="10">
  2. </tr>
  3. <th colspan="2">Alert Dialogs and Logs</th>
  4. </tr>
  5. <tr>
  6. <th>Dialogs</th>
  7. <th>Logs</th>
  8. <tr>
  9. </thead>
  10. <tr>
  11. <td><a href="#" id="alert">Alert Dialog</a></td>
  12. <td><a href="#" id="notification">Standard Log</a></td>
  13. </tr>
  14. <tr>
  15. <td><a href="#" id="confirm">Confirm Dialog</a></td>
  16. <td><a href="#" id="success">Success Log</a></td>
  17. </tr>
  18. <tr>
  19. <td><a href="#" id="prompt">Prompt Dialog</a></td>
  20. <td><a href="#" id="error">Error Log</a></td>
  21. </tr>
  22. <tr>
  23. <td><a href="#" id="labels">Custom Labels</a></td>
  24. <td><a href="#" id="custom">Custom Log</a></td>
  25. </tr>
  26. <tr>
  27. <td><a href="#" id="focus">Button Focus</a></td>
  28. <td><a href="#" id="delay">Hide in 10 seconds</a></td>
  29. </tr>
  30. <tr>
  31. <td><a href="#" id="order">Button Order</a></td>
  32. <td><a href="#" id="forever">Persistent Log</a></td>
  33. </tr>
  34. </tr>
  35. <th colspan="2">Ajax</th>
  36. </tr>
  37. </tr>
  38. <td colspan="2" style="text-align: center;"><a href="#" id="ajax">Ajax - Multiple Dialog</a></td>
  39. </tr>
  40. </tbody>
  41. </table>

Whole Source Code

  1. <!doctype html>
  2. <html lang="en">
  3. <meta charset="utf-8">
  4. <title>Alerts</title>
  5. <link rel="stylesheet" href="../themes/alertify.core.css" />
  6. <link rel="stylesheet" href="../themes/alertify.bootstrap.css" id="toggleCSS" />
  7. <meta name="viewport" content="width=device-width">
  8.  
  9. </head>
  10. <br>
  11. <br>
  12. <br>
  13. <br>
  14. <br>
  15. <br>
  16. <table border="1px" cellpadding="10">
  17. </tr>
  18. <th colspan="2">Alert Dialogs and Logs</th>
  19. </tr>
  20. <tr>
  21. <th>Dialogs</th>
  22. <th>Logs</th>
  23. <tr>
  24. </thead>
  25. <tr>
  26. <td><a href="#" id="alert">Alert Dialog</a></td>
  27. <td><a href="#" id="notification">Standard Log</a></td>
  28. </tr>
  29. <tr>
  30. <td><a href="#" id="confirm">Confirm Dialog</a></td>
  31. <td><a href="#" id="success">Success Log</a></td>
  32. </tr>
  33. <tr>
  34. <td><a href="#" id="prompt">Prompt Dialog</a></td>
  35. <td><a href="#" id="error">Error Log</a></td>
  36. </tr>
  37. <tr>
  38. <td><a href="#" id="labels">Custom Labels</a></td>
  39. <td><a href="#" id="custom">Custom Log</a></td>
  40. </tr>
  41. <tr>
  42. <td><a href="#" id="focus">Button Focus</a></td>
  43. <td><a href="#" id="delay">Hide in 10 seconds</a></td>
  44. </tr>
  45. <tr>
  46. <td><a href="#" id="order">Button Order</a></td>
  47. <td><a href="#" id="forever">Persistent Log</a></td>
  48. </tr>
  49. </tr>
  50. <th colspan="2">Ajax</th>
  51. </tr>
  52. </tr>
  53. <td colspan="2" style="text-align: center;"><a href="#" id="ajax">Ajax - Multiple Dialog</a></td>
  54. </tr>
  55. </tbody>
  56. </table>
  57. </center>
  58.  
  59.  
  60.  
  61. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  62. <script src="../lib/alertify.min.js"></script>
  63. function reset () {
  64. $("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
  65. alertify.set({
  66. labels : {
  67. ok : "OK",
  68. cancel : "Cancel"
  69. },
  70. delay : 5000,
  71. buttonReverse : false,
  72. buttonFocus : "ok"
  73. });
  74. }
  75.  
  76. // ==============================
  77. // Standard Dialogs
  78. $("#alert").on( 'click', function () {
  79. reset();
  80. alertify.alert("This is an alert dialog");
  81. return false;
  82. });
  83.  
  84. $("#confirm").on( 'click', function () {
  85. reset();
  86. alertify.confirm("This is a confirm dialog", function (e) {
  87. if (e) {
  88. alertify.success("You've clicked OK");
  89. } else {
  90. alertify.error("You've clicked Cancel");
  91. }
  92. });
  93. return false;
  94. });
  95.  
  96. $("#prompt").on( 'click', function () {
  97. reset();
  98. alertify.prompt("This is a prompt dialog", function (e, str) {
  99. if (e) {
  100. alertify.success("You've clicked OK and typed: " + str);
  101. } else {
  102. alertify.error("You've clicked Cancel");
  103. }
  104. }, "Default Value");
  105. return false;
  106. });
  107.  
  108. // ==============================
  109. // Ajax
  110. $("#ajax").on("click", function () {
  111. reset();
  112. alertify.confirm("Confirm?", function (e) {
  113. if (e) {
  114. alertify.alert("Successful AJAX after OK");
  115. } else {
  116. alertify.alert("Successful AJAX after Cancel");
  117. }
  118. });
  119. });
  120.  
  121. // ==============================
  122. // Standard Dialogs
  123. $("#notification").on( 'click', function () {
  124. reset();
  125. alertify.log("Standard log message");
  126. return false;
  127. });
  128.  
  129. $("#success").on( 'click', function () {
  130. reset();
  131. alertify.success("Success log message");
  132. return false;
  133. });
  134.  
  135. $("#error").on( 'click', function () {
  136. reset();
  137. alertify.error("Error log message");
  138. return false;
  139. });
  140.  
  141. // ==============================
  142. // Custom Properties
  143. $("#delay").on( 'click', function () {
  144. reset();
  145. alertify.set({ delay: 10000 });
  146. alertify.log("Hiding in 10 seconds");
  147. return false;
  148. });
  149.  
  150. $("#forever").on( 'click', function () {
  151. reset();
  152. alertify.log("Will stay until clicked", "", 0);
  153. return false;
  154. });
  155.  
  156. $("#labels").on( 'click', function () {
  157. reset();
  158. alertify.set({ labels: { ok: "Accept", cancel: "Deny" } });
  159. alertify.confirm("Confirm dialog with custom button labels", function (e) {
  160. if (e) {
  161. alertify.success("You've clicked OK");
  162. } else {
  163. alertify.error("You've clicked Cancel");
  164. }
  165. });
  166. return false;
  167. });
  168.  
  169. $("#focus").on( 'click', function () {
  170. reset();
  171. alertify.set({ buttonFocus: "cancel" });
  172. alertify.confirm("Confirm dialog with cancel button focused", function (e) {
  173. if (e) {
  174. alertify.success("You've clicked OK");
  175. } else {
  176. alertify.error("You've clicked Cancel");
  177. }
  178. });
  179. return false;
  180. });
  181.  
  182. $("#order").on( 'click', function () {
  183. reset();
  184. alertify.set({ buttonReverse: true });
  185. alertify.confirm("Confirm dialog with reversed button order", function (e) {
  186. if (e) {
  187. alertify.success("You've clicked OK");
  188. } else {
  189. alertify.error("You've clicked Cancel");
  190. }
  191. });
  192. return false;
  193. });
  194.  
  195. // ==============================
  196. // Custom Log
  197. $("#custom").on( 'click', function () {
  198. reset();
  199. alertify.custom = alertify.extend("custom");
  200. alertify.custom("I'm a custom log message");
  201. return false;
  202. });
  203.  
  204. // ==============================
  205. // Custom Themes
  206. $("#bootstrap").on( 'click', function () {
  207. reset();
  208. $("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
  209. alertify.prompt("Prompt dialog with bootstrap theme", function (e) {
  210. if (e) {
  211. alertify.success("You've clicked OK");
  212. } else {
  213. alertify.error("You've clicked Cancel");
  214. }
  215. }, "Default Value");
  216. return false;
  217. });
  218. </script>
  219.  
  220. </body>
  221. </html>
To try this tutorial just download and run this tutorial. If you have question, suggestion or anything, just leave comment and it's my pleasure to entertain your comments or email me at [email protected]

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment