-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngMedia.js
35 lines (35 loc) · 1.04 KB
/
ngMedia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* ngMedia 0.0.1
* (c) 2015 Ahmed H. Ismail
* License: MIT
*/
(function() {
'use strict';
angular.module('angularMedia', [])
.directive('ifMedia', function($window, ngIfDirective) {
var ngIf = ngIfDirective[0];
return {
transclude: ngIf.transclude,
priority: ngIf.priority,
terminal: ngIf.terminal,
restrict: ngIf.restrict,
link: function($scope, $element, $attr) {
var initialNgIf = $attr.ngIf, ifEvaluator;
if (initialNgIf) {
ifEvaluator = function () {
return $scope.$eval(initialNgIf) && $window.matchMedia($attr.ifMedia).matches;
}
} else { // if there's no ng-if, process normally
ifEvaluator = function () {
return $window.matchMedia($attr.ifMedia).matches;
};
}
$attr.ngIf = ifEvaluator;
ngIf.link.apply(ngIf, arguments);
angular.element($window).bind('resize', function() {
$scope.$apply();
});
}
}
});
})();