Created
November 4, 2010 20:04
-
-
Save zombie/663092 to your computer and use it in GitHub Desktop.
unobtrusive js for heatmap.mozillalabs.com
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
(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