Skip to content

Instantly share code, notes, and snippets.

@cfpg
Created January 2, 2010 19:23
Show Gist options
  • Save cfpg/267624 to your computer and use it in GitHub Desktop.
Save cfpg/267624 to your computer and use it in GitHub Desktop.
javascript:(function() {
var s=document.createElement('script');
s.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js");
if(typeof jQuery=='undefined') {
document.getElementsByTagName('head')[0].appendChild(s);
}
function doWork() {
$.expr[':'].image = function(obj){
return obj.href.match(/(jpg|png|gif)$/i);
};
$("a:image").each(function() {
var img = new Image();
img.src = $(this).attr('href');
$(img).attr("class", "thumb");
$(this).html(img).attr("target", "_blank");
$(img).load(function() {
$(img).attr("rel", img.width).css("width", getWidth(img.width)+"px");
});
});
$("img.thumb").mouseover(function() {
$(this).css("width", $(this).attr("rel")+'px');
}).mouseout(function() {
$(this).css("width", getWidth($(this).attr("rel"))+"px");
});
}
function getWidth(n) {
if ( n > 300 ) {
return n*0.6;
} else if ( n == 0 ) {
return "300";
} else {
return n;
}
}
var tryjQuery=function() {
setTimeout(function() {
if (typeof jQuery=='undefined') {
if (tryCounter) {
tryCounter--;
tryjQuery();
} else {
msg='Sorry, but after ' + startCounter;
showMsg();
}
} else {
doWork();
}
}, 250);
};
tryjQuery();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment