Getting mootools vs jQuery conflict on LazyLoad script









up vote
0
down vote

favorite












So I'm trying to use this script https://codepen.io/cjl750/pen/pEAmgR in my website.



 // LAZY LOAD FUNCTION
function lazyLoad()
$('iframe').each(function()
var frame = $(this),
vidSource = $(frame).attr('data-src'),
distance = $(frame).offset().top - $(window).scrollTop(),
distTopBot = window.innerHeight - distance,
distBotTop = distance + $(frame).height();

if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
$(frame).attr('src', vidSource);
$(frame).removeAttr('data-src');

);

var throttled = _.throttle(lazyLoad, 100);
$(window).scroll(throttled);


// ILLUSTRATION OF VARIABLES
// as calculated on div#example
function lazyLoadExample()
var frame = $('#example'),
vidSource = $(frame).attr('data-src'),
distance = $(frame).offset().top - $(window).scrollTop(),
distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
distBotTop = Math.round(distance + $(frame).height()); // distance from bottom of frame to top of viewport

document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

var throttled = _.throttle(lazyLoadExample, 100);
$(window).scroll(throttled);


But since the site handles both jQuery and Mootools, I'm getting a conflict:



Uncaught TypeError: $ is not a function
Depending on what I do, I even get a LazyLoad is not a function



To "fix" it I've replaced every $ for jquery



Like this:



// LAZY LOAD FUNCTION
function lazyLoad()
jQuery('iframe').each(function()
var frame = jQuery(this),
vidSource = jQuery(frame).attr('data-src'),
distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
distTopBot = window.innerHeight - distance,
distBotTop = distance + jQuery(frame).height();

if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
jQuery(frame).attr('src', vidSource);
jQuery(frame).removeAttr('data-src');

);

var throttled = _.throttle(lazyLoad, 100);
jQuery(window).scroll(throttled);


// ILLUSTRATION OF VARIABLES
// as calculated on div#example
function lazyLoadExample()
var frame = jQuery('#example'),
vidSource = jQuery(frame).attr('data-src'),
distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
distBotTop = Math.round(distance + jQuery(frame).height()); // distance from bottom of frame to top of viewport

document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

var throttled = _.throttle(lazyLoadExample, 100);
jQuery(window).scroll(throttled);


But I know that's not the right way to fix it. Please help.



I have even tried something like jQuery(function lazyLoad(&) );, no can do.



Aditional javascript:



<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>


PS: The script is supposed to Lazy Load iframes.










share|improve this question



























    up vote
    0
    down vote

    favorite












    So I'm trying to use this script https://codepen.io/cjl750/pen/pEAmgR in my website.



     // LAZY LOAD FUNCTION
    function lazyLoad()
    $('iframe').each(function()
    var frame = $(this),
    vidSource = $(frame).attr('data-src'),
    distance = $(frame).offset().top - $(window).scrollTop(),
    distTopBot = window.innerHeight - distance,
    distBotTop = distance + $(frame).height();

    if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
    $(frame).attr('src', vidSource);
    $(frame).removeAttr('data-src');

    );

    var throttled = _.throttle(lazyLoad, 100);
    $(window).scroll(throttled);


    // ILLUSTRATION OF VARIABLES
    // as calculated on div#example
    function lazyLoadExample()
    var frame = $('#example'),
    vidSource = $(frame).attr('data-src'),
    distance = $(frame).offset().top - $(window).scrollTop(),
    distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
    distBotTop = Math.round(distance + $(frame).height()); // distance from bottom of frame to top of viewport

    document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
    document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

    var throttled = _.throttle(lazyLoadExample, 100);
    $(window).scroll(throttled);


    But since the site handles both jQuery and Mootools, I'm getting a conflict:



    Uncaught TypeError: $ is not a function
    Depending on what I do, I even get a LazyLoad is not a function



    To "fix" it I've replaced every $ for jquery



    Like this:



    // LAZY LOAD FUNCTION
    function lazyLoad()
    jQuery('iframe').each(function()
    var frame = jQuery(this),
    vidSource = jQuery(frame).attr('data-src'),
    distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
    distTopBot = window.innerHeight - distance,
    distBotTop = distance + jQuery(frame).height();

    if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
    jQuery(frame).attr('src', vidSource);
    jQuery(frame).removeAttr('data-src');

    );

    var throttled = _.throttle(lazyLoad, 100);
    jQuery(window).scroll(throttled);


    // ILLUSTRATION OF VARIABLES
    // as calculated on div#example
    function lazyLoadExample()
    var frame = jQuery('#example'),
    vidSource = jQuery(frame).attr('data-src'),
    distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
    distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
    distBotTop = Math.round(distance + jQuery(frame).height()); // distance from bottom of frame to top of viewport

    document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
    document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

    var throttled = _.throttle(lazyLoadExample, 100);
    jQuery(window).scroll(throttled);


    But I know that's not the right way to fix it. Please help.



    I have even tried something like jQuery(function lazyLoad(&) );, no can do.



    Aditional javascript:



    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>

    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>


    PS: The script is supposed to Lazy Load iframes.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      So I'm trying to use this script https://codepen.io/cjl750/pen/pEAmgR in my website.



       // LAZY LOAD FUNCTION
      function lazyLoad()
      $('iframe').each(function()
      var frame = $(this),
      vidSource = $(frame).attr('data-src'),
      distance = $(frame).offset().top - $(window).scrollTop(),
      distTopBot = window.innerHeight - distance,
      distBotTop = distance + $(frame).height();

      if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
      $(frame).attr('src', vidSource);
      $(frame).removeAttr('data-src');

      );

      var throttled = _.throttle(lazyLoad, 100);
      $(window).scroll(throttled);


      // ILLUSTRATION OF VARIABLES
      // as calculated on div#example
      function lazyLoadExample()
      var frame = $('#example'),
      vidSource = $(frame).attr('data-src'),
      distance = $(frame).offset().top - $(window).scrollTop(),
      distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
      distBotTop = Math.round(distance + $(frame).height()); // distance from bottom of frame to top of viewport

      document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
      document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

      var throttled = _.throttle(lazyLoadExample, 100);
      $(window).scroll(throttled);


      But since the site handles both jQuery and Mootools, I'm getting a conflict:



      Uncaught TypeError: $ is not a function
      Depending on what I do, I even get a LazyLoad is not a function



      To "fix" it I've replaced every $ for jquery



      Like this:



      // LAZY LOAD FUNCTION
      function lazyLoad()
      jQuery('iframe').each(function()
      var frame = jQuery(this),
      vidSource = jQuery(frame).attr('data-src'),
      distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
      distTopBot = window.innerHeight - distance,
      distBotTop = distance + jQuery(frame).height();

      if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
      jQuery(frame).attr('src', vidSource);
      jQuery(frame).removeAttr('data-src');

      );

      var throttled = _.throttle(lazyLoad, 100);
      jQuery(window).scroll(throttled);


      // ILLUSTRATION OF VARIABLES
      // as calculated on div#example
      function lazyLoadExample()
      var frame = jQuery('#example'),
      vidSource = jQuery(frame).attr('data-src'),
      distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
      distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
      distBotTop = Math.round(distance + jQuery(frame).height()); // distance from bottom of frame to top of viewport

      document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
      document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

      var throttled = _.throttle(lazyLoadExample, 100);
      jQuery(window).scroll(throttled);


      But I know that's not the right way to fix it. Please help.



      I have even tried something like jQuery(function lazyLoad(&) );, no can do.



      Aditional javascript:



      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>

      <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>


      PS: The script is supposed to Lazy Load iframes.










      share|improve this question















      So I'm trying to use this script https://codepen.io/cjl750/pen/pEAmgR in my website.



       // LAZY LOAD FUNCTION
      function lazyLoad()
      $('iframe').each(function()
      var frame = $(this),
      vidSource = $(frame).attr('data-src'),
      distance = $(frame).offset().top - $(window).scrollTop(),
      distTopBot = window.innerHeight - distance,
      distBotTop = distance + $(frame).height();

      if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
      $(frame).attr('src', vidSource);
      $(frame).removeAttr('data-src');

      );

      var throttled = _.throttle(lazyLoad, 100);
      $(window).scroll(throttled);


      // ILLUSTRATION OF VARIABLES
      // as calculated on div#example
      function lazyLoadExample()
      var frame = $('#example'),
      vidSource = $(frame).attr('data-src'),
      distance = $(frame).offset().top - $(window).scrollTop(),
      distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
      distBotTop = Math.round(distance + $(frame).height()); // distance from bottom of frame to top of viewport

      document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
      document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

      var throttled = _.throttle(lazyLoadExample, 100);
      $(window).scroll(throttled);


      But since the site handles both jQuery and Mootools, I'm getting a conflict:



      Uncaught TypeError: $ is not a function
      Depending on what I do, I even get a LazyLoad is not a function



      To "fix" it I've replaced every $ for jquery



      Like this:



      // LAZY LOAD FUNCTION
      function lazyLoad()
      jQuery('iframe').each(function()
      var frame = jQuery(this),
      vidSource = jQuery(frame).attr('data-src'),
      distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
      distTopBot = window.innerHeight - distance,
      distBotTop = distance + jQuery(frame).height();

      if (distTopBot >= 0 && distBotTop >= 0) // if frame is partly in view
      jQuery(frame).attr('src', vidSource);
      jQuery(frame).removeAttr('data-src');

      );

      var throttled = _.throttle(lazyLoad, 100);
      jQuery(window).scroll(throttled);


      // ILLUSTRATION OF VARIABLES
      // as calculated on div#example
      function lazyLoadExample()
      var frame = jQuery('#example'),
      vidSource = jQuery(frame).attr('data-src'),
      distance = jQuery(frame).offset().top - jQuery(window).scrollTop(),
      distTopBot = Math.round(window.innerHeight - distance), // distance from top of frame to bottom of viewport
      distBotTop = Math.round(distance + jQuery(frame).height()); // distance from bottom of frame to top of viewport

      document.getElementById('stick1').innerHTML = "distBotTop: " + distBotTop;
      document.getElementById('stick2').innerHTML = "distTopBot: " + distTopBot;

      var throttled = _.throttle(lazyLoadExample, 100);
      jQuery(window).scroll(throttled);


      But I know that's not the right way to fix it. Please help.



      I have even tried something like jQuery(function lazyLoad(&) );, no can do.



      Aditional javascript:



      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>

      <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js"></script>


      PS: The script is supposed to Lazy Load iframes.







      javascript jquery jquery-ui mootools






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 6:15









      deblocker

      4,96721234




      4,96721234










      asked Nov 10 at 21:57









      023023

      1853316




      1853316



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243806%2fgetting-mootools-vs-jquery-conflict-on-lazyload-script%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243806%2fgetting-mootools-vs-jquery-conflict-on-lazyload-script%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto