Permalink
Browse files

Add additional media queries for pull #42

  • Loading branch information...
2 parents 415b1e1 + ffb6b38 commit 5671145d8a8adf3d72b6b62d8927799f8dd97863 Casey O'Hara committed Oct 8, 2012
Showing with 35 additions and 7 deletions.
  1. +19 −4 src/retina.js
  2. +3 −0 test/retina.test.js
  3. +13 −3 test/retina_image_path.test.js
View
@@ -32,18 +32,31 @@
}
existing_onload();
}
- }
+ };
+
+ Retina.isRetina = function(){
+ var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
+ (min--moz-device-pixel-ratio: 1.5),\
+ (-o-min-device-pixel-ratio: 3/2),\
+ (min-resolution: 1.5dppx)";
+ if (root.devicePixelRatio > 1)
+ return true;
+ if (root.matchMedia && root.matchMedia(mediaQuery).matches)
+ return true;
+
+ return false;
+ };
+ root.RetinaImagePath = RetinaImagePath;
+
function RetinaImagePath(path) {
this.path = path;
this.at_2x_path = path.replace(/\.\w+$/, function(match) { return "@2x" + match; });
}
- root.RetinaImagePath = RetinaImagePath;
-
RetinaImagePath.confirmed_paths = [];
RetinaImagePath.prototype.is_external = function() {
@@ -113,8 +126,10 @@
- if (root.devicePixelRatio > 1) {
+
+ if (Retina.isRetina()) {
Retina.init(root);
}
})();
+
View
@@ -20,6 +20,9 @@ describe('Retina', function() {
it('stashes the existing onload and executes it later', function(){
var existingOnloadExecutions = 0;
var window = {
+ matchMedia : function() {
+ return { matches: false }
+ },
onload : function() {
existingOnloadExecutions++;
}
@@ -4,9 +4,19 @@ delete global.document;
global.document = {};
global.Image = require('./fixtures/image').Image;
global.XMLHttpRequest = require('./fixtures/xml_http_request').XMLHttpRequest;
-global.Retina = require('../').Retina;
-global.RetinaImage = require('../').RetinaImage;
-global.RetinaImagePath = require('../').RetinaImagePath;
+
+global.exports = {
+ devicePixelRatio : 0.9,
+ matchMedia : function() {
+ return {
+ matches : false
+ }
+ }
+}
+
+var Retina = require('../').Retina;
+var RetinaImage = require('../').RetinaImage;
+var RetinaImagePath = require('../').RetinaImagePath;
describe('RetinaImagePath', function() {

0 comments on commit 5671145

Please sign in to comment.