components_popups.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Tooltips and popovers
  4. *
  5. * Demo JS code for components_popups.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var Popups = function () {
  11. //
  12. // Setup module components
  13. //
  14. // Custom tooltip color
  15. var _componentTooltipCustomColor = function() {
  16. $('[data-popup=tooltip-custom]').tooltip({
  17. template: '<div class="tooltip"><div class="arrow border-teal"></div><div class="tooltip-inner bg-teal"></div></div>'
  18. });
  19. };
  20. // Tooltip events
  21. var _componentTooltipEvents = function() {
  22. // onShow event
  23. $('#tooltip-show').tooltip({
  24. title: 'I am a tooltip',
  25. trigger: 'click'
  26. }).on('show.bs.tooltip', function() {
  27. alert('Show event fired.');
  28. });
  29. // onShown event
  30. $('#tooltip-shown').tooltip({
  31. title: 'I am a tooltip',
  32. trigger: 'click'
  33. }).on('shown.bs.tooltip', function() {
  34. alert('Shown event fired.');
  35. });
  36. // onHide event
  37. $('#tooltip-hide').tooltip({
  38. title: 'I am a tooltip',
  39. trigger: 'click'
  40. }).on('hide.bs.tooltip', function() {
  41. alert('Hide event fired.');
  42. });
  43. // onHidden event
  44. $('#tooltip-hidden').tooltip({
  45. title: 'I am a tooltip',
  46. trigger: 'click'
  47. }).on('hidden.bs.tooltip', function() {
  48. alert('Hidden event fired.');
  49. });
  50. };
  51. // Tooltip methods
  52. var _componentTooltipMethods = function() {
  53. // Show method
  54. $('#show-tooltip-method').on('click', function() {
  55. $('#show-tooltip-method-target').tooltip('show');
  56. });
  57. // Hide method
  58. $('#hide-tooltip-method-target').on('mouseenter', function() {
  59. $(this).tooltip('show')
  60. });
  61. $('#hide-tooltip-method').on('click', function() {
  62. $('#hide-tooltip-method-target').tooltip('hide');
  63. });
  64. // Toggle method
  65. $('#toggle-tooltip-method').on('click', function() {
  66. $('#toggle-tooltip-method-target').tooltip('toggle');
  67. })
  68. // Dispose method
  69. $('#dispose-tooltip-method').on('click', function() {
  70. $('#dispose-tooltip-method-target').tooltip('dispose');
  71. });
  72. // Toggle enable method
  73. $('#toggle-enabled-tooltip-method').on('click', function() {
  74. $('#toggle-enabled-tooltip-method-target').tooltip('toggleEnabled');
  75. });
  76. };
  77. // Custom popover color
  78. var _componentPopoverCustomHeaderColor = function() {
  79. $('[data-popup=popover-custom]').popover({
  80. template: '<div class="popover border-teal"><div class="arrow"></div><h3 class="popover-header bg-teal"></h3><div class="popover-body"></div></div>'
  81. });
  82. };
  83. // Custom popover background color
  84. var _componentPopoverCustomBackgroundColor = function() {
  85. $('[data-popup=popover-solid]').popover({
  86. template: '<div class="popover bg-primary border-primary"><div class="arrow"></div><h3 class="popover-header"></h3><div class="popover-body text-white"></div></div>'
  87. });
  88. };
  89. // Popover events
  90. var _componentPopoverEvents = function() {
  91. // onShow event
  92. $('#popover-show').popover({
  93. title: 'Popover title',
  94. content: 'And here\'s some amazing content. It\'s very engaging. Right?',
  95. trigger: 'click'
  96. }).on('show.bs.popover', function() {
  97. alert('Show event fired.');
  98. });
  99. // onShown event
  100. $('#popover-shown').popover({
  101. title: 'Popover title',
  102. content: 'And here\'s some amazing content. It\'s very engaging. Right?',
  103. trigger: 'click'
  104. }).on('shown.bs.popover', function() {
  105. alert('Shown event fired.');
  106. });
  107. // onHide event
  108. $('#popover-hide').popover({
  109. title: 'Popover title',
  110. content: 'And here\'s some amazing content. It\'s very engaging. Right?',
  111. placement: 'top',
  112. trigger: 'click'
  113. }).on('hide.bs.popover', function() {
  114. alert('Hide event fired.');
  115. });
  116. // onHidden event
  117. $('#popover-hidden').popover({
  118. title: 'Popover title',
  119. content: 'And here\'s some amazing content. It\'s very engaging. Right?',
  120. trigger: 'click'
  121. }).on('hidden.bs.popover', function() {
  122. alert('Hidden event fired.');
  123. });
  124. };
  125. // Popover methods
  126. var _componentPopoverMethods = function() {
  127. // Show method
  128. $('#show-popover-method').on('click', function() {
  129. $('#show-popover-method-target').popover('show');
  130. })
  131. // Hide method
  132. $('#hide-popover-method-target').on('mouseenter', function() {
  133. $(this).popover('show')
  134. });
  135. $('#hide-popover-method').on('click', function() {
  136. $('#hide-popover-method-target').popover('hide');
  137. });
  138. // Toggle method
  139. $('#toggle-popover-method').on('click', function() {
  140. $('#toggle-popover-method-target').popover('toggle');
  141. })
  142. // Dispose method
  143. $('#dispose-popover-method').on('click', function() {
  144. $('#dispose-popover-method-target').popover('dispose');
  145. });
  146. // Toggle enable method
  147. $('#toggle-enabled-popover-method').on('click', function() {
  148. $('#toggle-enabled-popover-method-target').popover('toggleEnabled');
  149. });
  150. };
  151. //
  152. // Return objects assigned to module
  153. //
  154. return {
  155. init: function() {
  156. _componentTooltipCustomColor();
  157. _componentTooltipEvents();
  158. _componentTooltipMethods();
  159. _componentPopoverCustomHeaderColor();
  160. _componentPopoverCustomBackgroundColor();
  161. _componentPopoverEvents();
  162. _componentPopoverMethods();
  163. }
  164. }
  165. }();
  166. // Initialize module
  167. // ------------------------------
  168. document.addEventListener('DOMContentLoaded', function() {
  169. Popups.init();
  170. });