angular-retina
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -1,2 +0,2 @@ | ||
/*! angular-retina - v0.1.3 - 2013-05-29 | ||
/*! angular-retina - v0.1.3 - 2013-06-22 | ||
* https://github.com/jrief/angular-retina | ||
@@ -9,7 +9,10 @@ * Copyright (c) 2013 Jacob Rief; Licensed MIT */ | ||
function ($provide) { | ||
$provide.decorator('ngSrcDirective', function ($delegate) { | ||
$delegate[0].compile = function (element, attrs) { | ||
}; | ||
return $delegate; | ||
}); | ||
$provide.decorator('ngSrcDirective', [ | ||
'$delegate', | ||
function ($delegate) { | ||
$delegate[0].compile = function (element, attrs) { | ||
}; | ||
return $delegate; | ||
} | ||
]); | ||
} | ||
@@ -19,5 +22,3 @@ ]).directive('ngSrc', [ | ||
'$http', | ||
'$cacheFactory', | ||
function ($window, $http, $cacheFactory) { | ||
var cache = $cacheFactory('retinaImageURLs'); | ||
function ($window, $http) { | ||
var msie = parseInt((/msie (\d+)/.exec($window.navigator.userAgent.toLowerCase()) || [])[1], 10); | ||
@@ -44,11 +45,11 @@ var isRetina = function () { | ||
function set2xVariant(img_url) { | ||
var img_url_2x = cache.get(img_url); | ||
if (img_url_2x === undefined) { | ||
var img_url_2x = $window.sessionStorage.getItem(img_url); | ||
if (!img_url_2x) { | ||
img_url_2x = getHighResolutionURL(img_url); | ||
$http.head(img_url_2x).success(function (data, status) { | ||
setImgSrc(img_url_2x); | ||
cache.put(img_url, img_url_2x); | ||
$window.sessionStorage.setItem(img_url, img_url_2x); | ||
}).error(function (data, status, headers, config) { | ||
setImgSrc(img_url); | ||
cache.put(img_url, img_url); | ||
$window.sessionStorage.setItem(img_url, img_url); | ||
}); | ||
@@ -62,3 +63,3 @@ } else { | ||
return; | ||
if (isRetina) { | ||
if (isRetina && typeof $window.sessionStorage === 'object') { | ||
set2xVariant(value); | ||
@@ -65,0 +66,0 @@ } else { |
@@ -1,4 +0,4 @@ | ||
/*! angular-retina - v0.1.3 - 2013-05-29 | ||
/*! angular-retina - v0.1.3 - 2013-06-22 | ||
* https://github.com/jrief/angular-retina | ||
* Copyright (c) 2013 Jacob Rief; Licensed MIT */ | ||
(function(e,n){"use strict";e.module("ngRetina",[]).config(["$provide",function(e){e.decorator("ngSrcDirective",function(e){return e[0].compile=function(){},e})}]).directive("ngSrc",["$window","$http","$cacheFactory",function(e,i,t){function r(e){var n=e.split(".");return 2>n.length?e:(n[n.length-2]+="@2x",n.join("."))}var c=t("retinaImageURLs"),o=parseInt((/msie (\d+)/.exec(e.navigator.userAgent.toLowerCase())||[])[1],10),a=function(){var n="(-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)";return e.devicePixelRatio>1?!0:e.matchMedia&&e.matchMedia(n).matches}();return function(e,t,u){function s(e){u.$set("src",e),o&&t.prop("src",e)}function d(e){var t=c.get(e);t===n?(t=r(e),i.head(t).success(function(){s(t),c.put(e,t)}).error(function(){s(e),c.put(e,e)})):s(t)}u.$observe("ngSrc",function(e){e&&(a?d(e):s(e))})}}])})(window.angular); | ||
(function(e){"use strict";e.module("ngRetina",[]).config(["$provide",function(e){e.decorator("ngSrcDirective",["$delegate",function(e){return e[0].compile=function(){},e}])}]).directive("ngSrc",["$window","$http",function(e,t){function n(e){var t=e.split(".");return 2>t.length?e:(t[t.length-2]+="@2x",t.join("."))}var i=parseInt((/msie (\d+)/.exec(e.navigator.userAgent.toLowerCase())||[])[1],10),o=function(){var t="(-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)";return e.devicePixelRatio>1?!0:e.matchMedia&&e.matchMedia(t).matches}();return function(r,c,s){function a(e){s.$set("src",e),i&&c.prop("src",e)}function u(i){var o=e.sessionStorage.getItem(i);o?a(o):(o=n(i),t.head(o).success(function(){a(o),e.sessionStorage.setItem(i,o)}).error(function(){a(i),e.sessionStorage.setItem(i,i)}))}s.$observe("ngSrc",function(t){t&&(o&&"object"==typeof e.sessionStorage?u(t):a(t))})}}])})(window.angular); |
@@ -65,2 +65,7 @@ 'use strict'; | ||
options: { | ||
browsers: ['ChromeCanary'] | ||
} | ||
}, | ||
testall: { | ||
options: { | ||
browsers: ['Safari', 'Chrome', 'ChromeCanary', 'Firefox', 'Opera'], | ||
@@ -94,2 +99,3 @@ singleRun: true | ||
grunt.registerTask('test', ['jshint', 'karma:test']); | ||
grunt.registerTask('testall', ['karma:testall']); | ||
grunt.registerTask('travis-ci', ['jshint', 'karma:travis-ci']); | ||
@@ -96,0 +102,0 @@ |
@@ -17,3 +17,3 @@ /* | ||
angular.module('ngRetina', []).config(function($provide) { | ||
$provide.decorator('ngSrcDirective', function($delegate) { | ||
$provide.decorator('ngSrcDirective', ['$delegate', function($delegate) { | ||
$delegate[0].compile = function(element, attrs) { | ||
@@ -23,6 +23,5 @@ // intentionally empty to override the built-in directive ng-src | ||
return $delegate; | ||
}); | ||
}]); | ||
}) | ||
.directive('ngSrc', function($window, $http, $cacheFactory) { | ||
var cache = $cacheFactory('retinaImageURLs'); | ||
.directive('ngSrc', function($window, $http) { | ||
var msie = parseInt(((/msie (\d+)/.exec($window.navigator.userAgent.toLowerCase()) || [])[1]), 10); | ||
@@ -52,4 +51,4 @@ var isRetina = (function() { | ||
function set2xVariant(img_url) { | ||
var img_url_2x = cache.get(img_url); | ||
if (img_url_2x === undefined) { | ||
var img_url_2x = $window.sessionStorage.getItem(img_url); | ||
if (!img_url_2x) { | ||
img_url_2x = getHighResolutionURL(img_url); | ||
@@ -59,7 +58,7 @@ $http.head(img_url_2x). | ||
setImgSrc(img_url_2x); | ||
cache.put(img_url, img_url_2x); | ||
$window.sessionStorage.setItem(img_url, img_url_2x); | ||
}). | ||
error(function(data, status, headers, config) { | ||
setImgSrc(img_url); | ||
cache.put(img_url, img_url); | ||
$window.sessionStorage.setItem(img_url, img_url); | ||
}); | ||
@@ -74,3 +73,3 @@ } else { | ||
return; | ||
if (isRetina) { | ||
if (isRetina && typeof $window.sessionStorage === 'object') { | ||
set2xVariant(value); | ||
@@ -77,0 +76,0 @@ } else { |
{ | ||
"name": "angular-retina", | ||
"description": "Replace AngularJS directive 'ng-src' by a version which supports Retina displays", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/jrief/angular-retina", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -74,2 +74,4 @@ # angular-retina | ||
0.1.0 - initial revision | ||
0.1.3 - fixed problems with minified JS code | ||
0.2.0 - using sessionStorage instead of $cacheFactory to boost performance | ||
@@ -76,0 +78,0 @@ ## License |
@@ -21,5 +21,3 @@ // Testacular configuration | ||
// list of files to exclude | ||
exclude = [ | ||
]; | ||
exclude = []; | ||
@@ -26,0 +24,0 @@ |
@@ -33,2 +33,7 @@ 'use strict'; | ||
afterEach(function() { | ||
window.sessionStorage.removeItem("/image.png"); | ||
window.sessionStorage.removeItem("/picture.png"); | ||
}); | ||
describe('for static "ng-src" tags', function() { | ||
@@ -35,0 +40,0 @@ it('should set src tag with a highres image', inject(function($compile) { |
627786
16751
80