@@ -23,7 +23,6 @@ export async function init(id) {
2323 vision . inited = true ;
2424
2525 const observer = new IntersectionObserver ( ( ) => {
26- console . log ( 'IntersectionObserver callback' ) ;
2726 if ( checkVisibility ( el ) ) {
2827 WebVideoCtrl . I_Resize ( el . offsetWidth , el . offsetHeight ) ;
2928 }
@@ -38,8 +37,68 @@ const hackJSResize = function () {
3837 const originalResize = JSVideoPlugin . prototype . JS_Resize ;
3938 JSVideoPlugin . prototype . JS_Resize = function ( e , t ) {
4039 const { szId } = this . oOptions ;
41- if ( document . getElementById ( szId ) ) {
42- return originalResize . call ( this , e , t ) ;
40+ const el = document . getElementById ( szId ) ;
41+ if ( el ) {
42+ const visible = checkVisibility ( el ) ;
43+ if ( visible ) {
44+ return originalResize . call ( this , e , t ) ;
45+ }
46+ else {
47+ WebVideoCtrl . I_HidPlugin ( ) ;
48+ }
49+ }
50+ }
51+ }
52+
53+ const checkVisibility = el => {
54+ if ( el . checkVisibility ) {
55+ return el . checkVisibility ( ) ;
56+ }
57+ else {
58+ return isVisible ( el ) ;
59+ }
60+ }
61+
62+ const isVisible = ( element ) => {
63+ if ( ! element ) return false ;
64+
65+ const style = window . getComputedStyle ( element ) ;
66+ if ( style . display === 'none' || style . visibility === 'hidden' || parseFloat ( style . opacity ) < 0.01 ) {
67+ return false ;
68+ }
69+
70+ const rect = element . getBoundingClientRect ( ) ;
71+ if ( rect . width === 0 || rect . height === 0 ) {
72+ return false ;
73+ }
74+
75+ let parent = element . parentElement ;
76+ while ( parent ) {
77+ const parentStyle = window . getComputedStyle ( parent ) ;
78+ if ( parentStyle . display === 'none' || parentStyle . visibility === 'hidden' ) {
79+ return false ;
80+ }
81+ parent = parent . parentElement ;
82+ }
83+
84+ return true ;
85+ }
86+
87+ const hackJSShowWnd = function ( ) {
88+ const originalShowWnd = JSVideoPlugin . prototype . JS_ShowWnd ;
89+ JSVideoPlugin . prototype . JS_ShowWnd = function ( ) {
90+ const { szId } = this . oOptions ;
91+ const el = document . getElementById ( szId ) ;
92+ if ( el ) {
93+ const visible = checkVisibility ( el ) ;
94+ if ( visible ) {
95+ return originalShowWnd . call ( this ) ;
96+ }
97+ else {
98+ return new Promise ( ( resolve , reject ) => {
99+ resolve ( ) ;
100+ } ) ;
101+ }
43102 }
44103 }
45104}
@@ -100,6 +159,7 @@ const initWindow = id => {
100159 if ( result . inited === false || ( result . inited && result . iWndIndex !== - 1 ) ) {
101160 clearInterval ( handler ) ;
102161 hackJSResize ( ) ;
162+ hackJSShowWnd ( ) ;
103163 hackJSDestroyPlugin ( ) ;
104164 resolve ( result ) ;
105165 }
0 commit comments