PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/public/js/core/demo/DemoUIMessages.js

https://gitlab.com/Nadiannisaqilah/bekod
JavaScript | 210 lines | 150 code | 32 blank | 28 comment | 0 complexity | 05b49d785e260380bcc5e3ca9e2b5f42 MD5 | raw file
  1. (function (namespace, $) {
  2. "use strict";
  3. var DemoUIMessages = function () {
  4. // Create reference to this instance
  5. var o = this;
  6. // Initialize app when document is ready
  7. $(document).ready(function () {
  8. o.initialize();
  9. });
  10. };
  11. var p = DemoUIMessages.prototype;
  12. // =========================================================================
  13. // MEMBER
  14. // =========================================================================
  15. p.messageTimer = null;
  16. // =========================================================================
  17. // INIT
  18. // =========================================================================
  19. p.initialize = function () {
  20. this._initToastr();
  21. $('#toast-info').trigger('click');
  22. };
  23. // =========================================================================
  24. // INIT TOASTR
  25. // =========================================================================
  26. // events
  27. p._initToastr = function () {
  28. this._initStateToastr();
  29. this._initCustomToastr();
  30. this._initPositionToastr();
  31. this._initActionToastr();
  32. };
  33. // =========================================================================
  34. // CUSTOM TOASTS
  35. // =========================================================================
  36. p._initCustomToastr = function () {
  37. var o = this;
  38. $('#toast-custom').on('click', function (e) {
  39. toastr.options.hideDuration = 0;
  40. toastr.clear();
  41. toastr.options.closeButton = ($('select[name="closeButton"]').val() === 'true');
  42. toastr.options.progressBar = ($('select[name="progressBar"]').val() === 'true');
  43. toastr.options.debug = ($('select[name="debug"]').val() === 'true');
  44. toastr.options.positionClass = $('select[name="positionClass"]').val();
  45. toastr.options.showDuration = parseInt($('select[name="showDuration"]').val());
  46. toastr.options.hideDuration = parseInt($('select[name="hideDuration"]').val());
  47. toastr.options.timeOut = parseInt($('select[name="timeOut"]').val());
  48. toastr.options.extendedTimeOut = parseInt($('select[name="extendedTimeOut"]').val());
  49. toastr.options.showEasing = $('select[name="showEasing"]').val();
  50. toastr.options.hideEasing = $('select[name="hideEasing"]').val();
  51. toastr.options.showMethod = $('select[name="showMethod"]').val();
  52. toastr.options.hideMethod = $('select[name="hideMethod"]').val();
  53. toastr[$('#state').val()]($('#message').val(), '');
  54. });
  55. };
  56. p._showCustomMessage = function () {
  57. toastr.options.closeButton = ($('select[name="closeButton"]').val() === 'true');
  58. toastr.options.progressBar = ($('select[name="progressBar"]').val() === 'true');
  59. toastr.options.debug = ($('select[name="debug"]').val() === 'true');
  60. toastr.options.positionClass = $('select[name="positionClass"]').val();
  61. toastr.options.showDuration = parseInt($('select[name="showDuration"]').val());
  62. toastr.options.hideDuration = parseInt($('select[name="hideDuration"]').val());
  63. toastr.options.timeOut = parseInt($('select[name="timeOut"]').val());
  64. toastr.options.extendedTimeOut = parseInt($('select[name="extendedTimeOut"]').val());
  65. toastr.options.showEasing = $('select[name="showEasing"]').val();
  66. toastr.options.hideEasing = $('select[name="hideEasing"]').val();
  67. toastr.options.showMethod = $('select[name="showMethod"]').val();
  68. toastr.options.hideMethod = $('select[name="hideMethod"]').val();
  69. toastr[$('#state').val()]($('#message').val(), '');
  70. };
  71. // =========================================================================
  72. // STATE TOASTS
  73. // =========================================================================
  74. p._initStateToastr = function () {
  75. var o = this;
  76. $('#toast-info').on('click', function (e) {
  77. o._toastrStateConfig();
  78. toastr.info('Welcome to the messages section', '');
  79. });
  80. $('#toast-warning').on('click', function (e) {
  81. o._toastrStateConfig();
  82. toastr.warning('This name is already added', '');
  83. });
  84. $('#toast-error').on('click', function (e) {
  85. o._toastrStateConfig();
  86. toastr.error('Duplicate item', '');
  87. });
  88. $('#toast-success').on('click', function (e) {
  89. o._toastrStateConfig();
  90. toastr.success('Added to catalog', '');
  91. });
  92. };
  93. // =========================================================================
  94. // POSITION TOASTS
  95. // =========================================================================
  96. p._initPositionToastr = function () {
  97. var o = this;
  98. $('.position-toast').on('click', function (e) {
  99. toastr.options.hideDuration = 0;
  100. toastr.clear();
  101. o._toastrStateConfig();
  102. toastr.options.timeOut = 0;
  103. toastr.options.positionClass = $(e.currentTarget).data('position');
  104. toastr.info('Position message', '');
  105. });
  106. };
  107. // =========================================================================
  108. // ACTION TOASTS
  109. // =========================================================================
  110. p._initActionToastr = function () {
  111. var o = this;
  112. $('#toast-info-progress').on('click', function (e) {
  113. toastr.clear();
  114. o._toastrStateConfig();
  115. toastr.options.progressBar = true;
  116. toastr.info('Message with a progressbar', '');
  117. });
  118. $('#toast-info-close').on('click', function (e) {
  119. toastr.clear();
  120. o._toastrStateConfig();
  121. toastr.options.closeButton = true;
  122. toastr.info('Message with a close button', '');
  123. });
  124. $('#toast-action').on('click', function (e) {
  125. toastr.clear();
  126. toastr.options.closeButton = false;
  127. toastr.options.progressBar = false;
  128. toastr.options.debug = false;
  129. toastr.options.positionClass = 'toast-bottom-left';
  130. toastr.options.showDuration = 333;
  131. toastr.options.hideDuration = 333;
  132. toastr.options.timeOut = 0;
  133. toastr.options.extendedTimeOut = 1000;
  134. toastr.options.showEasing = 'swing';
  135. toastr.options.hideEasing = 'swing';
  136. toastr.options.showMethod = 'slideDown';
  137. toastr.options.hideMethod = 'slideUp';
  138. var message = 'Marked as read. <button type="button" id="okBtn" class="btn btn-flat btn-success toastr-action">Undo</button>';
  139. toastr.info(message, '');
  140. });
  141. $('#toast-long-action').on('click', function (e) {
  142. toastr.clear();
  143. toastr.options.closeButton = false;
  144. toastr.options.progressBar = false;
  145. toastr.options.debug = false;
  146. toastr.options.positionClass = 'toast-bottom-left';
  147. toastr.options.showDuration = 333;
  148. toastr.options.hideDuration = 333;
  149. toastr.options.timeOut = 0;
  150. toastr.options.extendedTimeOut = 1000;
  151. toastr.options.showEasing = 'swing';
  152. toastr.options.hideEasing = 'swing';
  153. toastr.options.showMethod = 'slideDown';
  154. toastr.options.hideMethod = 'slideUp';
  155. var message = 'Connection timed out due to firewall setup. Showing limited. <button type="button" id="okBtn" class="btn btn-flat btn-warning toastr-action">Retry</button>';
  156. toastr.info(message, '');
  157. });
  158. };
  159. // =========================================================================
  160. // TOAST CONFIG
  161. // =========================================================================
  162. p._toastrStateConfig = function () {
  163. toastr.options.closeButton = false;
  164. toastr.options.progressBar = false;
  165. toastr.options.debug = false;
  166. toastr.options.positionClass = 'toast-bottom-left';
  167. toastr.options.showDuration = 333;
  168. toastr.options.hideDuration = 333;
  169. toastr.options.timeOut = 4000;
  170. toastr.options.extendedTimeOut = 4000;
  171. toastr.options.showEasing = 'swing';
  172. toastr.options.hideEasing = 'swing';
  173. toastr.options.showMethod = 'slideDown';
  174. toastr.options.hideMethod = 'slideUp';
  175. };
  176. // =========================================================================
  177. namespace.DemoUIMessages = new DemoUIMessages;
  178. }(this.materialadmin, jQuery)); // pass in (namespace, jQuery):