Supportlogo-header

06:18PM, Feb 08, 2010

dockane Member

Is there a way to "zip up" or truncate text on product pages?

Hi there,

I'm playing around with an idea that would let users with the click of a button, truncate the text on a product page.  Here's the scenario: Let's say I have 400 words that describe a product on a page. I would like to allow users to click a button that allows them to essentially close-up a section of that text so they only see let's say a series of 4 bullet points instead.

Essentially, I'm thinking of something like a reverse ajax thingy, where instead of seeing *more* information on a page a user can effectively see less.

The simplest way, although not really what I'm looking for is the old-school HTML code that would allow users to click to a specific point on the same page they're currently viewing.  I believe that was a # sign code of some sort...

Any ideas?

Thanks,
D

Persistence alone is omnipotent.

Last edited 06:52PM, Feb 09, 2010

michaelgoodman Member

You can do this with DHTML but it's clunky.  You can have 2 separate divs,  one showing the truncated text and one showing the full text. 

Your code for the divs would be something like:

<div id="fulltext">The full text of your document</div>

<div id="truncated" style="display:none;">The f...</div>

Wherein the truncated text (called truncated) is set to hidden.  and the fulltext (called fulltext, oddly enough) is shown giving the user the impression that there is only the full text.

Next you add in your button to truncate your text.

<a href="#" onclick="toggle_display('truncated'); toggle('fulltext'); return(false);">Truncate the Text</a>

and lastly the Javascript to toggle between the two divs.

<script type="text/javascript">
function toggle_display(id) {
var n = document.getElementById(id);
if(n.style.display == 'none')
n.style.display = 'block';
else
n.style.display = 'none';
}
</script>

With this in place clicking on the link doesn't reload the page it simply tells one div to hide and one to show.

One note here is that I made it so that clicking on the link will bring the text back again.  I don't know if you wanted them to never get it again but this way they can.

The reason I say this isn't elegant is because the page has to load both divs whether they're shown or not so if you have a lot of content in them then you're loading it twice.  Images should get cached so I guess that's okay. 

You could do it in a fancier way with ajax but I don't feel like writing that right now.

 also - I don't know me the ruby

Hope this gives you something to play with until one of the gurus gets here.

12:41AM, Feb 09, 2010

Jamie Administrator

Mike is right, there is no way to do this without having escaped (notextile) mark-up in the product description area. I would handle this much as Mike proposes. Though I am not sure what the "see less" logic is about. This is counter to the way I would run this on any page. Present less, let the user determine if they want to see more.

01:51AM, Feb 09, 2010

Caroline Schnapp Shopify

Though I am not sure what the "see less" logic is about. This is counter to the way I would run this on any page.

I feel the same.

Caroline from http://11heavens.comhttp://wiki.shopify.com/Eleven_heavens ∴ mllegeorgesand AT gmail DOT com

07:49AM, Feb 09, 2010

michaelgoodman Member

After writing this code out I realized that it was what i'd been looking for on the Tags menu (except the reverse). 

I didn't really think the whole "tags" thing through too thoroughly when I started writing all my shopify apps I just kind of automated it to pull in item specifics from our eBay listings and threw them into the tags. As a result after I added 600 or so items I had quite the list of tags. 

So this is kind of the reverse of what you want to do (I use show all instead of hide all)  but here it is in action if you're interested.  It's on the right hand menu:
http://www.beachery.com/collections/all

03:20PM, Feb 09, 2010

dockane Member

@Michael @Jaimie @Caroline

Thanks for the input.  Michael, you're correct, I'm essentially looking for your tag display in reverse, or like in the Theme Editor section of the Shopify Admin where the color editing is. . .same idea.

The idea behind this wacky question is allowing customers who only want to read about the benefits of an item to do just that.  Longer copy is incredibly more beneficial from an SEO standpoint, and I'm also playing around with longer J.Peterman style copy as well.  Some might enjoy reading the stories, while others may not. 

It's really just another way to experiment with "what works."  I'm crazy like that.  I love to test *everything*!

Does that help with the logic, and any additional ideas?

If I wanted to try this out, is Ajax the best way to go to save on the first load time on the page?

Thanks,
D

Persistence alone is omnipotent.

06:53PM, Feb 09, 2010

michaelgoodman Member

If it's just text the load times should be negligible since 5Kb of text ~= 10Kb of text what with these new-fangled fast internets.  I would only be hesitant if you were loading up images and stuff in there and even then I guess it's okay since the version you've got hidden is the shorter version.

Le me know if it works out.  If offering less information is the way to sell more I'm all for that!

login or Sign up for an account to reply.