demo.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. define(['jquery', 'bootstrap', 'frontend', 'config'], function ($, undefined, Frontend, Config) {
  2. var Controller = {
  3. qrcode: function () {
  4. $("form").submit(function () {
  5. $("#qrcodeimg").prop("src", (Config.subdomain == "1" ? '' : '/index') + "/demo/qrcode?" + $(this).serialize());
  6. return false;
  7. });
  8. $("form").trigger('submit');
  9. },
  10. bootstrap: function () {
  11. //Popover & Tooltip
  12. $('.bs-component [data-toggle="popover"]').popover();
  13. $('.bs-component [data-toggle="tooltip"]').tooltip();
  14. //Toastr
  15. var i = -1;
  16. var toastCount = 0;
  17. var $toastlast;
  18. var getMessage = function () {
  19. var msgs = ['My name is Inigo Montoya. You killed my father. Prepare to die!',
  20. '<div><input class="input-small" value="textbox"/>&nbsp;<a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="surpriseBtn" class="btn" style="margin: 0 8px 0 8px">Surprise me</button></div>',
  21. 'Are you the six fingered man?',
  22. 'Inconceivable!',
  23. 'I do not think that means what you think it means.',
  24. 'Have fun storming the castle!'
  25. ];
  26. i++;
  27. if (i === msgs.length) {
  28. i = 0;
  29. }
  30. return msgs[i];
  31. };
  32. $('#showtoast').click(function () {
  33. var shortCutFunction = $("#toastTypeGroup input:radio:checked").val();
  34. var msg = $('#message').val();
  35. var title = $('#title').val() || '';
  36. var $showDuration = $('#showDuration');
  37. var $hideDuration = $('#hideDuration');
  38. var $timeOut = $('#timeOut');
  39. var $extendedTimeOut = $('#extendedTimeOut');
  40. var $showEasing = $('#showEasing');
  41. var $hideEasing = $('#hideEasing');
  42. var $showMethod = $('#showMethod');
  43. var $hideMethod = $('#hideMethod');
  44. var toastIndex = toastCount++;
  45. Toastr.options = {
  46. closeButton: $('#closeButton').prop('checked'),
  47. debug: $('#debugInfo').prop('checked'),
  48. positionClass: $('#positionGroup input:radio:checked').val() || 'toast-top-right',
  49. onclick: null
  50. };
  51. if ($('#addBehaviorOnToastClick').prop('checked')) {
  52. Toastr.options.onclick = function () {
  53. alert('You can perform some custom action after a toast goes away');
  54. };
  55. }
  56. if ($showDuration.val().length) {
  57. Toastr.options.showDuration = $showDuration.val();
  58. }
  59. if ($hideDuration.val().length) {
  60. Toastr.options.hideDuration = $hideDuration.val();
  61. }
  62. if ($timeOut.val().length) {
  63. Toastr.options.timeOut = $timeOut.val();
  64. }
  65. if ($extendedTimeOut.val().length) {
  66. Toastr.options.extendedTimeOut = $extendedTimeOut.val();
  67. }
  68. if ($showEasing.val().length) {
  69. Toastr.options.showEasing = $showEasing.val();
  70. }
  71. if ($hideEasing.val().length) {
  72. Toastr.options.hideEasing = $hideEasing.val();
  73. }
  74. if ($showMethod.val().length) {
  75. Toastr.options.showMethod = $showMethod.val();
  76. }
  77. if ($hideMethod.val().length) {
  78. Toastr.options.hideMethod = $hideMethod.val();
  79. }
  80. if (!msg) {
  81. msg = getMessage();
  82. }
  83. $("#toastrOptions").text("Command: toastr["
  84. + shortCutFunction
  85. + "](\""
  86. + msg
  87. + (title ? "\", \"" + title : '')
  88. + "\")\n\nToastr.options = "
  89. + JSON.stringify(Toastr.options, null, 2)
  90. );
  91. var $toast = Toastr[shortCutFunction](msg, title); // Wire up an event handler to a button in the toast, if it exists
  92. $toastlast = $toast;
  93. if ($toast.find('#okBtn').length) {
  94. $toast.delegate('#okBtn', 'click', function () {
  95. alert('you clicked me. i was toast #' + toastIndex + '. goodbye!');
  96. $toast.remove();
  97. });
  98. }
  99. if ($toast.find('#surpriseBtn').length) {
  100. $toast.delegate('#surpriseBtn', 'click', function () {
  101. alert('Surprise! you clicked me. i was toast #' + toastIndex + '. You could perform an action here.');
  102. });
  103. }
  104. });
  105. function getLastToast() {
  106. return $toastlast;
  107. }
  108. $('#clearlasttoast').click(function () {
  109. Toastr.clear(getLastToast());
  110. });
  111. $('#cleartoasts').click(function () {
  112. Toastr.clear();
  113. });
  114. $(document).on("click", "#dialog-normal", function () {
  115. BootstrapDialog.show({
  116. title: 'Say-hello dialog',
  117. message: 'Hi Apple!'
  118. });
  119. });
  120. $(document).on("click", "#dialog-alert", function () {
  121. BootstrapDialog.alert('Hi Apple!');
  122. });
  123. $(document).on("click", "#dialog-confirm", function () {
  124. BootstrapDialog.confirm('Hi Apple, are you sure?', function (result) {
  125. if (result) {
  126. alert('Yup.');
  127. } else {
  128. alert('Nope.');
  129. }
  130. });
  131. });
  132. },
  133. };
  134. return Controller;
  135. });