-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathangular.media.js
More file actions
44 lines (41 loc) · 1.24 KB
/
angular.media.js
File metadata and controls
44 lines (41 loc) · 1.24 KB
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
36
37
38
39
40
41
42
43
44
angular.module('angular.media', [])
.provider('MediaQuery', function() {
this.shortcuts = {
'phone': '(max-width:480px)',
'tablet': '(min-width:481px) and (max-width:979px)',
'laptop': '(min-width:980px) and (max-width:1199px)',
'desktop': '(min-width:1200px)'
};
this.$get = function() {
var shortcuts = this.shortcuts;
return {
shortcuts: shortcuts
}
};
this.setShortcuts = function(shortcuts) {
this.shortcuts = shortcuts;
};
})
.factory('Media', function() {
return {};
})
.service('$media', ['MediaQuery', 'Media', '$rootScope', function(MediaQuery, Media, $rootScope) {
var Media = Media;
var shortcuts = MediaQuery.shortcuts;
return {
query: function(shortcut) {
return this.raw(shortcuts[shortcut]);
},
raw: function(raw_query) {
Media.value = window.matchMedia(raw_query).matches;
window.onresize = function(){
Media.value = window.matchMedia(raw_query).matches;
$rootScope.$apply();
}
return Media.value;
}
}
}])
.run(['$rootScope', '$media', function($rootScope, $media) {
$rootScope.$media = $media;
}]);