laravel-admin.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. $.fn.editable.defaults.params = function(params) {
  2. params._editable = 1;
  3. params._method = 'PUT';
  4. return params;
  5. }
  6. ;
  7. $.fn.editable.defaults.error = function(data) {
  8. var msg = '';
  9. if (data.responseJSON.errors) {
  10. $.each(data.responseJSON.errors, function(k, v) {
  11. msg += v + "\n";
  12. });
  13. }
  14. return msg
  15. }
  16. ;
  17. toastr.options = {
  18. closeButton: true,
  19. progressBar: true,
  20. showMethod: 'slideDown',
  21. timeOut: 4000
  22. };
  23. $(document).delegate('[type=submit]', 'click', function() {
  24. if ($(this).closest('form').is('[pjax-container]')) {
  25. let isSubmited = $(this).attr('disabled') == 'disabled';
  26. $(this).addClass('disabled').attr('disabled', true);
  27. !isSubmited && $(this).closest('form[pjax-container]').submit();
  28. }
  29. });
  30. $(document).on('submit', 'form[pjax-container]', function(event) {
  31. });
  32. $(document).click(function() {
  33. $('.sidebar-form .dropdown-menu').hide();
  34. });
  35. $(function() {
  36. $('.sidebar-menu li:not(.treeview) > a').on('click', function() {
  37. var $parent = $(this).parent().addClass('active');
  38. $parent.siblings('.treeview.active').find('> a').trigger('click');
  39. $parent.siblings().removeClass('active').find('li').removeClass('active');
  40. });
  41. var menu = $('.sidebar-menu li > a[href$="' + (location.pathname + location.search + location.hash) + '"]').parent().addClass('active');
  42. menu.parents('ul.treeview-menu').addClass('menu-open');
  43. menu.parents('li.treeview').addClass('active');
  44. $.AdminLTE.layout.fix();
  45. $('[data-toggle="popover"]').popover();
  46. $('.sidebar-form .autocomplete').on('keyup focus', function() {
  47. var $menu = $('.sidebar-form .dropdown-menu');
  48. var text = $(this).val();
  49. if (text === '') {
  50. $menu.hide();
  51. return;
  52. }
  53. var regex = new RegExp(text,'i');
  54. var matched = false;
  55. $menu.find('li').each(function() {
  56. if (!regex.test($(this).find('a').text())) {
  57. $(this).hide();
  58. } else {
  59. $(this).show();
  60. matched = true;
  61. }
  62. });
  63. if (matched) {
  64. $menu.show();
  65. }
  66. }).click(function(event) {
  67. event.stopPropagation();
  68. });
  69. $('.sidebar-form .dropdown-menu li a').click(function() {
  70. $('.sidebar-form .autocomplete').val($(this).text());
  71. });
  72. });
  73. $(window).scroll(function() {
  74. if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
  75. $('#totop').fadeIn(500);
  76. } else {
  77. $('#totop').fadeOut(500);
  78. }
  79. });
  80. $('#totop').on('click', function(e) {
  81. e.preventDefault();
  82. $('html,body').animate({
  83. scrollTop: 0
  84. }, 500);
  85. });
  86. (function($) {
  87. var Grid = function() {
  88. this.selects = {};
  89. };
  90. Grid.prototype.select = function(id) {
  91. this.selects[id] = id;
  92. }
  93. ;
  94. Grid.prototype.unselect = function(id) {
  95. delete this.selects[id];
  96. }
  97. ;
  98. Grid.prototype.selected = function() {
  99. var rows = [];
  100. $.each(this.selects, function(key, val) {
  101. rows.push(key);
  102. });
  103. return rows;
  104. }
  105. ;
  106. ;
  107. $.admin.redirect = function(url) {
  108. $.admin.grid = new Grid();
  109. }
  110. ;
  111. $.admin.getToken = function() {
  112. return $('meta[name="csrf-token"]').attr('content');
  113. }
  114. ;
  115. $.admin.loadedScripts = [];
  116. $.admin.loadScripts = function(arr) {
  117. var _arr = $.map(arr, function(src) {
  118. if ($.inArray(src, $.admin.loadedScripts)) {
  119. return;
  120. }
  121. $.admin.loadedScripts.push(src);
  122. return $.getScript(src);
  123. });
  124. _arr.push($.Deferred(function(deferred) {
  125. $(deferred.resolve);
  126. }));
  127. return $.when.apply($, _arr);
  128. }
  129. }
  130. )(jQuery);