Skip to content

Instantly share code, notes, and snippets.

@MKorostoff
Created February 23, 2012 15:33
Show Gist options
  • Save MKorostoff/1893316 to your computer and use it in GitHub Desktop.
Save MKorostoff/1893316 to your computer and use it in GitHub Desktop.
/* On the video page, the description shows a trimmed version and expands when you click "more"
and shrinks again when you click "less". We do that by loading two copies of the field,
one trimmed and plain text, the other untrimmed and full HTML. We show/hide these elements
with a static link.
*/
//When the more button is clicked:
jQuery('.node-type-video .more-button').click(function() {
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body').show();
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body-1').hide();
jQuery('.node-type-video .less-button').show();
jQuery(this).hide();
});
//When the more button is clicked
jQuery('.node-type-video .less-button').click(function() {
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body').hide();
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body-1').show();
jQuery('.node-type-video .more-button').show();
jQuery(this).hide();
});
//If the overall string is shorter than the trim length, we just execute the "show more" function, and hide the more/less controls
var click_hider = jQuery('.node-type-video .views-field-body-1 .field-content').html().length;
if (click_hider<=65) {
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body').show();
jQuery('.node-type-video .view-id-video.view-display-id-block_1 .views-field.views-field-body-1').hide();
jQuery('.node-type-video .more-button').hide();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment