Permalink
Browse files

Use jquery closest to determine whether clicked element triggers expe…

…riment goal
  • Loading branch information...
1 parent 57ce18e commit d1938c6e2fb6acad08dd4a76486cd529023d88a5 @fmoga fmoga committed Jan 23, 2013
Showing with 4 additions and 3 deletions.
  1. +4 −3 experiments/media/js/experiments.js
@@ -4,16 +4,17 @@ experiments = function() {
$.get("/experiments/confirm_human/");
},
goal: function(goal_name) {
- $.post("/experiments/goal/" + goal_name);
+ $.post("/experiments/goal/" + goal_name + "/");
}
};
}();
if (document.addEventListener) {
// sets the cookie in the capturing phase so that in the bubbling phase we guarantee that if a request is being issued it will contain the new cookie as well
document.addEventListener("click", function(event) {
- if ((event.target).hasAttribute('data-experiments-goal')) {
- $.cookie("experiments_goal", $(event.target).data('experiments-goal'), { path: '/' });
+ closest = $(event.target).closest('[data-experiments-goal]')
+ if (closest.length) {
+ $.cookie("experiments_goal", $(closest[0]).data('experiments-goal'), { path: '/' });
}
}, true);
} else { // IE 8

0 comments on commit d1938c6

Please sign in to comment.