Jump to content

How To Install + Dropdown Accordion in a Product Description

Recommended Posts

Posted

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

Posted

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. 

 

 

Posted

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

 

Posted

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

Posted

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>

Posted (edited)

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!)

Posted

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; 
}

 

Posted

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

Posted

Tried the code but it doesn't seem to be working.

1st - the script isn't firing when the page first loads

2nd - after I refresh the page, it starts showing in the correct place but is all opened up. 

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

Posted

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.

Posted

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>
Posted (edited)

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
Posted (edited)

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
Posted

Correct, but if you had other code, not related to the accordion, don't remove that.

The last code I posted above should move the accordion and make it work how you want.... Hopefully.....

Posted

Hey sorry I tried but it is not working now at all. Just appearing at the end of the page even if i refresh it. 

Posted

Put this in the header code injection

<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

 

Posted

It seems to be working now but the accordion in now appearing at the top of the page and not under the description. Also I noticed that the website if taking longer to load, up to 10 seconds.

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

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.