script.blade.php 1.7 KB

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