Skip to content

Instantly share code, notes, and snippets.

@normanzb
Created September 25, 2015 12:26
Show Gist options
  • Save normanzb/0e9b67d1dc4939d657e1 to your computer and use it in GitHub Desktop.
Save normanzb/0e9b67d1dc4939d657e1 to your computer and use it in GitHub Desktop.
// Apply path matching
var path = d.location.pathname,
refMatch = document.referrer.match(/.{8}[^/]*(\/[^?]+)/),
ref = refMatch ? refMatch[1] : null,
isPathMatch = function(pattern) {
var p = new RegExp((pattern[0] == "/" ? "^" : "") + pattern, "i");
return p.test(path);
},
toArray = function(v){ return _.isArray(v) ? v : [v] };
if (criteria.path && !_.any(toArray(criteria.path), isPathMatch)) {
return;
}
if (criteria.not_path && _.any(toArray(criteria.not_path), isPathMatch)) {
return;
}
path = ref;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment