Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Drupal.behaviors.showAdvertizementLoader = {
  2.     attach(context, settings) {
  3.       if (context === document) {
  4.         const body = $('#js-preroll-container', context)[0];
  5.         const config = {childList: true, attributes: true, subtree: true};
  6.         var in_dom = false;
  7.  
  8.         const observer = new MutationObserver(function (mutations) {
  9.           mutations.forEach(function (mutation) {
  10.             if ($(body).find('#js-preroll-container-wrapper').length > 0) {
  11.               if (!in_dom) {
  12.                 console.log("element inserted");
  13.               }
  14.               in_dom = true;
  15.             }
  16.             else {
  17.               if (in_dom) {
  18.                 in_dom = false;
  19.                 console.log("element removed");
  20.               }
  21.             }
  22.           });
  23.         });
  24.  
  25.         observer.observe(body, config);
  26.       }
  27.     },
  28.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement