Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kyledurand/719f17aee11215b9826a to your computer and use it in GitHub Desktop.
Save kyledurand/719f17aee11215b9826a to your computer and use it in GitHub Desktop.
Removing 'cropped' from image src

This one is farily straight forward

    {{ '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js' | script_tag }}

    <script type="text/javascript">

      (function(window, undefined) {
        var $;

        var asyncLoad = function(src, callback) {
          var previousScript = document.getElementsByTagName('script')[0];
          var script = document.createElement('script');
          script.src = src;
          script.type = 'text/javascript';
          script.async = true;
          script.onload = callback;
          previousScript.parentNode.insertBefore(script, previousScript);
        }
        
        var resize_images = function() {
          $('.order-summary .product--has-image img').each(function(){
            var src = $(this).attr('src');
            $(this).attr('src', src.replace('_150x150_cropped', ''));
            $(this).fadeIn('slow');
          });
        }
        
        var pollFn = function() {
          var pollInterval = setInterval( function() { orderSummary() }, 20);
          var orderSummary = function(){
            if (!$("#payment").hasClass("hidden") && !$("#payment").hasClass("step--blank")) {
              resize_images();
              clearInterval(pollInterval);
            } else if ($('#contact-information').hasClass('step--current')) {
              resize_images();
              clearInterval(pollInterval);
            }
          };
        }

        asyncLoad('//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', function() {
          $ = window.jQuery;
          pollFn();
        });
        
      })(this);
      
    </script> 
    
    <!-- This css should be moved to checkout.scss.liquid -->
    
    <style>
      .js .product__image { display: none; }
    </style>

I've hidden the images until load and then they fade in. This avoids the visible 'jump' when the image size adjusts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment