From 175e5bdc309f7bee14e87d68104d14bb8e7f9b9b Mon Sep 17 00:00:00 2001 From: OhaiBBQ Date: Mon, 1 Nov 2010 10:37:07 -0700 Subject: [PATCH] Added strict equality operator to #publisher and #stream keydown event Added caching of the $container jQuery object Added caching of $controls and $this in the .make_profile_photo click event changed the success callback to use this.src = photo_url; instead of creating a new jQuery object --- public/javascripts/view.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/public/javascripts/view.js b/public/javascripts/view.js index a129330ca..62efa5364 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -49,13 +49,13 @@ $(document).ready(function(){ ); $("#publisher").find("textarea").keydown( function(e) { - if (e.keyCode == 13) { + if (e.keyCode === 13) { $(this).closest("form").submit(); } }); $("#stream").delegate("textarea.comment_box", "keydown", function(e){ - if (e.keyCode == 13) { + if (e.keyCode === 13) { $(this).closest("form").submit(); } }); @@ -101,26 +101,29 @@ $.fn.clearForm = function() { var video_active_container = null; function openVideo(type, videoid, link) { - var container = document.createElement('div'); + var container = document.createElement('div'), + $container = $(container); if(type == 'youtube.com') { - container.innerHTML = 'Watch this video on Youtube
'; + $container.html('Watch this video on Youtube
'); } else { - container.innerHTML = 'Invalid videotype '+type+' (ID: '+videoid+')'; + $container.html('Invalid videotype '+type+' (ID: '+videoid+')'); } if(video_active_container != null) { video_active_container.parentNode.removeChild(video_active_container); } video_active_container = container; - $(container).hide(); + $container.hide(); link.parentNode.insertBefore(container, this.nextSibling); - $(container).slideDown('fast', function() { }); - link.onclick = function() { $(container).slideToggle('fast', function() { } ); } + $container.slideDown('fast', function() { }); + link.onclick = function() { $container.slideToggle('fast', function() { } ); } } $(".make_profile_photo").live("click", function(){ - var user_id = $(this).closest(".controls").attr('data-actor'); - person_id = $(this).closest(".controls").attr('data-actor_person'); - photo_url = $(this).closest(".controls").attr('data-image_url'); + var $this = $(this), + $controls = $this.closest(".controls"), + user_id = $controls.attr('data-actor'); + person_id = $controls.attr('data-actor_person'); + photo_url = $controls(".controls").attr('data-image_url'); $.ajax({ type: "PUT", @@ -128,7 +131,7 @@ $(".make_profile_photo").live("click", function(){ data: {"person":{"profile":{ "image_url": photo_url }}}, success: function(){ $("img[data-person_id='"+ person_id +"']").each( function() { - $(this).attr('src', photo_url); + this.src = photo_url; }); } });