Skip to content

Instantly share code, notes, and snippets.

@menacestudio
Last active December 12, 2015 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menacestudio/4736143 to your computer and use it in GitHub Desktop.
Save menacestudio/4736143 to your computer and use it in GitHub Desktop.
SO: Toggle current excerpt and show full view and hide other full views.
$(function() {
$('[id^="post-"]').click(
function() {
var self = $(this);
/** Toggle all posts except for the current one. */
$('.post_content').not(self.find('.post_content')).hide();
$('.image-box').not(self.find('.image-box')).show('slow', function(){});
$('.post_excerpt').not(self.find('.post_excerpt')).show(500, function(){});
/** Show full post but hide excerpt UI elements. */
self.find('.post_content').show(500, function(){});
self.find('.image-box').hide('slow', function(){});
self.find('.post_excerpt').hide(500, function(){});
/**
You can play with the rest of the code since I'm not sure what they do.
*/
//$('html, body').animate({ scrollTop: $(this).offset().top - $('#header').outerHeight() }, 500);
/*
if (self.hasClass('alignment-1') == true) {
self.find('.excerpt').animate({'margin-right':'0'}, 500);
} else if ($(this).hasClass('alignment-2') == true) {
self.find('.excerpt').animate({'margin-left':'0'}, 500);
}
*/
/*
if ($(this).hasClass('alignment-1') == true) {
$(this).find('.excerpt').animate({'margin-right':'261px'}, 500);
} else if ($(this).hasClass('alignment-2') == true) {
$(this).find('.excerpt').animate({'margin-left':'261px'}, 500);
}
*/
}
);
});
$(function() {
$('[id^="post-"]').click(
function(e) {
e.preventDefault();
var speed = 500;
var self = $(this);
var isVisible = self.find('.post_content').is(':visible'); // full view content
if (!isVisible) {
/** Toggle all posts except for the current one. */
$('.post_content').not(self.find('.post_content')).hide(speed);
$('.image-box').not(self.find('.image-box')).show(speed);
$('.post_excerpt').not(self.find('.post_excerpt')).show(speed);
/** Show full post but hide excerpt UI elements. */
self.find('.post_content').show(speed);
self.find('.image-box').hide(speed);
self.find('.post_excerpt').hide(speed);
$('html, body').animate({ scrollTop: $(this).offset().top - $('#header').outerHeight() }, speed);
if (self.hasClass('alignment-1') == true) {
self.find('.excerpt').animate({'margin-right':'0'}, speed);
} else if ($(this).hasClass('alignment-2') == true) {
self.find('.excerpt').animate({'margin-left':'0'}, speed);
}
} else {
/** Bring back everything to original state */
$('.post_content').hide(speed);
$('.image-box').show(speed);
$('.post_excerpt').show(speed);
if (self.hasClass('alignment-1') == true) {
self.find('.excerpt').animate({'margin-right':'261px'}, speed);
} else if (self.hasClass('alignment-2') == true) {
self.find('.excerpt').animate({'margin-left':'261px'}, speed);
}
}
}
);
});
$(function () {
$('[id^="post-"]').click(
function (e) {
e.preventDefault();
var speed = 500;
var self = $(this);
var isVisible = self.find('.post_content').is(':visible'); // full view content
if (!isVisible) {
/** Toggle all posts except for the current one. */
$('.post_content').not(self.find('.post_content')).hide({
duration: speed,
complete: function() {
$('.image-box').not(self.find('.image-box')).show(speed);
$('.post_excerpt').not(self.find('.post_excerpt')).show(speed);
/** Show full post but hide excerpt UI elements. */
self.find('.post_content').show(speed);
self.find('.image-box').hide(speed);
self.find('.post_excerpt').hide(speed);
$('html, body').animate({ scrollTop: $(this).offset().top - $('#header').outerHeight() }, speed);
if (self.hasClass('alignment-1') == true) {
self.find('.excerpt').animate({ 'margin-right': '0' }, speed);
} else if ($(this).hasClass('alignment-2') == true) {
self.find('.excerpt').animate({ 'margin-left': '0' }, speed);
}
}
});
} else {
/** Bring back everything to original state */
$('.post_content').hide({duration: speed, complete: function(){
$('.image-box').show(speed);
$('.post_excerpt').show(speed);
if (self.hasClass('alignment-1') == true) {
self.find('.excerpt').animate({ 'margin-right': '261px' }, speed);
} else if (self.hasClass('alignment-2') == true) {
self.find('.excerpt').animate({ 'margin-left': '261px' }, speed);
}
}});
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment