Skip to content

Instantly share code, notes, and snippets.

@justinhillsjohnson
Created August 8, 2012 14:36
Show Gist options
  • Save justinhillsjohnson/3295506 to your computer and use it in GitHub Desktop.
Save justinhillsjohnson/3295506 to your computer and use it in GitHub Desktop.
360 review
var isClicked = false,
$videoContent = $('#video-content'); //cache the selector
//utilize event delegation instead of direct event binding (note the 2nd param is the selector for event delegation)
$videoContent.on('click', '.ratings img', function() {
e.preventDefault(); //this is all it takes to shortcircuit the event, unless you want to also call e.stopPropagation(); return false does both of these.
});
$videoContent.on('click', '.ratings' function() {
//use === false instead of ! to prevent type coercion issues
if(isClicked === false) {
rate_post();
isClicked = true;
}
});
//again, use event delegation
$videoContent.on('hover', '.ratings', function(e) {
if (e.type === 'mouseenter') {
$(this).find('img').attr('src', 'http://cpb360.com/wp-content/plugins/wp-postratings/images/like/rating_1_over.gif'); //do you want these to be production references, always? maybe relative pathing is better
} else if (e.type === 'mouseleave') {
$(this).find('img').attr('src', 'http://cpb360.com/wp-content/plugins/wp-postratings/images/like/rating_1_on.gif');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment