Added more caching of jQuery objects, saved a line by using .toggleClass()

This commit is contained in:
OhaiBBQ 2010-11-01 10:07:41 -07:00
parent c8e8ef06e7
commit 6474f5c5f3

View file

@ -5,7 +5,7 @@
$(document).ready(function(){ $(document).ready(function(){
var $stream = $("#stream");
// expand all comments on page load // expand all comments on page load
$("#stream:not('.show')").find('.comments').each(function(index) { $("#stream:not('.show')").find('.comments').each(function(index) {
var comments = $(this); var comments = $(this);
@ -16,17 +16,17 @@ $(document).ready(function(){
}); });
// comment toggle action // comment toggle action
$("#stream:not('.show')").delegate("a.show_post_comments", "click", function(evt) { $stream.not(".show").delegate("a.show_post_comments", "click", function(evt) {
evt.preventDefault(); evt.preventDefault();
expandComments($(this)); expandComments($(this));
}); });
// comment submit action // comment submit action
$("#stream").delegate("a.comment_submit", "click", function(evt){ $stream.delegate("a.comment_submit", "click", function(evt){
$(this).closest("form").children(".comment_box").attr("rows", 1); $(this).closest("form").children(".comment_box").attr("rows", 1);
}); });
$("#stream").delegate("textarea.comment_box", "focus", function(evt){ $stream.delegate("textarea.comment_box", "focus", function(evt){
var commentBox = $(this); var commentBox = $(this);
commentBox.attr("rows", 2) commentBox.attr("rows", 2)
.closest("form").find(".comment_submit").fadeIn(200); .closest("form").find(".comment_submit").fadeIn(200);
@ -41,16 +41,10 @@ $(document).ready(function(){
}); });
// reshare button action // reshare button action
$("#stream").delegate(".reshare_button", "click", function(evt){ $stream.delegate(".reshare_button", "click", function(evt){
evt.preventDefault(); evt.preventDefault();
var button = $(this); $(this).toggleClass("active")
if(button.hasClass("active")) { .closest(".reshare_pane").children(".reshare_box").toggle();
button.closest(".reshare_pane").children(".reshare_box").hide();
button.removeClass("active");
} else {
button.closest(".reshare_pane").children(".reshare_box").show();
button.addClass("active");
}
}); });
});//end document ready });//end document ready