Jump to content

How To Install + Dropdown Accordion in a Product Description

Recommended Posts

Site URL: https://www.erheer.com/shop/ariel

Hi Squarespace Wizards,

I am trying to install a dropdown accordion in the description of a physical product. Unfortunately Squarespace doesn't have the option to add a markdown box in the description of a product(screenshot 1). 

I have add the code block and the markdown box in the additional Info (screenshot 2) but that shows at the end of the page after all the product photos at the moment. I'd like the dropdown to be a part of the product description itself (screenshot 4) and not at the end of the page. 

Any assistance would be greatly appreciated.

Thanks,

Divya

Screen Shot 2020-06-29 at 3.06.13 am.png

Screen Shot 2020-06-29 at 3.09.05 am.png

Screen Shot 2020-06-29 at 3.05.23 am.png

Screen Shot 2020-06-29 at 3.16.42 am.png

Link to comment

Thanks for the reply. I will share the link once i've figured out how to make the code work outside the develop/edit mode of squarespace. The accordion is working fine on the page in edit mode but when I test it in on a fresh tab, its not. 

 

 

Link to comment

Hi tuanphan, I've added the code to additional info. Please help with adding it to just under the description itself. 

Also if it's not too much trouble could you help me with closing the + automatically close when another "H" is opened.

https://aqua-megalodon-5m3t.squarespace.com/shop/ariel

Please let me know if you need any additional info.

On 6/30/2020 at 7:04 PM, tuanphan said:

You can add to additional info, then share url again. We can give the code to move it to description

 

Link to comment

Just after the text ends..Please see photo attached.

Also I want the same to happen for all my products, so will I have to post the code on each individual product or can I paste it somewhere else so that it is applied to all the products. 

Screen Shot 2020-06-29 at 3.16.42 am.png

Link to comment

Here it is and thanks for working on this!

<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
 $(document).ready(function(){

 $('.markdown-block .sqs-block-content h3').css('cursor','pointer');

 $(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();

 $(".markdown-block .sqs-block-content h3").click(function()
{$(this).nextUntil("h3").slideToggle();});
 });
 </script>

Link to comment

Add to Code Injection Footer

<script>
  $(document).ready(function() { 
		$('.ProductItem-additional .markdown-block').insertAfter('.ProductItem-details-excerpt');
	});
</script>

and add this to Home > Design > Custom CSS

.ProductItem-details .markdown-block {
    order: 4;
}

 

Edited by tuanphan

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment

I was just helping someone else today with a similar accordion, but he hasn't been back to test it yet. See if this works.

    $(document).ready(function() {
      $('.markdown-block .sqs-block-content h3').addClass('ui-closed').css('cursor', 'pointer');
      $('.markdown-block .sqs-block-content h3').nextUntil('h3').slideUp();
      $('.markdown-block .sqs-block-content h3').click(function() {
        if ($(this).nextUntil('h3').is(':hidden')) {
          $('.markdown-block .sqs-block-content h3').nextUntil('h3').slideUp();
          $('.markdown-block .sqs-block-content h3').removeClass('ui-open');
          $('.markdown-block .sqs-block-content h3').addClass('ui-closed');

          $(this).nextUntil('h3').slideDown();
          $(this).toggleClass('ui-closed ui-open');
        } else {
          $(this).nextUntil('h3').slideUp();
          $(this).toggleClass('ui-closed ui-open');
        }
      });
    });
.markdown-block p {
  margin-left: 1em; 
}

.markdown-block .ui-closed:before {
  font-family: monospace;
  content: "+ ";
  color: #2DA9C6; 
}

.markdown-block .ui-open:before {
  font-family: monospace;
  content: "- ";
  color: #2DA9C6; 
}

 

Link to comment

It is working but only after I refresh the page. Somehow when the page loads for the first time, it still shows the text at the end of the page and all opened up like in screenshot 1 & 2. And then when I hit refresh, it works (screenshot 3)

Screen Shot 2020-07-02 at 12.28.36 pm.png

Screen Shot 2020-07-02 at 12.28.47 pm.png

Screen Shot 2020-07-02 at 12.29.05 pm.png

Link to comment

Sorry, try changing this code

<script>
  $(document).ready(function() { 
		$('.ProductItem-additional .markdown-block').insertAfter('.ProductItem-details-excerpt');
	});
</script>

to this

<script>
  window.Squarespace.onInitialize(Y, function () { 
		$('.ProductItem-additional .markdown-block').insertAfter('.ProductItem-details-excerpt');
	});
</script>

This is an issue with ajax loading.

Link to comment

Tried but it is doing the same thing. Not firing at first load and then when I refresh, it works but all the sections are opened up. 

Also this code is in the Code Injection Footer and not header. 

<script>
  window.Squarespace.onInitialize(Y, function () { 
		$('.ProductItem-additional .markdown-block').insertAfter('.ProductItem-details-excerpt');
	});
</script>
Link to comment

OHHHH. I think I see the issue.

You might have put some of the CSS in the code injection block.

So delete both codes from above replace with this (code injection)

<script>
window.Squarespace.onInitialize(Y, function() {
  $('.ProductItem-additional .markdown-block').insertAfter('.ProductItem-details-excerpt');
  $('.markdown-block .sqs-block-content h3').addClass('ui-closed').css('cursor', 'pointer');
  $('.markdown-block .sqs-block-content h3').nextUntil('h3').slideUp();
  $('.markdown-block .sqs-block-content h3').click(function() {
    if ($(this).nextUntil('h3').is(':hidden')) {
      $('.markdown-block .sqs-block-content h3').nextUntil('h3').slideUp();
      $('.markdown-block .sqs-block-content h3').removeClass('ui-open');
      $('.markdown-block .sqs-block-content h3').addClass('ui-closed');

      $(this).nextUntil('h3').slideDown();
      $(this).toggleClass('ui-closed ui-open');
    } else {
      $(this).nextUntil('h3').slideUp();
      $(this).toggleClass('ui-closed ui-open');
    }
  });
});
</script>

Then add this to Design -> Custom CSS

.markdown-block p {
  margin-left: 1em; 
}

.markdown-block .ui-closed:before {
  font-family: monospace;
  content: "+ ";
  color: #2DA9C6; 
}

.markdown-block .ui-open:before {
  font-family: monospace;
  content: "- ";
  color: #2DA9C6; 
}

 

Edited by rwp
Link to comment

I think I am losing the plot here. Just to confirm once again, just the above two pieces of code right and delete everything else? 

CSS goes  in Design < Custom CSS 

Script goes in Home > Settings > Advanced >  Code Injection (Footer)

No other piece of code on the product, just the Markdown block in Additional Info?

Sorry for being a noob. 

Edited by divar
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.