commonroutesApp/www/lib/angular-material/modules/closure/subheader/subheader.js
www/lib/angular-material/modules/closure/subheader/subheader.jsRaw
1/*!
2 * Angular Material Design
3 * https://github.com/angular/material
4 * @license MIT
5 * v1.1.1
6 */
7goog.provide('ngmaterial.components.subheader');
8goog.require('ngmaterial.components.sticky');
9goog.require('ngmaterial.core');
10/**
11 * @ngdoc module
12 * @name material.components.subheader
13 * @description
14 * SubHeader module
15 *
16 * Subheaders are special list tiles that delineate distinct sections of a
17 * list or grid list and are typically related to the current filtering or
18 * sorting criteria. Subheader tiles are either displayed inline with tiles or
19 * can be associated with content, for example, in an adjacent column.
20 *
21 * Upon scrolling, subheaders remain pinned to the top of the screen and remain
22 * pinned until pushed on or off screen by the next subheader. @see [Material
23 * Design Specifications](https://www.google.com/design/spec/components/subheaders.html)
24 *
25 * > To improve the visual grouping of content, use the system color for your subheaders.
26 *
27 */
28MdSubheaderDirective.$inject = ["$mdSticky", "$compile", "$mdTheming", "$mdUtil"];
29angular
30 .module('material.components.subheader', [
31 'material.core',
32 'material.components.sticky'
33 ])
34 .directive('mdSubheader', MdSubheaderDirective);
35
36/**
37 * @ngdoc directive
38 * @name mdSubheader
39 * @module material.components.subheader
40 *
41 * @restrict E
42 *
43 * @description
44 * The `md-subheader` directive creates a sticky subheader for a section.
45 *
46 * Developers are able to disable the stickiness of the subheader by using the following markup
47 *
48 * <hljs lang="html">
49 * <md-subheader class="md-no-sticky">Not Sticky</md-subheader>
50 * </hljs>
51 *
52 * ### Notes
53 * - The `md-subheader` directive uses the <a ng-href="api/service/$mdSticky">$mdSticky</a> service
54 * to make the subheader sticky.
55 *
56 * > Whenever the current browser doesn't support stickiness natively, the subheader
57 * will be compiled twice to create a sticky clone of the subheader.
58 *
59 * @usage
60 * <hljs lang="html">
61 * <md-subheader>Online Friends</md-subheader>
62 * </hljs>
63 */
64
65function MdSubheaderDirective($mdSticky, $compile, $mdTheming, $mdUtil) {
66 return {
67 restrict: 'E',
68 replace: true,
69 transclude: true,
70 template: (
71 '<div class="md-subheader _md">' +
72 ' <div class="md-subheader-inner">' +
73 ' <div class="md-subheader-content"></div>' +
74 ' </div>' +
75 '</div>'
76 ),
77 link: function postLink(scope, element, attr, controllers, transclude) {
78 $mdTheming(element);
79 element.addClass('_md');
80
81 // Remove the ngRepeat attribute from the root element, because we don't want to compile
82 // the ngRepeat for the sticky clone again.
83 $mdUtil.prefixer().removeAttribute(element, 'ng-repeat');
84
85 var outerHTML = element[0].outerHTML;
86
87 function getContent(el) {
88 return angular.element(el[0].querySelector('.md-subheader-content'));
89 }
90
91 // Transclude the user-given contents of the subheader
92 // the conventional way.
93 transclude(scope, function(clone) {
94 getContent(element).append(clone);
95 });
96
97 // Create another clone, that uses the outer and inner contents
98 // of the element, that will be 'stickied' as the user scrolls.
99 if (!element.hasClass('md-no-sticky')) {
100 transclude(scope, function(clone) {
101 // If the user adds an ng-if or ng-repeat directly to the md-subheader element, the
102 // compiled clone below will only be a comment tag (since they replace their elements with
103 // a comment) which cannot be properly passed to the $mdSticky; so we wrap it in our own
104 // DIV to ensure we have something $mdSticky can use
105 var wrapper = $compile('<div class="md-subheader-wrapper">' + outerHTML + '</div>')(scope);
106
107 // Delay initialization until after any `ng-if`/`ng-repeat`/etc has finished before
108 // attempting to create the clone
109 $mdUtil.nextTick(function() {
110 // Append our transcluded clone into the wrapper.
111 // We don't have to recompile the element again, because the clone is already
112 // compiled in it's transclusion scope. If we recompile the outerHTML of the new clone, we would lose
113 // our ngIf's and other previous registered bindings / properties.
114 getContent(wrapper).append(clone);
115 });
116
117 // Make the element sticky and provide the stickyClone our self, to avoid recompilation of the subheader
118 // element.
119 $mdSticky(scope, element, wrapper);
120 });
121 }
122 }
123 };
124}
125
126ngmaterial.components.subheader = angular.module("material.components.subheader");