Skip to content

Instantly share code, notes, and snippets.

@bryanbibat
Created June 23, 2012 23:47
Show Gist options
  • Save bryanbibat/2980587 to your computer and use it in GitHub Desktop.
Save bryanbibat/2980587 to your computer and use it in GitHub Desktop.
Replaces the title and all images with class="retina" in a WP blog that uses Pagelines theme
//logic shamelessly copied from https://github.com/imulus/retinajs
jQuery(document).ready(function() {
var replaceRetina = function(elem) {
if (elem.complete) {
var src = elem.src;
var path_segments = src.split('.');
var path_without_extension = path_segments.slice(0, (path_segments.length - 1)).join(".");
var extension = path_segments[path_segments.length - 1];
elem.setAttribute('width', elem.offsetWidth);
elem.setAttribute('height', elem.offsetHeight);
elem.setAttribute('src', path_without_extension + "@2x." + extension);
} else {
setTimeout(function() { replaceRetina(elem) }, 5);
}
}
if (window.devicePixelRatio > 1) {
jQuery(".mainlogo-img, .retina").each(function(i) {
replaceRetina(this);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment