Skip to content

Instantly share code, notes, and snippets.

@zombie
Created November 4, 2010 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zombie/663092 to your computer and use it in GitHub Desktop.
Save zombie/663092 to your computer and use it in GitHub Desktop.
unobtrusive js for heatmap.mozillalabs.com
(function() {
var base='/', cache={};
$('.button').each(function one() {
var h = $(this).attr('href');
h = (h[0]!='/') ? (base+h) : (h=='/freq' ? '/freq/' : h);
if (!cache[h]) $.get(h, function(d) {
cache[h] = $(d.replace(/^[\s\S]*<body>|<scr.+ipt>/g, ''));
});
$(this).click(function() {
$('body').html(cache[h]);
base = h.replace(/[^\/]*$/, '');
$('.button').each(one);
return false;
});
});
})();
// the equivalent bookmarklet
javascript:(function() {var base='/', cache={};$('.button').each(function one() {var h = $(this).attr('href');h = (h[0]!='/') ? (base+h) : (h=='/freq' ? '/freq/' : h);if (!cache[h]) $.get(h, function(d) {cache[h] = $(d.replace(/^[\s\S]*<body>|<scr.+ipt>/g, ''));});$(this).click(function() {$('body').html(cache[h]);base = h.replace(/[^\/]*$/, '');$('.button').each(one);return false;});});})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment