PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/app/webroot/assets/build/js/custom.js

https://gitlab.com/iamak/ticketapp-cakephp
JavaScript | 297 lines | 212 code | 43 blank | 42 comment | 26 complexity | c1fa60aa5a3016fa6c165d8ce698328a MD5 | raw file
  1. /**
  2. * Resize function without multiple trigger
  3. *
  4. * Usage:
  5. * $(window).smartresize(function(){
  6. * // code here
  7. * });
  8. */
  9. (function($, sr) {
  10. // debouncing function from John Hann
  11. // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
  12. var debounce = function(func, threshold, execAsap) {
  13. var timeout;
  14. return function debounced() {
  15. var obj = this,
  16. args = arguments;
  17. function delayed() {
  18. if (!execAsap)
  19. func.apply(obj, args);
  20. timeout = null;
  21. }
  22. if (timeout)
  23. clearTimeout(timeout);
  24. else if (execAsap)
  25. func.apply(obj, args);
  26. timeout = setTimeout(delayed, threshold || 100);
  27. };
  28. };
  29. // smartresize
  30. jQuery.fn[sr] = function(fn) {
  31. return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
  32. };
  33. })(jQuery, 'smartresize');
  34. /**
  35. * To change this license header, choose License Headers in Project Properties.
  36. * To change this template file, choose Tools | Templates
  37. * and open the template in the editor.
  38. */
  39. var CURRENT_URL = window.location.href.split('#')[0].split('?')[0],
  40. $BODY = $('body'),
  41. $MENU_TOGGLE = $('#menu_toggle'),
  42. $SIDEBAR_MENU = $('#sidebar-menu'),
  43. $SIDEBAR_FOOTER = $('.sidebar-footer'),
  44. $LEFT_COL = $('.left_col'),
  45. $RIGHT_COL = $('.right_col'),
  46. $NAV_MENU = $('.nav_menu'),
  47. $FOOTER = $('footer');
  48. // Sidebar
  49. $(document).ready(function() {
  50. // TODO: This is some kind of easy fix, maybe we can improve this
  51. var setContentHeight = function() {
  52. // reset height
  53. $RIGHT_COL.css('min-height', $(window).height());
  54. var bodyHeight = $BODY.outerHeight(),
  55. footerHeight = $BODY.hasClass('footer_fixed') ? -10 : $FOOTER.height(),
  56. leftColHeight = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height(),
  57. contentHeight = bodyHeight < leftColHeight ? leftColHeight : bodyHeight;
  58. // normalize content
  59. contentHeight -= $NAV_MENU.height() + footerHeight;
  60. $RIGHT_COL.css('min-height', contentHeight);
  61. };
  62. $SIDEBAR_MENU.find('a').on('click', function(ev) {
  63. var $li = $(this).parent();
  64. if ($li.is('.active')) {
  65. $li.removeClass('active active-sm');
  66. $('ul:first', $li).slideUp(function() {
  67. setContentHeight();
  68. });
  69. } else {
  70. // prevent closing menu if we are on child menu
  71. if (!$li.parent().is('.child_menu')) {
  72. $SIDEBAR_MENU.find('li').removeClass('active active-sm');
  73. $SIDEBAR_MENU.find('li ul').slideUp();
  74. }
  75. $li.addClass('active');
  76. $('ul:first', $li).slideDown(function() {
  77. setContentHeight();
  78. });
  79. }
  80. });
  81. // toggle small or large menu
  82. $MENU_TOGGLE.on('click', function() {
  83. if ($BODY.hasClass('nav-md')) {
  84. $SIDEBAR_MENU.find('li.active ul').hide();
  85. $SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
  86. } else {
  87. $SIDEBAR_MENU.find('li.active-sm ul').show();
  88. $SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
  89. }
  90. $BODY.toggleClass('nav-md nav-sm');
  91. setContentHeight();
  92. });
  93. // check active menu
  94. $SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page');
  95. $SIDEBAR_MENU.find('a').filter(function() {
  96. return this.href == CURRENT_URL;
  97. }).parent('li').addClass('current-page').parents('ul').slideDown(function() {
  98. setContentHeight();
  99. }).parent().addClass('active');
  100. // recompute content when resizing
  101. $(window).smartresize(function() {
  102. setContentHeight();
  103. });
  104. setContentHeight();
  105. // fixed sidebar
  106. if ($.fn.mCustomScrollbar) {
  107. $('.menu_fixed').mCustomScrollbar({
  108. autoHideScrollbar: true,
  109. theme: 'minimal',
  110. mouseWheel: { preventDefault: true }
  111. });
  112. }
  113. });
  114. // /Sidebar
  115. // Panel toolbox
  116. $(document).ready(function() {
  117. $('.collapse-link').on('click', function() {
  118. var $BOX_PANEL = $(this).closest('.x_panel'),
  119. $ICON = $(this).find('i'),
  120. $BOX_CONTENT = $BOX_PANEL.find('.x_content');
  121. // fix for some div with hardcoded fix class
  122. if ($BOX_PANEL.attr('style')) {
  123. $BOX_CONTENT.slideToggle(200, function() {
  124. $BOX_PANEL.removeAttr('style');
  125. });
  126. } else {
  127. $BOX_CONTENT.slideToggle(200);
  128. $BOX_PANEL.css('height', 'auto');
  129. }
  130. $ICON.toggleClass('fa-chevron-up fa-chevron-down');
  131. });
  132. $('.close-link').click(function() {
  133. var $BOX_PANEL = $(this).closest('.x_panel');
  134. $BOX_PANEL.remove();
  135. });
  136. });
  137. // /Panel toolbox
  138. // Tooltip
  139. $(document).ready(function() {
  140. $('[data-toggle="tooltip"]').tooltip({
  141. container: 'body'
  142. });
  143. });
  144. // /Tooltip
  145. // Progressbar
  146. if ($(".progress .progress-bar")[0]) {
  147. $('.progress .progress-bar').progressbar();
  148. }
  149. // /Progressbar
  150. // Switchery
  151. $(document).ready(function() {
  152. if ($(".js-switch")[0]) {
  153. var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
  154. elems.forEach(function(html) {
  155. var switchery = new Switchery(html, {
  156. color: '#26B99A'
  157. });
  158. });
  159. }
  160. });
  161. // /Switchery
  162. // iCheck
  163. $(document).ready(function() {
  164. if ($("input.flat")[0]) {
  165. $(document).ready(function() {
  166. $('input.flat').iCheck({
  167. checkboxClass: 'icheckbox_flat-green',
  168. radioClass: 'iradio_flat-green'
  169. });
  170. });
  171. }
  172. });
  173. // /iCheck
  174. // Table
  175. $('table input').on('ifChecked', function() {
  176. checkState = '';
  177. $(this).parent().parent().parent().addClass('selected');
  178. countChecked();
  179. });
  180. $('table input').on('ifUnchecked', function() {
  181. checkState = '';
  182. $(this).parent().parent().parent().removeClass('selected');
  183. countChecked();
  184. });
  185. var checkState = '';
  186. $('.bulk_action input').on('ifChecked', function() {
  187. checkState = '';
  188. $(this).parent().parent().parent().addClass('selected');
  189. countChecked();
  190. });
  191. $('.bulk_action input').on('ifUnchecked', function() {
  192. checkState = '';
  193. $(this).parent().parent().parent().removeClass('selected');
  194. countChecked();
  195. });
  196. $('.bulk_action input#check-all').on('ifChecked', function() {
  197. checkState = 'all';
  198. countChecked();
  199. });
  200. $('.bulk_action input#check-all').on('ifUnchecked', function() {
  201. checkState = 'none';
  202. countChecked();
  203. });
  204. function countChecked() {
  205. if (checkState === 'all') {
  206. $(".bulk_action input[name='table_records']").iCheck('check');
  207. }
  208. if (checkState === 'none') {
  209. $(".bulk_action input[name='table_records']").iCheck('uncheck');
  210. }
  211. var checkCount = $(".bulk_action input[name='table_records']:checked").length;
  212. if (checkCount) {
  213. $('.column-title').hide();
  214. $('.bulk-actions').show();
  215. $('.action-cnt').html(checkCount + ' Records Selected');
  216. } else {
  217. $('.column-title').show();
  218. $('.bulk-actions').hide();
  219. }
  220. }
  221. // Accordion
  222. $(document).ready(function() {
  223. $(".expand").on("click", function() {
  224. $(this).next().slideToggle(200);
  225. $expand = $(this).find(">:first-child");
  226. if ($expand.text() == "+") {
  227. $expand.text("-");
  228. } else {
  229. $expand.text("+");
  230. }
  231. });
  232. });
  233. // Select2
  234. $(document).ready(function() {
  235. $(".select2_single").select2({
  236. placeholder: "Please Select",
  237. allowClear: true
  238. });
  239. $(".select2_group").select2({});
  240. $(".select2_multiple").select2({
  241. //maximumSelectionLength: 4,
  242. placeholder: "Please select",
  243. allowClear: true,
  244. });
  245. });
  246. // NProgress
  247. if (typeof NProgress != 'undefined') {
  248. $(document).ready(function() {
  249. NProgress.start();
  250. });
  251. $(window).load(function() {
  252. NProgress.done();
  253. });
  254. }