plugins.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Avoid `console` errors in browsers that lack a console.
  2. (function () {
  3. var method;
  4. var noop = function () {
  5. };
  6. var methods = [
  7. 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
  8. 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
  9. 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
  10. 'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
  11. ];
  12. var length = methods.length;
  13. var console = (window.console = window.console || {});
  14. while (length--) {
  15. method = methods[length];
  16. // Only stub undefined methods.
  17. if (!console[method]) {
  18. console[method] = noop;
  19. }
  20. }
  21. }());
  22. // Place any jQuery/helper plugins in here.
  23. $(function () {
  24. $.ajaxSetup({
  25. headers: {
  26. 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
  27. }
  28. });
  29. /*
  30. Allows you to add data-method="METHOD to links to automatically inject a form with the method on click
  31. Example: <a href="{{route('customers.destroy', $customer->id)}}" data-method="delete" name="delete_item">Delete</a>
  32. Injects a form with that's fired on click of the link with a DELETE request.
  33. Good because you don't have to dirty your HTML with delete forms everywhere.
  34. */
  35. $('[data-method]').append(function () {
  36. return "\n" +
  37. "<form action='" + $(this).attr('href') + "' method='POST' name='delete_item' style='display:none'>\n" +
  38. " <input type='hidden' name='_method' value='" + $(this).attr('data-method') + "'>\n" +
  39. " <input type='hidden' name='_token' value='" + $('meta[name="_token"]').attr('content') + "'>\n" +
  40. "</form>\n"
  41. })
  42. .removeAttr('href')
  43. .attr('style', 'cursor:pointer;')
  44. .attr('onclick', '$(this).find("form").submit();');
  45. /*
  46. Generic are you sure dialog
  47. */
  48. $('form[name=delete_item]').submit(function () {
  49. return confirm("确定要删除此项?");
  50. });
  51. /*
  52. Bind all bootstrap tooltips
  53. */
  54. $("[data-toggle=\"tooltip\"]").tooltip();
  55. $("[data-toggle=\"popover\"]").popover();
  56. //This closes the popover when its clicked away from
  57. $('body').on('click', function (e) {
  58. $('[data-toggle="popover"]').each(function () {
  59. if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
  60. $(this).popover('hide');
  61. }
  62. });
  63. });
  64. // 单选框 input checked radio 初始化
  65. $('.wrapper-content').find("input").iCheck({
  66. checkboxClass: 'icheckbox_square-green',
  67. radioClass: 'iradio_square-green',
  68. increaseArea: '20%'
  69. });
  70. $('.btn-dropbox').find('input').iCheck('destroy');
  71. // input 单选框全选or 全取消
  72. $('.wrapper-content .table').find(".check-all").on('ifChecked', function (e) {
  73. e.preventDefault();
  74. $(this).parents('table').find(".icheckbox_square-green").iCheck('check');
  75. });
  76. $('.wrapper-content .table').find(".check-all").on('ifUnchecked', function (e) {
  77. e.preventDefault();
  78. $(this).parents('table').find(".icheckbox_square-green").iCheck('uncheck');
  79. });
  80. $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
  81. var $this = $(this),
  82. href = $this.attr('href'),
  83. url = $(this).data('url');
  84. console.log(url);
  85. if (url) {
  86. var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, '')));
  87. console.log($target.html());
  88. $target.html('').load(url, function () {
  89. });
  90. }
  91. });
  92. $('.modal').on('click', '[data-toggle=form-submit]', function (e) {
  93. e.preventDefault();
  94. $($(this).data('target')).submit();
  95. });
  96. });