Created
September 4, 2013 11:11
-
-
Save cheeyeo/6435628 to your computer and use it in GitHub Desktop.
Rails 3.2 jquery 'live' action being updated with 'on' for UJS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var like_enter = function(){ | |
$(".already_liked").find('.title').text('Unlike It'); | |
$(".already_liked").find('i.icon-circle').addClass('unliked-circle'); | |
$(".already_liked").find('i.icon-light').removeClass('icon-heart').addClass('icon-remove'); | |
} | |
var like_leave = function(){ | |
$(".already_liked").find('.title').text('Like It'); | |
$(".already_liked").find('i.icon-circle').removeClass('unliked-circle'); | |
$(".already_liked").find('i.icon-light').removeClass('icon-remove').addClass('icon-heart'); | |
} | |
$(document).on("mouseenter", "a.already_liked", like_enter); | |
$(document).on("mouseleave", "a.already_liked", like_leave); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above example lives within the main application JS file. In order to rebind the mouseenter and mouseleave events within a UJS response they must be redefined in the context of the document object else it will not work.