Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add an option to choose the path suffix for 2x images #58

Closed
wants to merge 2 commits into from

4 participants

@YuAo

Added an option to choose the path suffix for 2x images.

I'm using _2x path suffix for my retina images, just as www.apple.com does. But this script only works if your retina image suffix is "@2x". So I added an option.

Commit e7930be
Added another option to select just some of the img tags to make their image retina, not all the images on a webpage.
I can see "travis build failed", because of querySelectorAll. Maybe travis is using an old JS engine.
https://developer.mozilla.org/en-US/docs/DOM/Document.querySelectorAll

@zackdever

I think adding retinaImageSuffix is a good idea (1304e63), though it would be nice if these two changes were separate pull request.

Related to retinaImgTagSelector (e7930be), see #46.

@YuAo YuAo closed this
@nmaves

This would help us out a great deal if this was accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/retina.js
View
10 src/retina.js
@@ -3,6 +3,12 @@
var root = (typeof exports == 'undefined' ? window : exports);
var config = {
+ // An option to choose a suffix for 2x images
+ retinaImageSuffix : "@2x",
+
+ // An option to select some of the img tags to make their image retina.
+ retinaImgTagSelector : "body img",
+
// Ensure Content-Type is an image before trying to load @2x image
// https://github.com/imulus/retinajs/pull/45)
check_mime_type: true
@@ -25,7 +31,7 @@
var existing_onload = context.onload || new Function;
context.onload = function() {
- var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
+ var images = document.querySelectorAll(config.retinaImgTagSelector), retinaImages = [], i, image;
for (i = 0; i < images.length; i++) {
image = images[i];
retinaImages.push(new RetinaImage(image));
@@ -54,7 +60,7 @@
function RetinaImagePath(path) {
this.path = path;
- this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
+ this.at_2x_path = path.replace(/\.\w+$/, function(match) { return config.retinaImageSuffix + match; });
}
RetinaImagePath.confirmed_paths = [];
Something went wrong with that request. Please try again.