1- <style >
2- .ajax-error-frame {
3- display : none ;
4- position : fixed ;
5- z-index : 1020 ;
6- top : 0 ;
7- }
8- .ajax-error-frame .content {
9- --width : 80vw ;
10- --height : 90vh ;
11- position : absolute ;
12- width : var (--width );
13- height : var (--height );
14- box-shadow : 0px 0px 4rem ;
15- transform : translate (calc ((100vw - var (--width )) / 2 ), calc ((100vh - var (--height )) / 2 ));
16- border-radius : 0.4rem ;
17- background-color : #FFF ;
18- display : flex ;
19- flex-direction : column ;
20- overflow : hidden ;
21- }
22- .ajax-error-frame iframe {
23- border : 0 ;
24- height : 100% ;
25- }
26- .ajax-error-frame .close {
27- position : absolute ;
28- right : 0.8rem ;
29- top : 0.4rem ;
30- cursor : pointer ;
31- }
32- .ajax-error-frame .background {
33- position : absolute ;
34- background-color : #0002 ;
35- width : 100vw ;
36- height : 100vh ;
37- }
38- .ajax-error-frame.active {
39- display : block ;
40- opacity : 0 ;
41- animation-name : fadeIn;
42- animation-duration : .4s ;
43- animation-fill-mode : forwards ;
44- }
45- @keyframes fadeIn {
46- from { opacity : 0 ; }
47- to { opacity : 1 ; }
48- }
49- </style >
50-
51- <div class =" ajax-error-frame" >
52- <div class =" background" ></div >
53- <div class =" content" >
54- <div class =" close" >×</div >
55- <iframe ></iframe >
56- </div >
57- </div >
58-
591<script >
60- const errorFrame = document .querySelector (' .ajax-error-frame' );
61-
622$ (document ).ajaxComplete ((e , result , settings ) => {
633 if (result .responseJSON ? .exception !== undefined ) {
644 $ .ajax ({... settings, accepts: " text/html" , backpackExceptionHandler: true });
655 }
666 else if (settings .backpackExceptionHandler ) {
677 Noty .closeAll ();
68- errorFrame .classList .add (' active' );
69- errorFrame .querySelector (' iframe' ).srcdoc = result .responseText ;
70- errorFrame .querySelectorAll (' .close, .background' ).forEach (e => e .onclick = () => errorFrame .classList .remove (' active' ));
8+ showErrorFrame (result .responseText );
719 }
7210});
11+
12+ const showErrorFrame = html => {
13+ let page = document .createElement (' html' );
14+ page .innerHTML = html;
15+ page .querySelectorAll (' a' ).forEach (a => a .setAttribute (' target' , ' _top' ));
16+
17+ let modal = document .getElementById (' ajax-error-frame' );
18+
19+ if (typeof modal !== ' undefined' && modal !== null ) {
20+ modal .innerHTML = ' ' ;
21+ } else {
22+ modal = document .createElement (' div' );
23+ modal .id = ' ajax-error-frame' ;
24+ modal .style .position = ' fixed' ;
25+ modal .style .width = ' 100vw' ;
26+ modal .style .height = ' 100vh' ;
27+ modal .style .padding = ' 5vh 5vw' ;
28+ modal .style .backgroundColor = ' rgba(0, 0, 0, 0.4)' ;
29+ modal .style .zIndex = 200000 ;
30+ }
31+
32+ let iframe = document .createElement (' iframe' );
33+ iframe .style .backgroundColor = ' #17161A' ;
34+ iframe .style .borderRadius = ' 5px' ;
35+ iframe .style .width = ' 100%' ;
36+ iframe .style .height = ' 100%' ;
37+ iframe .style .border = ' 0' ;
38+ iframe .style .boxShadow = ' 0 0 4rem' ;
39+ modal .appendChild (iframe);
40+
41+ document .body .prepend (modal);
42+ document .body .style .overflow = ' hidden' ;
43+ iframe .contentWindow .document .open ();
44+ iframe .contentWindow .document .write (page .outerHTML );
45+ iframe .contentWindow .document .close ();
46+
47+ // Close on click
48+ modal .addEventListener (' click' , () => hideErrorFrame (modal));
49+
50+ // Close on escape key press
51+ modal .setAttribute (' tabindex' , 0 );
52+ modal .addEventListener (' keydown' , e => e .key === ' Escape' && hideErrorFrame (modal));
53+ modal .focus ();
54+ }
55+
56+ const hideErrorFrame = modal => {
57+ modal .outerHTML = ' ' ;
58+ document .body .style .overflow = ' visible' ;
59+ }
7360< / script>
0 commit comments