Last active
December 16, 2015 17:29
-
-
Save thetrickster/5470271 to your computer and use it in GitHub Desktop.
On facebook Like button event, enable form.fb-like-form input elements
This file contains 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
// Setup a variable to contain all the form input elements to enable | |
var myDisabledFields = "input, textarea, select, button"; | |
// The FB.Event.subscribe method lets us run some javascript on certain events. The "Like" event for the Javascript SDK is "edge.create" | |
FB.Event.subscribe('edge.create', | |
// Once we're subscribed, anytime the Like button is cliked Facebook sends us back some data in an array. | |
// We'll call that data array "response". | |
function(response) { | |
// If you uncomment the next line, you'll see the data returned in your console | |
// console.log(response); | |
// Let's use some jQuery to target form with the class "fb-like-form" and find and enable | |
// each of the matching input elements we put in our variable above | |
jQuery(".fb-like-form").find(myDisabledFields).each(function() { | |
// Remove the "disabled" attribute for this element | |
jQuery(this).removeAttr("disabled"); | |
// Optionally, do other stuff here. | |
}); | |
} | |
); | |
// Let's re-enable the form when someone "UnLikes" a Like button | |
FB.Event.subscribe("edge.remove", function(response){ | |
jQuery(".fb-like-form").find(myDisabledFields).each(function() { | |
jQuery(this).attr("disabled", "disabled"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Place the code above after your FORM and Facebook Like Button markup and before the closing BODY tag.