custom.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /**
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. // Sidebar
  7. $(function () {
  8. var URL = window.location,
  9. $BODY = $('body'),
  10. $SIDEBAR_MENU = $('#sidebar-menu'),
  11. $MENU_TOGGLE = $('#menu_toggle');
  12. $SIDEBAR_FOOTER = $('.sidebar-footer');
  13. $LEFT_COL = $('.left_col');
  14. $SIDEBAR_MENU.find('li ul').slideUp();
  15. $SIDEBAR_MENU.find('li').removeClass('active');
  16. $SIDEBAR_MENU.find('li').on('click', function(ev) {
  17. var link = $('a', this).attr('href');
  18. // prevent event bubbling on parent menu
  19. if (link) {
  20. ev.stopPropagation();
  21. }
  22. // execute slidedown if parent menu
  23. else {
  24. if ($(this).is('.active')) {
  25. $(this).removeClass('active');
  26. $('ul', this).slideUp();
  27. } else {
  28. $SIDEBAR_MENU.find('li').removeClass('active');
  29. $SIDEBAR_MENU.find('li ul').slideUp();
  30. $(this).addClass('active');
  31. $('ul', this).slideDown();
  32. }
  33. }
  34. });
  35. $MENU_TOGGLE.on('click', function() {
  36. if ($BODY.hasClass('nav-md')) {
  37. $BODY.removeClass('nav-md').addClass('nav-sm');
  38. $LEFT_COL.removeClass('scroll-view').removeAttr('style');
  39. $SIDEBAR_FOOTER.hide();
  40. if ($SIDEBAR_MENU.find('li').hasClass('active')) {
  41. $SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
  42. }
  43. } else {
  44. $BODY.removeClass('nav-sm').addClass('nav-md');
  45. $SIDEBAR_FOOTER.show();
  46. if ($SIDEBAR_MENU.find('li').hasClass('active-sm')) {
  47. $SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
  48. }
  49. }
  50. });
  51. // check active menu
  52. $SIDEBAR_MENU.find('a[href="' + URL + '"]').parent('li').addClass('current-page');
  53. $SIDEBAR_MENU.find('a').filter(function () {
  54. return this.href == URL;
  55. }).parent('li').addClass('current-page').parent('ul').slideDown().parent().addClass('active');
  56. });
  57. // Panel toolbox
  58. $(function () {
  59. $('.collapse-link').on('click', function() {
  60. var $BOX_PANEL = $(this).closest('.x_panel'),
  61. $ICON = $(this).find('i'),
  62. $BOX_CONTENT = $BOX_PANEL.find('.x_content');
  63. // fix for some div with hardcoded fix class
  64. if ($BOX_PANEL.attr('style')) {
  65. $BOX_CONTENT.slideToggle(200, function(){
  66. $BOX_PANEL.removeAttr('style');
  67. });
  68. } else {
  69. $BOX_CONTENT.slideToggle(200);
  70. $BOX_PANEL.css('height', 'auto');
  71. }
  72. $ICON.toggleClass('fa-chevron-up fa-chevron-down');
  73. });
  74. $('.close-link').click(function () {
  75. var $BOX_PANEL = $(this).closest('.x_panel');
  76. $BOX_PANEL.remove();
  77. });
  78. });
  79. // Right column height
  80. $(".right_col").css("min-height", $(window).height());
  81. $(window).resize(function () {
  82. $(".right_col").css("min-height", $(window).height());
  83. });
  84. // Tooltip
  85. $(function () {
  86. $('[data-toggle="tooltip"]').tooltip();
  87. });
  88. // Progressbar
  89. if ($(".progress .progress-bar")[0]) {
  90. $('.progress .progress-bar').progressbar(); // bootstrap 3
  91. }
  92. // Switchery
  93. if ($(".js-switch")[0]) {
  94. var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
  95. elems.forEach(function (html) {
  96. var switchery = new Switchery(html, {
  97. color: '#26B99A'
  98. });
  99. });
  100. }
  101. // iCheck
  102. if ($("input.flat")[0]) {
  103. $(document).ready(function () {
  104. $('input.flat').iCheck({
  105. checkboxClass: 'icheckbox_flat-green',
  106. radioClass: 'iradio_flat-green'
  107. });
  108. });
  109. }
  110. // Starrr
  111. var __slice = [].slice;
  112. (function ($, window) {
  113. var Starrr;
  114. Starrr = (function () {
  115. Starrr.prototype.defaults = {
  116. rating: void 0,
  117. numStars: 5,
  118. change: function (e, value) {
  119. }
  120. };
  121. function Starrr($el, options) {
  122. var i, _, _ref,
  123. _this = this;
  124. this.options = $.extend({}, this.defaults, options);
  125. this.$el = $el;
  126. _ref = this.defaults;
  127. for (i in _ref) {
  128. _ = _ref[i];
  129. if (this.$el.data(i) !== null) {
  130. this.options[i] = this.$el.data(i);
  131. }
  132. }
  133. this.createStars();
  134. this.syncRating();
  135. this.$el.on('mouseover.starrr', 'span', function (e) {
  136. return _this.syncRating(_this.$el.find('span').index(e.currentTarget) + 1);
  137. });
  138. this.$el.on('mouseout.starrr', function () {
  139. return _this.syncRating();
  140. });
  141. this.$el.on('click.starrr', 'span', function (e) {
  142. return _this.setRating(_this.$el.find('span').index(e.currentTarget) + 1);
  143. });
  144. this.$el.on('starrr:change', this.options.change);
  145. }
  146. Starrr.prototype.createStars = function () {
  147. var _i, _ref, _results;
  148. _results = [];
  149. for (_i = 1, _ref = this.options.numStars; 1 <= _ref ? _i <= _ref : _i >= _ref; 1 <= _ref ? _i++ : _i--) {
  150. _results.push(this.$el.append("<span class='glyphicon .glyphicon-star-empty'></span>"));
  151. }
  152. return _results;
  153. };
  154. Starrr.prototype.setRating = function (rating) {
  155. if (this.options.rating === rating) {
  156. rating = void 0;
  157. }
  158. this.options.rating = rating;
  159. this.syncRating();
  160. return this.$el.trigger('starrr:change', rating);
  161. };
  162. Starrr.prototype.syncRating = function (rating) {
  163. var i, _i, _j, _ref;
  164. rating || (rating = this.options.rating);
  165. if (rating) {
  166. for (i = _i = 0, _ref = rating - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
  167. this.$el.find('span').eq(i).removeClass('glyphicon-star-empty').addClass('glyphicon-star');
  168. }
  169. }
  170. if (rating && rating < 5) {
  171. for (i = _j = rating; rating <= 4 ? _j <= 4 : _j >= 4; i = rating <= 4 ? ++_j : --_j) {
  172. this.$el.find('span').eq(i).removeClass('glyphicon-star').addClass('glyphicon-star-empty');
  173. }
  174. }
  175. if (!rating) {
  176. return this.$el.find('span').removeClass('glyphicon-star').addClass('glyphicon-star-empty');
  177. }
  178. };
  179. return Starrr;
  180. })();
  181. return $.fn.extend({
  182. starrr: function () {
  183. var args, option;
  184. option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
  185. return this.each(function () {
  186. var data;
  187. data = $(this).data('star-rating');
  188. if (!data) {
  189. $(this).data('star-rating', (data = new Starrr($(this), option)));
  190. }
  191. if (typeof option === 'string') {
  192. return data[option].apply(data, args);
  193. }
  194. });
  195. }
  196. });
  197. })(window.jQuery, window);
  198. $(function () {
  199. return $(".starrr").starrr();
  200. });
  201. $(document).ready(function () {
  202. $('#stars').on('starrr:change', function (e, value) {
  203. $('#count').html(value);
  204. });
  205. $('#stars-existing').on('starrr:change', function (e, value) {
  206. $('#count-existing').html(value);
  207. });
  208. });
  209. // Table
  210. $('table input').on('ifChecked', function () {
  211. check_state = '';
  212. $(this).parent().parent().parent().addClass('selected');
  213. countChecked();
  214. });
  215. $('table input').on('ifUnchecked', function () {
  216. check_state = '';
  217. $(this).parent().parent().parent().removeClass('selected');
  218. countChecked();
  219. });
  220. var check_state = '';
  221. $('.bulk_action input').on('ifChecked', function () {
  222. check_state = '';
  223. $(this).parent().parent().parent().addClass('selected');
  224. countChecked();
  225. });
  226. $('.bulk_action input').on('ifUnchecked', function () {
  227. check_state = '';
  228. $(this).parent().parent().parent().removeClass('selected');
  229. countChecked();
  230. });
  231. $('.bulk_action input#check-all').on('ifChecked', function () {
  232. check_state = 'check_all';
  233. countChecked();
  234. });
  235. $('.bulk_action input#check-all').on('ifUnchecked', function () {
  236. check_state = 'uncheck_all';
  237. countChecked();
  238. });
  239. function countChecked() {
  240. if (check_state == 'check_all') {
  241. $(".bulk_action input[name='table_records']").iCheck('check');
  242. }
  243. if (check_state == 'uncheck_all') {
  244. $(".bulk_action input[name='table_records']").iCheck('uncheck');
  245. }
  246. var n = $(".bulk_action input[name='table_records']:checked").length;
  247. if (n > 0) {
  248. $('.column-title').hide();
  249. $('.bulk-actions').show();
  250. $('.action-cnt').html(n + ' Records Selected');
  251. } else {
  252. $('.column-title').show();
  253. $('.bulk-actions').hide();
  254. }
  255. }
  256. // Accordion
  257. $(function () {
  258. $(".expand").on("click", function () {
  259. $(this).next().slideToggle(200);
  260. $expand = $(this).find(">:first-child");
  261. if ($expand.text() == "+") {
  262. $expand.text("-");
  263. } else {
  264. $expand.text("+");
  265. }
  266. });
  267. });
  268. // NProgress
  269. if (typeof NProgress != 'undefined') {
  270. $(document).ready(function () {
  271. NProgress.start();
  272. });
  273. $(window).load(function () {
  274. NProgress.done();
  275. });
  276. }