jfs

Class change watch width mutationObserver

jfs
Jul 5th, 2021
1,099
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function maintenanceAjaxLoad(clickedMenuItem){
  2.     /* new logo position */
  3.     var logo     = document.getElementById('ufk__animated');
  4.     var mainCont = document.getElementById('mainContent');
  5.     var ajaxHref = clickedMenuItem.href;
  6.     var ajaxData = ajaxHref.replace(/(#[^-]+)/,'') + '.json';
  7.     var ajaxCont = document.getElementById('bodyCont');
  8.  
  9.     const mutationObserver = new MutationObserver(function (mutationsList, observer) {
  10.         mutationsList.forEach(mutation => {
  11.             console.log(mutation.target);
  12.  
  13.             if (mutation.target.classList.contains('finished')) {
  14.                 console.log('finished' + logo);
  15.                
  16.                 logo.classList.add('ufk_newpos');
  17.  
  18.                 logo.addEventListener('animationend', function(){
  19.                     logo.classList.replace('finished', 'anicomplete');
  20.  
  21.                     mainCont.style.flex = '1 0 auto';
  22.                     mainCont.style.justifyContent = 'flex-start';
  23.  
  24.                     ajaxCont.classList.add('fade-in');
  25.  
  26.                     ajaxLoad(ajaxData, ajaxCont, function(response){
  27.                         let htmlTitle = response.title;
  28.                         let htmlText = response.text;
  29.  
  30.                         ajaxCont.innerHTML = htmlTitle + htmlText;
  31.                         history.pushState(htmlText, ajaxData, ajaxHref);
  32.                     });
  33.                 });
  34.             }
  35.         });
  36.     });
  37.  
  38.     mutationObserver.observe(logo, { attributes: true});
  39.  
  40.     if(logo.classList.contains('anicomplete')){
  41.         ajaxLoad(ajaxData, ajaxCont, function(response){
  42.             let htmlTitle = response.title;
  43.             let htmlText = response.text;
  44.  
  45.             ajaxCont.innerHTML = htmlTitle + htmlText;
  46.             history.pushState(htmlText, ajaxData, ajaxHref);
  47.         });
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment