script.blade.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <script>
  2. function LA() {}
  3. LA.token = "{{ csrf_token() }}";
  4. LA.lang = {!! json_encode(trans('admin.client') ?: []) !!};
  5. LA.components = {booting:[]};
  6. LA.ready = function (callback, win) {
  7. if (!win || win === window) {
  8. if (typeof LA.pjaxresponse == 'undefined') {
  9. return $(callback, win || window);
  10. }
  11. return $(document, win || window).one('pjax:script', callback);
  12. }
  13. var proxy = function (e) {
  14. win.$(win.$('#pjax-container')).one('pjax:script', proxy);
  15. callback(e);
  16. };
  17. win.LA.ready(proxy);
  18. };
  19. LA._form_ = {
  20. before: [], success: [], error: []
  21. };
  22. {{--注册表单提交前钩子事件--}}
  23. {{--@param {function} call 返回 false 可以阻止表单提交--}}
  24. LA.beforeSubmit = function (call) {
  25. typeof call == 'function' && (LA._form_.before = [call]);
  26. };
  27. {{--@param {function} success 提交成功事件,返回 false 可以阻止默认的表单事件--}}
  28. {{--@param {function} error 提交出错事件,返回 false 可以阻止默认的表单事件--}}
  29. LA.submitted = function (success, error) {
  30. typeof success == 'function' && (LA._form_.success = [success]);
  31. typeof error == 'function' && (LA._form_.error = [error]);
  32. };
  33. {{--
  34. 注册页面初始化事件,相当于:
  35. $(fn);
  36. $(document).on('pjax:complete', fn);
  37. --}}
  38. LA.booting = function (fn) {
  39. typeof fn == 'function' && (LA.components.booting.push(fn));
  40. };
  41. </script>