mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-16 00:06:15 +10:00
Merge pull request #2335 from jrief/angular-retina
Added package angular-retina [Jacob Rief]
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
/*! angular-retina - v0.2.2 - 2013-12-13
|
||||
* https://github.com/jrief/angular-retina
|
||||
* Copyright (c) 2013 Jacob Rief; Licensed MIT */
|
||||
(function (angular, undefined) {
|
||||
'use strict';
|
||||
angular.module('ngRetina', []).config([
|
||||
'$provide',
|
||||
function ($provide) {
|
||||
$provide.decorator('ngSrcDirective', [
|
||||
'$delegate',
|
||||
function ($delegate) {
|
||||
$delegate[0].compile = function (element, attrs) {
|
||||
};
|
||||
return $delegate;
|
||||
}
|
||||
]);
|
||||
}
|
||||
]).directive('ngSrc', [
|
||||
'$window',
|
||||
'$http',
|
||||
function ($window, $http) {
|
||||
var msie = parseInt((/msie (\d+)/.exec($window.navigator.userAgent.toLowerCase()) || [])[1], 10);
|
||||
var 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 ($window.devicePixelRatio > 1)
|
||||
return true;
|
||||
return $window.matchMedia && $window.matchMedia(mediaQuery).matches;
|
||||
}();
|
||||
function getHighResolutionURL(url) {
|
||||
var parts = url.split('.');
|
||||
if (parts.length < 2)
|
||||
return url;
|
||||
parts[parts.length - 2] += '@2x';
|
||||
return parts.join('.');
|
||||
}
|
||||
return function (scope, element, attrs) {
|
||||
function setImgSrc(img_url) {
|
||||
attrs.$set('src', img_url);
|
||||
if (msie)
|
||||
element.prop('src', img_url);
|
||||
}
|
||||
function set2xVariant(img_url) {
|
||||
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);
|
||||
$window.sessionStorage.setItem(img_url, img_url_2x);
|
||||
}).error(function (data, status, headers, config) {
|
||||
setImgSrc(img_url);
|
||||
$window.sessionStorage.setItem(img_url, img_url);
|
||||
});
|
||||
} else {
|
||||
setImgSrc(img_url_2x);
|
||||
}
|
||||
}
|
||||
attrs.$observe('ngSrc', function (value) {
|
||||
if (!value)
|
||||
return;
|
||||
if (isRetina && typeof $window.sessionStorage === 'object') {
|
||||
set2xVariant(value);
|
||||
} else {
|
||||
setImgSrc(value);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
]);
|
||||
}(window.angular));
|
||||
@@ -0,0 +1,4 @@
|
||||
/*! angular-retina - v0.2.2 - 2013-12-13
|
||||
* https://github.com/jrief/angular-retina
|
||||
* Copyright (c) 2013 Jacob Rief; Licensed MIT */
|
||||
!function(a){"use strict";a.module("ngRetina",[]).config(["$provide",function(a){a.decorator("ngSrcDirective",["$delegate",function(a){return a[0].compile=function(){},a}])}]).directive("ngSrc",["$window","$http",function(a,b){function c(a){var b=a.split(".");return b.length<2?a:(b[b.length-2]+="@2x",b.join("."))}var d=parseInt((/msie (\d+)/.exec(a.navigator.userAgent.toLowerCase())||[])[1],10),e=function(){var b="(-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 a.devicePixelRatio>1?!0:a.matchMedia&&a.matchMedia(b).matches}();return function(f,g,h){function i(a){h.$set("src",a),d&&g.prop("src",a)}function j(d){var e=a.sessionStorage.getItem(d);e?i(e):(e=c(d),b.head(e).success(function(){i(e),a.sessionStorage.setItem(d,e)}).error(function(){i(d),a.sessionStorage.setItem(d,d)}))}h.$observe("ngSrc",function(b){b&&(e&&"object"==typeof a.sessionStorage?j(b):i(b))})}}])}(window.angular);
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "angular-retina",
|
||||
"filename":"angular-retina.min.js",
|
||||
"description": "Replaces the AngularJS directive ng-src by a version which supports Retina displays",
|
||||
"version": "0.2.2",
|
||||
"homepage": "https://github.com/jrief/angular-retina",
|
||||
"keywords": [
|
||||
"AngularJS",
|
||||
"Retina",
|
||||
"High resolution displays",
|
||||
"directives",
|
||||
"angular",
|
||||
"angular.js"
|
||||
],
|
||||
"repositories": [{
|
||||
"type": "git",
|
||||
"url": "git://github.com/jrief/angular-retina.git"
|
||||
}],
|
||||
"author": [{
|
||||
"name": "Jacob Rief",
|
||||
"email": "jacob.rief@gmail.com"
|
||||
}],
|
||||
"licenses": [{
|
||||
"type": "MIT",
|
||||
"url": "https://github.com/jrief/angular-retina/blob/master/LICENSE-MIT"
|
||||
}]
|
||||
}
|
||||
Reference in New Issue
Block a user