navbar_components.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Navbar components
  4. *
  5. * Demo JS code for navbar_component.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var NavbarComponents = function() {
  11. //
  12. // Setup module components
  13. //
  14. // Select2
  15. var _componentSelect2 = function() {
  16. if (!$().select2) {
  17. console.warn('Warning - select2.min.js is not loaded.');
  18. return;
  19. }
  20. // Initialize
  21. $('.form-control-select2').select2({
  22. minimumResultsForSearch: Infinity
  23. });
  24. };
  25. // Daterange pickers
  26. var _componentDaterange = function() {
  27. if (!$().daterangepicker) {
  28. console.warn('Warning - daterangepicker.js is not loaded.');
  29. return;
  30. }
  31. //
  32. // Custom display
  33. //
  34. // Initialize
  35. $('.daterange-ranges-button').daterangepicker(
  36. {
  37. startDate: moment().subtract(29, 'days'),
  38. endDate: moment(),
  39. minDate: '01/01/2014',
  40. maxDate: '12/31/2018',
  41. dateLimit: {
  42. days: 60
  43. },
  44. ranges: {
  45. 'Today': [moment(), moment()],
  46. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  47. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  48. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  49. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  50. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  51. },
  52. opens: $('html').attr('dir') == 'rtl' ? 'right' : 'left',
  53. applyClass: 'btn-small btn-primary btn-block',
  54. cancelClass: 'btn-small btn-light btn-block',
  55. locale: {
  56. format: 'MM/DD/YYYY',
  57. direction: $('html').attr('dir') == 'rtl' ? 'rtl' : 'ltr'
  58. }
  59. },
  60. function(start, end) {
  61. $('.daterange-ranges-button span').html(start.format('MMM D, YY') + ' - ' + end.format('MMM D, YY'));
  62. }
  63. );
  64. // Format results
  65. $('.daterange-ranges-button span').html(moment().subtract(29, 'days').format('MMM D, YY') + ' - ' + moment().format('MMM D, YY'));
  66. //
  67. // Attached to button
  68. //
  69. // Initialize
  70. $('.daterange-ranges').daterangepicker(
  71. {
  72. startDate: moment().subtract(29, 'days'),
  73. endDate: moment(),
  74. minDate: '01/01/2014',
  75. maxDate: '12/31/2018',
  76. dateLimit: { days: 60 },
  77. ranges: {
  78. 'Today': [moment(), moment()],
  79. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  80. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  81. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  82. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  83. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  84. },
  85. opens: $('html').attr('dir') == 'rtl' ? 'left' : 'right',
  86. applyClass: 'btn-small btn-primary btn-block',
  87. cancelClass: 'btn-small btn-light btn-block',
  88. locale: {
  89. format: 'MM/DD/YYYY',
  90. direction: $('html').attr('dir') == 'rtl' ? 'rtl' : 'ltr'
  91. }
  92. },
  93. function(start, end) {
  94. $('.daterange-ranges span').html(start.format('MMM D, YY') + ' - ' + end.format('MMM D, YY'));
  95. }
  96. );
  97. // Format results
  98. $('.daterange-ranges span').html(moment().subtract(29, 'days').format('MMM D, YY') + ' - ' + moment().format('MMM D, YY'));
  99. };
  100. // Switchery
  101. var _componentSwitchery = function() {
  102. if (typeof Switchery == 'undefined') {
  103. console.warn('Warning - switchery.min.js is not loaded.');
  104. return;
  105. }
  106. // Initialize multiple switches
  107. var elems = Array.prototype.slice.call(document.querySelectorAll('.form-input-switchery'));
  108. elems.forEach(function(html) {
  109. var switchery = new Switchery(html, {color: '#006064', secondaryColor: '#fff'});
  110. });
  111. };
  112. // Multiselect
  113. var _componentMultiselect = function() {
  114. if (!$().multiselect) {
  115. console.warn('Warning - select2.min.js is not loaded.');
  116. return;
  117. }
  118. // Initialize
  119. $('.form-control-multiselect').multiselect();
  120. // Material theme example
  121. $('.form-control-multiselect-material').multiselect({
  122. buttonClass: 'btn btn-light text-white'
  123. });
  124. };
  125. // Uniform
  126. var _componentUniform = function() {
  127. if (!$().uniform) {
  128. console.warn('Warning - uniform.min.js is not loaded.');
  129. return;
  130. }
  131. // Initialize
  132. $('.form-input-styled').uniform({
  133. fileButtonClass: 'action btn btn-icon btn-light',
  134. fileButtonHtml: '<i class="icon-plus2"></i>'
  135. });
  136. // Material theme example
  137. $('.form-input-styled-material').uniform({
  138. selectClass: 'uniform-select text-white',
  139. fileButtonClass: 'action btn btn-icon bg-white text-default',
  140. fileButtonHtml: '<i class="icon-plus2"></i>'
  141. });
  142. };
  143. //
  144. // Return objects assigned to module
  145. //
  146. return {
  147. init: function() {
  148. _componentSelect2();
  149. _componentDaterange();
  150. _componentSwitchery();
  151. _componentMultiselect();
  152. _componentUniform();
  153. }
  154. }
  155. }();
  156. // Initialize module
  157. // ------------------------------
  158. document.addEventListener('DOMContentLoaded', function() {
  159. NavbarComponents.init();
  160. });