This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
/
core.js
98 lines (90 loc) · 2.43 KB
/
core.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Initialization function that validates environment
* requirements.
*/
angular
.module('material.core', [
'ngAnimate',
'material.core.animate',
'material.core.layout',
'material.core.interaction',
'material.core.gestures',
'material.core.theming'
])
.config(MdCoreConfigure)
.run(DetectNgTouch);
/**
* Detect if the ng-Touch module is also being used.
* Warn if detected.
* @ngInject
*/
function DetectNgTouch($log, $injector) {
if ($injector.has('$swipe')) {
var msg = "" +
"You are using the ngTouch module. \n" +
"AngularJS Material already has mobile click, tap, and swipe support... \n" +
"ngTouch is not supported with AngularJS Material!";
$log.warn(msg);
}
}
/**
* @ngInject
*/
function MdCoreConfigure($provide, $mdThemingProvider) {
$provide.decorator('$$rAF', ['$delegate', rAFDecorator]);
$provide.decorator('$q', ['$delegate', qDecorator]);
$mdThemingProvider.theme('default')
.primaryPalette('indigo')
.accentPalette('pink')
.warnPalette('deep-orange')
.backgroundPalette('grey');
}
/**
* @ngInject
*/
function rAFDecorator($delegate) {
/**
* Use this to throttle events that come in often.
* The throttled function will always use the *last* invocation before the
* coming frame.
*
* For example, window resize events that fire many times a second:
* If we set to use an raf-throttled callback on window resize, then
* our callback will only be fired once per frame, with the last resize
* event that happened before that frame.
*
* @param {function} cb function to debounce
*/
$delegate.throttle = function(cb) {
var queuedArgs, alreadyQueued, queueCb, context;
return function debounced() {
queuedArgs = arguments;
context = this;
queueCb = cb;
if (!alreadyQueued) {
alreadyQueued = true;
$delegate(function() {
queueCb.apply(context, Array.prototype.slice.call(queuedArgs));
alreadyQueued = false;
});
}
};
};
return $delegate;
}
/**
* @ngInject
*/
function qDecorator($delegate) {
/**
* Adds a shim for $q.resolve for AngularJS version that don't have it,
* so we don't have to think about it.
*
* via https://github.com/angular/angular.js/pull/11987
*/
// TODO(crisbeto): this won't be necessary once we drop AngularJS 1.3
if (!$delegate.resolve) {
$delegate.resolve = $delegate.when;
}
return $delegate;
}