Jump to content

Elements Manipulate

Recommended Posts

Please see Elements Manipulate.

This is a base effect and gives you the ability to append, prepend, or replace one selector with another. You might use it for an effect like moving a common block from the footer to particular pages.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment
  • creedon changed the title to Elements Manipulate
  • 1 year later...
  • 1 month later...

Here is an example settings that moves a Video block from Additional Info above the quantity.

  <script type="application/vnd.twc.em">
  
    {
    
      /*
      
        the format of each data structure is a selector source and destination,
        an action, and optional callback
        
        following is an example data structure. copy the example data structure
        below and paste after the example data structure. remove the forward
        slash asterisk and asterisk forward slash lines from before and after
        the example data structure. repeat for as many as many elements as you
        need to manipulate. this has been done once initially
        
        */
        
      /* "[ enter selector source here between double quotes replacing square brackets ]" : {
      
        "selectorDestination" : "[ enter selector destination here between double quotes replacing square brackets ]",
        
        // action value is after, append, before, prepend or replace
        
        "action" : "append",
        
        // selectorParentDestination is optional, use when you want to first
        // find a selector destination but then work up the ancestor hierarchy
        // to manipulate it
        
        "selectorParentDestination" : "[ enter selector parent destination here between double quotes replacing square brackets ]",
        
        // sourceCopy when true will make a copy of the source element and use
        // it instead of the actual selectorSource. value is false or true
        
        "sourceCopy" : false,
        
        // callback is optional, use when you want to manipulate the structure
        // of the source element. replace undefined with the name of your custom
        // function
        //
        // your callback must accept and return a JavaScript object
        
        "callback" : "[ enter callback name here between double quotes replacing square brackets ]"
        
        }, */
        
      "#block-yui_3_17_2_1_1728593423043_10015" : {
      
        "selectorDestination" : ".ProductItem-quantity-add-to-cart",
        
        // action value is after, append, before, prepend or replace
        
        "action" : "before",
        
        // selectorParentDestination is optional, use when you want to first
        // find a selector destination but then work up the ancestor hierarchy
        // to manipulate it
        
        "selectorParentDestination" : "[ enter selector parent destination here between double quotes replacing square brackets ]",
        
        // sourceCopy when true will make a copy of the source element and use
        // it instead of the actual selectorSource. value is false or true
        
        "sourceCopy" : false,
        
        // callback is optional, use when you want to manipulate the structure
        // of the source element. replace undefined with the name of your custom
        // function
        //
        // your callback must accept and return a JavaScript object
        
        "callback" : "[ enter callback name here between double quotes replacing square brackets ]"
        
        },
        
      }
      
    </script>

 

Screenshot2024-10-10at3_48_03PM.thumb.png.31931b45622ce816bd42c2627fc9ae4f.png

This only handles one vid for one product. If you need to do multiple products then you'd need different settings.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Hi @creedon Thanks so much for getting back to me. I'm not particularly knowledgable of this kind of code and am trying to make sense of it, in terms of whether I need to add anything to it? I tried pasting the entire lot into the header injection, but nothing happened. Sorry if I'm being dumb.

The plan is to have a single looping video on all product pages, and I was hoping this could be achieved using a single piece of code - but in reality am I going to have to add code per video?

Thanks again.

Edited by CSSnoob
Link to comment

Settings Example : Additional Info First Row Video Block Before Quantity

If you have a video for every product that you want to appear before Quantity. Add a Video block as the first row of the Additional Info layout.

<script type="application/vnd.twc.em">

  {
  
    /*
    
      the format of each data structure is a selector source and destination,
      an action, and optional callback
      
      following is an example data structure. copy the example data structure
      below and paste after the example data structure. remove the forward
      slash asterisk and asterisk forward slash lines from before and after
      the example data structure. repeat for as many as many elements as you
      need to manipulate. this has been done once initially
      
      */
      
    /* "[ enter selector source here between double quotes replacing square brackets ]" : {
    
      "selectorDestination" : "[ enter selector destination here between double quotes replacing square brackets ]",
      
      // action value is after, append, before, prepend or replace
      
      "action" : "append",
      
      // selectorParentDestination is optional, use when you want to first
      // find a selector destination but then work up the ancestor hierarchy
      // to manipulate it
      
      "selectorParentDestination" : "[ enter selector parent destination here between double quotes replacing square brackets ]",
      
      // sourceCopy when true will make a copy of the source element and use
      // it instead of the actual selectorSource. value is false or true
      
      "sourceCopy" : false,
      
      // callback is optional, use when you want to manipulate the structure
      // of the source element. replace undefined with the name of your custom
      // function
      //
      // your callback must accept and return a JavaScript object
      
      "callback" : "[ enter callback name here between double quotes replacing square brackets ]"
      
      }, */
      
    ".ProductItem .ProductItem-additional .sqs-layout > .sqs-row:first-child > .sqs-col-12 > .sqs-block-video" : {
    
      "selectorDestination" : ".ProductItem-quantity-add-to-cart",
      
      // action value is after, append, before, prepend or replace
      
      "action" : "before",
      
      // selectorParentDestination is optional, use when you want to first
      // find a selector destination but then work up the ancestor hierarchy
      // to manipulate it
      
      "selectorParentDestination" : "[ enter selector parent destination here between double quotes replacing square brackets ]",
      
      // sourceCopy when true will make a copy of the source element and use
      // it instead of the actual selectorSource. value is false or true
      
      "sourceCopy" : false,
      
      // callback is optional, use when you want to manipulate the structure
      // of the source element. replace undefined with the name of your custom
      // function
      //
      // your callback must accept and return a JavaScript object
      
      "callback" : "[ enter callback name here between double quotes replacing square brackets ]"
      
      },
      
    }
    
  </script>

 

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.