Change script contents if body has class of home-page

by ian_smithz

HTML

<script>



  document.addEventListener("DOMContentLoaded", function() {

    var resizeTimer;

    var resizeFunction = function() {

      var winWidth = window.innerWidth;
      var innerWidth = $(".wrp .inner").width();


      $(".full_width_wrp").css("width", winWidth);
      $(".full_width_wrp").css("left", -(winWidth - innerWidth) / 2);

    }

    $(window).resize(function() {

      clearTimeout(resizeTimer);
      resizeTimer = setTimeout(resizeFunction, 250);
      resizeFunction();
    });

    resizeFunction();

  });

</script>

JavaScript

if ($('body').hasClass('home-page')) {
    $("script").each(function() {
      var text = $(this).text();
      text = text.replace("window.innerWidth", "$(window).width()");
      $(this).text(text);
    });
  }
  
  // find script
  //console.log((document.getElementsByTagName("script")[0].innerHTML));