Skip to content
Navigation Menu
{{ message }}
forked from angular/bower-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-material.js
More file actions
7885 lines (6896 loc) · 251 KB
/
Copy pathangular-material.js
File metadata and controls
7885 lines (6896 loc) · 251 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
angular.module('ngMaterial', ["ng","ngAnimate","ngAria","material.core","material.core.theming","material.components.backdrop","material.components.bottomSheet","material.components.button","material.components.card","material.components.checkbox","material.components.content","material.components.dialog","material.components.divider","material.components.icon","material.components.input","material.components.list","material.components.progressCircular","material.components.progressLinear","material.components.radioButton","material.components.sidenav","material.components.slider","material.components.sticky","material.components.subheader","material.components.swipe","material.components.switch","material.components.tabs","material.components.textField","material.components.toast","material.components.toolbar","material.components.tooltip","material.components.whiteframe"]);
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function() {
'use strict';
/**
* Initialization function that validates environment
* requirements.
*/
angular.module('material.core', ['material.core.theming'])
.run(MdCoreInitialize)
.config(MdCoreConfigure);
function MdCoreInitialize() {
if (typeof Hammer === 'undefined') {
throw new Error(
'ngMaterial requires HammerJS to be preloaded.'
);
}
}
function MdCoreConfigure($provide, $mdThemingProvider) {
$provide.decorator('$$rAF', ['$delegate', '$rootScope', rAFDecorator]);
$mdThemingProvider.theme('default')
.primaryColor('blue')
.accentColor('green')
.warnColor('red')
.backgroundColor('grey');
function rAFDecorator($$rAF, $rootScope) {
/**
* Use this to debounce events that come in often.
* The debounced 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-debounced 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} callback function to debounce
*/
$$rAF.debounce = function(cb) {
var queueArgs, alreadyQueued, queueCb, context;
return function debounced() {
queueArgs = arguments;
context = this;
queueCb = cb;
if (!alreadyQueued) {
alreadyQueued = true;
$$rAF(function() {
queueCb.apply(context, queueArgs);
alreadyQueued = false;
});
}
};
};
return $$rAF;
}
}
MdCoreConfigure.$inject = ["$provide", "$mdThemingProvider"];
})();
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function() {
'use strict';
angular.module('material.core')
.factory('$mdConstant', MdConstantFactory);
function MdConstantFactory($$rAF, $sniffer) {
var webkit = /webkit/i.test($sniffer.vendorPrefix);
function vendorProperty(name) {
return webkit ? ('webkit' + name.charAt(0).toUpperCase() + name.substring(1)) : name;
}
return {
KEY_CODE: {
ENTER: 13,
ESCAPE: 27,
SPACE: 32,
LEFT_ARROW : 37,
UP_ARROW : 38,
RIGHT_ARROW : 39,
DOWN_ARROW : 40
},
CSS: {
/* Constants */
TRANSITIONEND: 'transitionend' + (webkit ? ' webkitTransitionEnd' : ''),
ANIMATIONEND: 'animationend' + (webkit ? ' webkitAnimationEnd' : ''),
TRANSFORM: vendorProperty('transform'),
TRANSITION: vendorProperty('transition'),
TRANSITION_DURATION: vendorProperty('transitionDuration'),
ANIMATION_PLAY_STATE: vendorProperty('animationPlayState'),
ANIMATION_DURATION: vendorProperty('animationDuration'),
ANIMATION_NAME: vendorProperty('animationName'),
ANIMATION_TIMING: vendorProperty('animationTimingFunction'),
ANIMATION_DIRECTION: vendorProperty('animationDirection')
},
MEDIA: {
'sm': '(max-width: 600px)',
'gt-sm': '(min-width: 600px)',
'md': '(min-width: 600px) and (max-width: 960px)',
'gt-md': '(min-width: 960px)',
'lg': '(min-width: 960px) and (max-width: 1200px)',
'gt-lg': '(min-width: 1200px)'
}
};
}
MdConstantFactory.$inject = ["$$rAF", "$sniffer"];
})();
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function(){
angular
.module('material.core')
.config( ["$provide", function($provide){
$provide.decorator('$mdUtil', ['$delegate', function ($delegate){
/**
* Inject the iterator facade to easily support iteration and accessors
* @see iterator below
*/
$delegate.iterator = Iterator;
return $delegate;
}
])
}]);
/**
* iterator is a list facade to easily support iteration and accessors
*
* @param items Array list which this iterator will enumerate
* @param reloop Boolean enables iterator to consider the list as an endless reloop
*/
function Iterator(items, reloop) {
var trueFn = function() { return true; };
reloop = !!reloop;
var _items = items || [ ];
// Published API
return {
items: getItems,
count: count,
inRange: inRange,
contains: contains,
indexOf: indexOf,
itemAt: itemAt,
findBy: findBy,
add: add,
remove: remove,
first: first,
last: last,
next: angular.bind(null, findSubsequentItem, false),
previous: angular.bind(null, findSubsequentItem, true),
hasPrevious: hasPrevious,
hasNext: hasNext
};
/**
* Publish copy of the enumerable set
* @returns {Array|*}
*/
function getItems() {
return [].concat(_items);
}
/**
* Determine length of the list
* @returns {Array.length|*|number}
*/
function count() {
return _items.length;
}
/**
* Is the index specified valid
* @param index
* @returns {Array.length|*|number|boolean}
*/
function inRange(index) {
return _items.length && ( index > -1 ) && (index < _items.length );
}
/**
* Can the iterator proceed to the next item in the list; relative to
* the specified item.
*
* @param item
* @returns {Array.length|*|number|boolean}
*/
function hasNext(item) {
return item ? inRange(indexOf(item) + 1) : false;
}
/**
* Can the iterator proceed to the previous item in the list; relative to
* the specified item.
*
* @param item
* @returns {Array.length|*|number|boolean}
*/
function hasPrevious(item) {
return item ? inRange(indexOf(item) - 1) : false;
}
/**
* Get item at specified index/position
* @param index
* @returns {*}
*/
function itemAt(index) {
return inRange(index) ? _items[index] : null;
}
/**
* Find all elements matching the key/value pair
* otherwise return null
*
* @param val
* @param key
*
* @return array
*/
function findBy(key, val) {
return _items.filter(function(item) {
return item[key] === val;
});
}
/**
* Add item to list
* @param item
* @param index
* @returns {*}
*/
function add(item, index) {
if ( !item ) return -1;
if (!angular.isNumber(index)) {
index = _items.length;
}
_items.splice(index, 0, item);
return indexOf(item);
}
/**
* Remove item from list...
* @param item
*/
function remove(item) {
if ( contains(item) ){
_items.splice(indexOf(item), 1);
}
}
/**
* Get the zero-based index of the target item
* @param item
* @returns {*}
*/
function indexOf(item) {
return _items.indexOf(item);
}
/**
* Boolean existence check
* @param item
* @returns {boolean}
*/
function contains(item) {
return item && (indexOf(item) > -1);
}
/**
* Return first item in the list
* @returns {*}
*/
function first() {
return _items.length ? _items[0] : null;
}
/**
* Return last item in the list...
* @returns {*}
*/
function last() {
return _items.length ? _items[_items.length - 1] : null;
}
/**
* Find the next item. If reloop is true and at the end of the list, it will
* go back to the first item. If given ,the `validate` callback will be used
* determine whether the next item is valid. If not valid, it will try to find the
* next item again.
* @param item
* @param {optional} validate function
* @param {optional} recursion limit
* @returns {*}
*/
function findSubsequentItem(backwards, item, validate, limit) {
validate = validate || trueFn;
var curIndex = indexOf(item);
if (!inRange(curIndex)) {
return null;
}
var nextIndex = curIndex + (backwards ? -1 : 1);
var foundItem = null;
if (inRange(nextIndex)) {
foundItem = _items[nextIndex];
} else if (reloop) {
foundItem = backwards ? last() : first();
nextIndex = indexOf(foundItem);
}
if ((foundItem === null) || (nextIndex === limit)) {
return null;
}
if (angular.isUndefined(limit)) {
limit = nextIndex;
}
return validate(foundItem) ? foundItem : findSubsequentItem(backwards, foundItem, validate, limit);
}
}
})();
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
angular.module('material.core')
.factory('$mdMedia', mdMediaFactory);
/**
* Exposes a function on the '$mdMedia' service which will return true or false,
* whether the given media query matches. Re-evaluates on resize. Allows presets
* for 'sm', 'md', 'lg'.
*
* @example $mdMedia('sm') == true if device-width <= sm
* @example $mdMedia('(min-width: 1200px)') == true if device-width >= 1200px
* @example $mdMedia('max-width: 300px') == true if device-width <= 300px (sanitizes input, adding parens)
*/
function mdMediaFactory($mdConstant, $mdUtil, $rootScope, $window) {
var queriesCache = $mdUtil.cacheFactory('$mdMedia:queries', {capacity: 15});
var resultsCache = $mdUtil.cacheFactory('$mdMedia:results', {capacity: 15});
angular.element($window).on('resize', updateAll);
return $mdMedia;
function $mdMedia(query) {
var validated = queriesCache.get(query);
if (angular.isUndefined(validated)) {
validated = queriesCache.put(query, validate(query));
}
var result = resultsCache.get(validated);
if (angular.isUndefined(result)) {
result = add(validated);
}
return result;
}
function validate(query) {
return $mdConstant.MEDIA[query] ||
((query.charAt(0) !== '(') ? ('(' + query + ')') : query);
}
function add(query) {
return resultsCache.put(query, !!$window.matchMedia(query).matches);
}
function updateAll() {
var keys = resultsCache.keys();
var len = keys.length;
if (len) {
for (var i = 0; i < len; i++) {
add(keys[i]);
}
// Trigger a $digest() if not already in progress
$rootScope.$evalAsync();
}
}
}
mdMediaFactory.$inject = ["$mdConstant", "$mdUtil", "$rootScope", "$window"];
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function() {
'use strict';
/*
* This var has to be outside the angular factory, otherwise when
* there are multiple material apps on the same page, each app
* will create its own instance of this array and the app's IDs
* will not be unique.
*/
var nextUniqueId = ['0','0','0'];
angular.module('material.core')
.factory('$mdUtil', ["$cacheFactory", "$document", "$timeout", function($cacheFactory, $document, $timeout) {
var Util;
return Util = {
now: window.performance ? angular.bind(window.performance, window.performance.now) : Date.now,
attachDragBehavior: attachDragBehavior,
elementRect: function(element, offsetParent) {
var node = element[0];
offsetParent = offsetParent || node.offsetParent || document.body;
offsetParent = offsetParent[0] || offsetParent;
var nodeRect = node.getBoundingClientRect();
var parentRect = offsetParent.getBoundingClientRect();
return {
left: nodeRect.left - parentRect.left + offsetParent.scrollLeft,
top: nodeRect.top - parentRect.top + offsetParent.scrollTop,
width: nodeRect.width,
height: nodeRect.height
};
},
fakeNgModel: function() {
return {
$setViewValue: function(value) {
this.$viewValue = value;
this.$render(value);
this.$viewChangeListeners.forEach(function(cb) { cb(); });
},
$parsers: [],
$formatters: [],
$viewChangeListeners: [],
$render: angular.noop
};
},
/**
* @see cacheFactory below
*/
cacheFactory: cacheFactory,
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds.
// @param wait Integer value of msecs to delay (since last debounce reset); default value 10 msecs
// @param invokeApply should the $timeout trigger $digest() dirty checking
debounce: function (func, wait, scope, invokeApply) {
var timer;
return function debounced() {
var context = scope,
args = Array.prototype.slice.call(arguments);
$timeout.cancel(timer);
timer = $timeout(function() {
timer = undefined;
func.apply(context, args);
}, wait || 10, invokeApply );
};
},
// Returns a function that can only be triggered every `delay` milliseconds.
// In other words, the function will not be called unless it has been more
// than `delay` milliseconds since the last call.
throttle: function throttle(func, delay) {
var recent;
return function throttled() {
var context = this;
var args = arguments;
var now = Util.now();
if (!recent || (now - recent > delay)) {
func.apply(context, args);
recent = now;
}
};
},
/**
* nextUid, from angular.js.
* A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric
* characters such as '012ABC'. The reason why we are not using simply a number counter is that
* the number string gets longer over time, and it can also overflow, where as the nextId
* will grow much slower, it is a string, and it will never overflow.
*
* @returns an unique alpha-numeric string
*/
nextUid: function() {
var index = nextUniqueId.length;
var digit;
while(index) {
index--;
digit = nextUniqueId[index].charCodeAt(0);
if (digit == 57 /*'9'*/) {
nextUniqueId[index] = 'A';
return nextUniqueId.join('');
}
if (digit == 90 /*'Z'*/) {
nextUniqueId[index] = '0';
} else {
nextUniqueId[index] = String.fromCharCode(digit + 1);
return nextUniqueId.join('');
}
}
nextUniqueId.unshift('0');
return nextUniqueId.join('');
},
// Stop watchers and events from firing on a scope without destroying it,
// by disconnecting it from its parent and its siblings' linked lists.
disconnectScope: function disconnectScope(scope) {
if (!scope) return;
// we can't destroy the root scope or a scope that has been already destroyed
if (scope.$root === scope) return;
if (scope.$$destroyed ) return;
var parent = scope.$parent;
scope.$$disconnected = true;
// See Scope.$destroy
if (parent.$$childHead === scope) parent.$$childHead = scope.$$nextSibling;
if (parent.$$childTail === scope) parent.$$childTail = scope.$$prevSibling;
if (scope.$$prevSibling) scope.$$prevSibling.$$nextSibling = scope.$$nextSibling;
if (scope.$$nextSibling) scope.$$nextSibling.$$prevSibling = scope.$$prevSibling;
scope.$$nextSibling = scope.$$prevSibling = null;
},
// Undo the effects of disconnectScope above.
reconnectScope: function reconnectScope(scope) {
if (!scope) return;
// we can't disconnect the root node or scope already disconnected
if (scope.$root === scope) return;
if (!scope.$$disconnected) return;
var child = scope;
var parent = child.$parent;
child.$$disconnected = false;
// See Scope.$new for this logic...
child.$$prevSibling = parent.$$childTail;
if (parent.$$childHead) {
parent.$$childTail.$$nextSibling = child;
parent.$$childTail = child;
} else {
parent.$$childHead = parent.$$childTail = child;
}
},
/*
* getClosest replicates jQuery.closest() to walk up the DOM tree until it finds a matching nodeName
*
* @param el Element to start walking the DOM from
* @param tagName Tag name to find closest to el, such as 'form'
*/
getClosest: function getClosest(el, tagName) {
tagName = tagName.toUpperCase();
do {
if (el.nodeName === tagName) {
return el;
}
} while (el = el.parentNode);
return null;
}
};
function attachDragBehavior(scope, element, options) {
// The state of the current drag & previous drag
var drag;
var previousDrag;
// Whether the pointer is currently down on this element.
var pointerIsDown;
var START_EVENTS = 'mousedown touchstart pointerdown';
var MOVE_EVENTS = 'mousemove touchmove pointermove';
var END_EVENTS = 'mouseup mouseleave touchend touchcancel pointerup pointercancel';
// Listen to move and end events on document. End events especially could have bubbled up
// from the child.
element.on(START_EVENTS, startDrag);
$document.on(MOVE_EVENTS, doDrag)
.on(END_EVENTS, endDrag);
scope.$on('$destroy', cleanup);
return cleanup;
function cleanup() {
if (cleanup.called) return;
cleanup.called = true;
element.off(START_EVENTS, startDrag);
$document.off(MOVE_EVENTS, doDrag)
.off(END_EVENTS, endDrag);
drag = pointerIsDown = false;
}
function startDrag(ev) {
var eventType = ev.type.charAt(0);
var now = Util.now();
// iOS & old android bug: after a touch event, iOS sends a click event 350 ms later.
// Don't allow a drag of a different pointerType than the previous drag if it has been
// less than 400ms.
if (previousDrag && previousDrag.pointerType !== eventType &&
(now - previousDrag.endTime < 400)) {
return;
}
if (pointerIsDown) return;
pointerIsDown = true;
drag = {
// Restrict this drag to whatever started it: if a mousedown started the drag,
// don't let anything but mouse events continue it.
pointerType: eventType,
startX: getPosition(ev),
startTime: now
};
element.one('$md.dragstart', function(ev) {
// Allow user to cancel by preventing default
if (ev.defaultPrevented) drag = null;
});
element.triggerHandler('$md.dragstart', drag);
}
function doDrag(ev) {
if (!drag || !isProperEventType(ev, drag)) return;
if (drag.pointerType === 't' || drag.pointerType === 'p') {
// No scrolling for touch/pointer events
ev.preventDefault();
}
updateDragState(ev);
element.triggerHandler('$md.drag', drag);
}
function endDrag(ev) {
pointerIsDown = false;
if (!drag || !isProperEventType(ev, drag)) return;
drag.endTime = Util.now();
updateDragState(ev);
element.triggerHandler('$md.dragend', drag);
previousDrag = drag;
drag = null;
}
function updateDragState(ev) {
var x = getPosition(ev);
drag.distance = drag.startX - x;
drag.direction = drag.distance > 0 ? 'left' : (drag.distance < 0 ? 'right' : '');
drag.duration = drag.startTime - Util.now();
drag.velocity = Math.abs(drag.duration) / drag.time;
}
function getPosition(ev) {
ev = ev.originalEvent || ev; //support jQuery events
var point = (ev.touches && ev.touches[0]) ||
(ev.changedTouches && ev.changedTouches[0]) ||
ev;
return point.pageX;
}
function isProperEventType(ev, drag) {
return drag && ev && (ev.type || '').charAt(0) === drag.pointerType;
}
}
/*
* Inject a 'keys()' method into Angular's $cacheFactory. Then
* head-hook all other methods
*
*/
function cacheFactory(id, options) {
var cache = $cacheFactory(id, options);
var keys = {};
cache._put = cache.put;
cache.put = function(k,v) {
keys[k] = true;
return cache._put(k, v);
};
cache._remove = cache.remove;
cache.remove = function(k) {
delete keys[k];
return cache._remove(k);
};
cache._removeAll = cache.removeAll;
cache.removeAll = function() {
keys = {};
return cache._removeAll();
};
cache._destroy = cache.destroy;
cache.destroy = function() {
keys = {};
return cache._destroy();
};
cache.keys = function() {
return Object.keys(keys);
};
return cache;
}
}]);
/*
* Since removing jQuery from the demos, some code that uses `element.focus()` is broken.
*
* We need to add `element.focus()`, because it's testable unlike `element[0].focus`.
*
* TODO(ajoslin): This should be added in a better place later.
*/
angular.element.prototype.focus = angular.element.prototype.focus || function() {
if (this.length) {
this[0].focus();
}
return this;
};
angular.element.prototype.blur = angular.element.prototype.blur || function() {
if (this.length) {
this[0].blur();
}
return this;
};
})();
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function() {
'use strict';
angular.module('material.core')
.service('$mdAria', AriaService);
function AriaService($$rAF, $log, $window) {
return {
expect: expect,
expectAsync: expectAsync,
expectWithText: expectWithText
};
/**
* Check if expected attribute has been specified on the target element or child
* @param element
* @param attrName
* @param {optional} defaultValue What to set the attr to if no value is found
*/
function expect(element, attrName, defaultValue) {
var node = element[0];
if (!node.hasAttribute(attrName) && !childHasAttribute(node, attrName)) {
defaultValue = angular.isString(defaultValue) && defaultValue.trim() || '';
if (defaultValue.length) {
element.attr(attrName, defaultValue);
} else {
$log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
}
}
}
function expectAsync(element, attrName, defaultValueGetter) {
// Problem: when retrieving the element's contents synchronously to find the label,
// the text may not be defined yet in the case of a binding.
// There is a higher chance that a binding will be defined if we wait one frame.
$$rAF(function() {
expect(element, attrName, defaultValueGetter());
});
}
function expectWithText(element, attrName) {
expectAsync(element, attrName, function() {
return element.text().trim();
});
}
function childHasAttribute(node, attrName) {
var hasChildren = node.hasChildNodes(),
hasAttr = false;
function isHidden(el) {
var style = el.currentStyle ? el.currentStyle : $window.getComputedStyle(el);
return (style.display === 'none');
}
if(hasChildren) {
var children = node.childNodes;
for(var i=0; i<children.length; i++){
var child = children[i];
if(child.nodeType === 1 && child.hasAttribute(attrName)) {
if(!isHidden(child)){
hasAttr = true;
}
}
}
}
return hasAttr;
}
}
AriaService.$inject = ["$$rAF", "$log", "$window"];
})();
/*!
* Angular Material Design
* https://github.com/angular/material
* @license MIT
* v0.7.0-rc2-master-416079b
*/
(function() {
'use strict';
angular.module('material.core')
.service('$mdCompiler', mdCompilerService);
function mdCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {
/*
* @ngdoc service
* @name $mdCompiler
* @module material.core
* @description
* The $mdCompiler service is an abstraction of angular's compiler, that allows the developer
* to easily compile an element with a templateUrl, controller, and locals.
*
* @usage
* <hljs lang="js">
* $mdCompiler.compile({
* templateUrl: 'modal.html',
* controller: 'ModalCtrl',
* locals: {
* modal: myModalInstance;
* }
* }).then(function(compileData) {
* compileData.element; // modal.html's template in an element
* compileData.link(myScope); //attach controller & scope to element
* });
* </hljs>
*/
/*
* @ngdoc method
* @name $mdCompiler#compile
* @description A helper to compile an HTML template/templateUrl with a given controller,
* locals, and scope.
* @param {object} options An options object, with the following properties:
*
* - `controller` - `{(string=|function()=}` Controller fn that should be associated with
* newly created scope or the name of a registered controller if passed as a string.
* - `controllerAs` - `{string=}` A controller alias name. If present the controller will be
* published to scope under the `controllerAs` name.
* - `template` - `{string=}` An html template as a string.
* - `templateUrl` - `{string=}` A path to an html template.
* - `transformTemplate` - `{function(template)=}` A function which transforms the template after
* it is loaded. It will be given the template string as a parameter, and should
* return a a new string representing the transformed template.
* - `resolve` - `{Object.<string, function>=}` - An optional map of dependencies which should
* be injected into the controller. If any of these dependencies are promises, the compiler
* will wait for them all to be resolved, or if one is rejected before the controller is
* instantiated `compile()` will fail..
* * `key` - `{string}`: a name of a dependency to be injected into the controller.
* * `factory` - `{string|function}`: If `string` then it is an alias for a service.
* Otherwise if function, then it is injected and the return value is treated as the
* dependency. If the result is a promise, it is resolved before its value is
* injected into the controller.
*
* @returns {object=} promise A promise, which will be resolved with a `compileData` object.
* `compileData` has the following properties:
*
* - `element` - `{element}`: an uncompiled element matching the provided template.
* - `link` - `{function(scope)}`: A link function, which, when called, will compile
* the element and instantiate the provided controller (if given).
* - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
* called. If `bindToController` is true, they will be coppied to the ctrl instead
* - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in
*/
this.compile = function(options) {
var templateUrl = options.templateUrl;
var template = options.template || '';
var controller = options.controller;
var controllerAs = options.controllerAs;
var resolve = options.resolve || {};
var locals = options.locals || {};
var transformTemplate = options.transformTemplate || angular.identity;
var bindToController = options.bindToController;
// Take resolve values and invoke them.
// Resolves can either be a string (value: 'MyRegisteredAngularConst'),
// or an invokable 'factory' of sorts: (value: function ValueGetter($dependency) {})
angular.forEach(resolve, function(value, key) {
if (angular.isString(value)) {
resolve[key] = $injector.get(value);
} else {
resolve[key] = $injector.invoke(value);
}
});
//Add the locals, which are just straight values to inject
//eg locals: { three: 3 }, will inject three into the controller
angular.extend(resolve, locals);
if (templateUrl) {
resolve.$template = $http.get(templateUrl, {cache: $templateCache})
.then(function(response) {
return response.data;
});
} else {
resolve.$template = $q.when(template);
}
// Wait for all the resolves to finish if they are promises
return $q.all(resolve).then(function(locals) {
var template = transformTemplate(locals.$template);
var element = angular.element('<div>').html(template.trim()).contents();
var linkFn = $compile(element);
//Return a linking function that can be used later when the element is ready
return {
locals: locals,
element: element,
link: function link(scope) {
locals.$scope = scope;
//Instantiate controller if it exists, because we have scope
if (controller) {
var ctrl = $controller(controller, locals);
if (bindToController) {
angular.extend(ctrl, locals);
}
//See angular-route source for this logic
element.data('$ngControllerController', ctrl);
element.children().data('$ngControllerController', ctrl);
if (controllerAs) {
scope[controllerAs] = ctrl;
You can’t perform that action at this time.
