sidebar_components.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* ------------------------------------------------------------------------------
  2. *
  3. * # Sidebar components
  4. *
  5. * Demo JS code for sidebar_components.html page
  6. *
  7. * ---------------------------------------------------------------------------- */
  8. // Setup module
  9. // ------------------------------
  10. var SidebarComponents = function () {
  11. //
  12. // Setup module components
  13. //
  14. // Uniform
  15. var _componentUniform = function() {
  16. if (!$().uniform) {
  17. console.warn('Warning - uniform.min.js is not loaded.');
  18. return;
  19. }
  20. // Checkboxes, radios
  21. $('.form-input-styled').uniform({
  22. fileButtonClass: 'action btn btn-icon bg-warning',
  23. fileButtonHtml: '<i class="icon-plus2"></i>'
  24. });
  25. };
  26. // Switchery
  27. var _componentSwitchery = function() {
  28. if (typeof Switchery == 'undefined') {
  29. console.warn('Warning - switchery.min.js is not loaded.');
  30. return;
  31. }
  32. // Multiple switchery toggles
  33. var elems = Array.prototype.slice.call(document.querySelectorAll('.form-input-switchery'));
  34. elems.forEach(function(html) {
  35. var switchery = new Switchery(html);
  36. });
  37. };
  38. // Select2
  39. var _componentSelect2 = function() {
  40. if (!$().select2) {
  41. console.warn('Warning - select2.min.js is not loaded.');
  42. return;
  43. }
  44. // Initialize
  45. $('.form-control-select2').select2({
  46. minimumResultsForSearch: Infinity
  47. });
  48. };
  49. // Multiselect
  50. var _componentMultiselect = function() {
  51. if (!$().multiselect) {
  52. console.warn('Warning - bootstrap-multiselect.js is not loaded.');
  53. return;
  54. }
  55. // Initialize
  56. $('.form-control-multiselect').multiselect();
  57. };
  58. // Color picker
  59. var _componentColorPicker = function() {
  60. if (!$().spectrum) {
  61. console.warn('Warning - spectrum.js is not loaded.');
  62. return;
  63. }
  64. // Initialize
  65. $('.colorpicker-flat-full').spectrum({
  66. flat: true,
  67. showInitial: true,
  68. showButtons: false,
  69. showInput: true,
  70. showAlpha: true,
  71. allowEmpty: true
  72. });
  73. };
  74. // Daterange picker
  75. var _componentDaterange = function() {
  76. if (!$().daterangepicker) {
  77. console.warn('Warning - daterangepicker.js is not loaded.');
  78. return;
  79. }
  80. // Initialize
  81. $('#reportrange').daterangepicker(
  82. {
  83. startDate: moment().subtract(29, 'days'),
  84. endDate: moment(),
  85. minDate: '01/01/2016',
  86. maxDate: '12/31/2019',
  87. dateLimit: { days: 60 },
  88. ranges: {
  89. 'Today': [moment(), moment()],
  90. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  91. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  92. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  93. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  94. },
  95. opens: $('html').attr('dir') == 'rtl' ? 'left' : 'right',
  96. buttonClasses: ['btn'],
  97. applyClass: 'btn-small btn-info btn-block',
  98. cancelClass: 'btn-small btn-light btn-block',
  99. locale: {
  100. applyLabel: 'Submit',
  101. fromLabel: 'From',
  102. toLabel: 'To',
  103. customRangeLabel: 'Custom Range',
  104. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
  105. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  106. firstDay: 1,
  107. direction: $('html').attr('dir') == 'rtl' ? 'rtl' : 'ltr'
  108. }
  109. },
  110. function(start, end) {
  111. $('#reportrange .daterange-custom-display').html(start.format('<i>D</i> <b><i>MMM</i> <i>YYYY</i></b>') + '<em> &#8211; </em>' + end.format('<i>D</i> <b><i>MMM</i> <i>YYYY</i></b>'));
  112. }
  113. );
  114. // Custom date display layout
  115. $('#reportrange .daterange-custom-display').html(moment().subtract(29, 'days').format('<i>D</i> <b><i>MMM</i> <i>YYYY</i></b>') + '<em> &#8211; </em>' + moment().format('<i>D</i> <b><i>MMM</i> <i>YYYY</i></b>'));
  116. };
  117. // jQuery UI components
  118. var _componentsJqueryUI = function() {
  119. if (!$().datepicker || !$().slider || !$().sortable) {
  120. console.warn('Warning - jQuery UI components are not loaded.');
  121. return;
  122. }
  123. // Date picker
  124. $('.datepicker').datepicker();
  125. //
  126. // Sliders
  127. //
  128. // Range slider
  129. $('.ui-slider-range').slider({
  130. range: true,
  131. min: 0,
  132. max: 60,
  133. values: [ 10, 50 ]
  134. });
  135. //
  136. // Add pips to horizontal slider
  137. //
  138. // First we need a slider to work with
  139. $('.ui-slider-labels').slider({
  140. max: 9,
  141. range: true,
  142. values: [ 2, 7 ]
  143. });
  144. // And then we can apply pips to it!
  145. $('.ui-slider-labels').slider('pips' , {
  146. rest: 'labels'
  147. });
  148. $('.ui-slider-labels').slider('float');
  149. //
  150. // Add pips to vertical slider
  151. //
  152. // Add options
  153. $('.ui-slider-vertical-pips > span').each(function() {
  154. // Read initial values from markup and remove that
  155. var value = parseInt($(this).text());
  156. $(this).empty().slider({
  157. min: 0,
  158. max: 9,
  159. value: value,
  160. animate: true,
  161. range: 'min',
  162. orientation: 'vertical'
  163. });
  164. });
  165. // Add pips
  166. $('.ui-slider-vertical-pips > span').slider('pips');
  167. //
  168. // Sortable
  169. //
  170. $('.sortable').sortable({
  171. connectWith: '.sortable',
  172. items: '.card',
  173. helper: 'original',
  174. cursor: 'move',
  175. handle: '[data-action=move]',
  176. revert: 100,
  177. containment: '.sidebar-secondary',
  178. forceHelperSize: true,
  179. placeholder: 'sortable-placeholder',
  180. forcePlaceholderSize: true,
  181. tolerance: 'pointer',
  182. start: function(e, ui){
  183. ui.placeholder.height(ui.item.outerHeight());
  184. }
  185. });
  186. };
  187. // Dual listbox
  188. var _componentDualListbox = function() {
  189. if (!$().bootstrapDualListbox) {
  190. console.warn('Warning - duallistbox.min.js is not loaded.');
  191. return;
  192. }
  193. // Initialize
  194. $('.form-control-listbox').bootstrapDualListbox({
  195. preserveSelectionOnMove: 'moved',
  196. moveOnSelect: false
  197. });
  198. };
  199. // Fancytree
  200. var _componentFancytree = function() {
  201. if (!$().fancytree) {
  202. console.warn('Warning - fancytree_all.min.js is not loaded.');
  203. return;
  204. }
  205. // Initialize
  206. $('.tree-default').fancytree();
  207. };
  208. // Lightbox
  209. var _componentFancybox = function() {
  210. if (!$().fancybox) {
  211. console.warn('Warning - fancybox.min.js is not loaded.');
  212. return;
  213. }
  214. // Image lightbox
  215. $('[data-popup="lightbox"]').fancybox({
  216. padding: 3
  217. });
  218. };
  219. //
  220. // Return objects assigned to module
  221. //
  222. return {
  223. initComponents: function() {
  224. _componentUniform();
  225. _componentSwitchery();
  226. _componentSelect2();
  227. _componentMultiselect();
  228. _componentColorPicker();
  229. _componentDaterange();
  230. _componentsJqueryUI();
  231. _componentDualListbox();
  232. _componentFancytree();
  233. _componentFancybox();
  234. }
  235. }
  236. }();
  237. // Initialize module
  238. // ------------------------------
  239. document.addEventListener('DOMContentLoaded', function() {
  240. SidebarComponents.initComponents();
  241. });