@@ -64,6 +64,11 @@ export class AdUIManager {
6464 player . registerPlugin ( decoratorClass )
6565 newDecoratorPlugin = player . getPlugin ( decoratorClass . pluginName )
6666 fragment . appendChild ( newDecoratorPlugin . root )
67+ if ( newDecoratorPlugin . extraEls ?. length ) {
68+ newDecoratorPlugin . extraEls . forEach ( el => {
69+ fragment . appendChild ( el )
70+ } )
71+ }
6772 }
6873
6974 adUIPlugins . push ( [
@@ -133,11 +138,26 @@ export class AdUIManager {
133138 if ( ! overrideAdPlugin ) {
134139 return
135140 }
136- const { root : adRoot } = overrideAdPlugin
137- const { root : normalRoot } = normalPlugin
141+ const { root : adRoot , extraEls : adExtraEls } = overrideAdPlugin
142+ const { root : normalRoot , extraEls : normalExtraEls } = normalPlugin
138143 if ( fragmentContainer . contains ( adRoot ) ) {
139144 fragmentContainer . removeChild ( adRoot )
140145 }
146+ // handle extra elements except root
147+ if ( Array . isArray ( adExtraEls ) && adExtraEls . length ) {
148+ adExtraEls . forEach ( ( adEl , index ) => {
149+ if ( fragmentContainer . contains ( adEl ) ) {
150+ fragmentContainer . removeChild ( adEl )
151+ }
152+ const normalEl = normalExtraEls ?. [ index ]
153+ if ( normalEl ?. parentNode ) {
154+ // show ad extra dom
155+ normalEl . parentNode . insertBefore ( adEl , normalEl )
156+ // hide normal extra dom
157+ fragmentContainer . appendChild ( normalEl )
158+ }
159+ } )
160+ }
141161 // The ad plugin and the target plugin swap positions
142162 normalRoot . parentNode . insertBefore ( adRoot , normalRoot )
143163 fragmentContainer . appendChild ( normalRoot )
@@ -180,15 +200,30 @@ export class AdUIManager {
180200 if ( ! overrideAdPlugin ) {
181201 return
182202 }
183- const { root : adRoot } = overrideAdPlugin
184- const { root : normalRoot } = normalPlugin
203+ const { root : adRoot , extraEls : adExtraEl } = overrideAdPlugin
204+ const { root : normalRoot , extraEls : normalExtraEl } = normalPlugin
185205 if ( fragmentContainer . contains ( normalRoot ) ) {
186206 fragmentContainer . removeChild ( normalRoot )
187207 }
188208 if ( ! fragmentContainer . contains ( adRoot ) ) {
189209 adRoot . parentNode . insertBefore ( normalRoot , adRoot )
190210 fragmentContainer . appendChild ( adRoot )
191211 }
212+ // handle extra elements except root
213+ if ( Array . isArray ( normalExtraEl ) && normalExtraEl ?. length ) {
214+ normalExtraEl . forEach ( ( normalEl , index ) => {
215+ if ( fragmentContainer . contains ( normalEl ) ) {
216+ fragmentContainer . removeChild ( normalEl )
217+ }
218+ const adEl = adExtraEl ?. [ index ]
219+ if ( adEl && adEl . parentNode ) {
220+ // show normal extra dom
221+ adEl . parentNode . insertBefore ( normalEl , adEl )
222+ // hide ad extra dom
223+ fragmentContainer . appendChild ( adEl )
224+ }
225+ } )
226+ }
192227 } )
193228
194229 // Non-Ad UI Plugins
0 commit comments