arnaucube
arnaucube/commonroutesAppPublic Self-hosted repository
commonroutesApp/www/lib/angular-material/modules/js/whiteframe/whiteframe.js
www/lib/angular-material/modules/js/whiteframe/whiteframe.jsRaw
 1/*!
 2 * Angular Material Design
 3 * https://github.com/angular/material
 4 * @license MIT
 5 * v1.1.1
 6 */
 7(function( window, angular, undefined ){
 8"use strict";
 9
10/**
11 * @ngdoc module
12 * @name material.components.whiteframe
13 */
14MdWhiteframeDirective.$inject = ["$log"];
15angular
16  .module('material.components.whiteframe', ['material.core'])
17  .directive('mdWhiteframe', MdWhiteframeDirective);
18
19/**
20 * @ngdoc directive
21 * @module material.components.whiteframe
22 * @name mdWhiteframe
23 *
24 * @description
25 * The md-whiteframe directive allows you to apply an elevation shadow to an element.
26 *
27 * The attribute values needs to be a number between 1 and 24 or -1.
28 * When set to -1 no style is applied.
29 *
30 * ### Notes
31 * - If there is no value specified it defaults to 4dp.
32 * - If the value is not valid it defaults to 4dp.
33
34 * @usage
35 * <hljs lang="html">
36 * <div md-whiteframe="3">
37 *   <span>Elevation of 3dp</span>
38 * </div>
39 * </hljs>
40 *
41 * <hljs lang="html">
42 * <div md-whiteframe="-1">
43 *   <span>No elevation shadow applied</span>
44 * </div>
45 * </hljs>
46 *
47 * <hljs lang="html">
48 * <div ng-init="elevation = 5" md-whiteframe="{{elevation}}">
49 *   <span>Elevation of 5dp with an interpolated value</span>
50 * </div>
51 * </hljs>
52 */
53function MdWhiteframeDirective($log) {
54  var DISABLE_DP = -1;
55  var MIN_DP = 1;
56  var MAX_DP = 24;
57  var DEFAULT_DP = 4;
58
59  return {
60    link: postLink
61  };
62
63  function postLink(scope, element, attr) {
64    var oldClass = '';
65
66    attr.$observe('mdWhiteframe', function(elevation) {
67      elevation = parseInt(elevation, 10) || DEFAULT_DP;
68
69      if (elevation != DISABLE_DP && (elevation > MAX_DP || elevation < MIN_DP)) {
70        $log.warn('md-whiteframe attribute value is invalid. It should be a number between ' + MIN_DP + ' and ' + MAX_DP, element[0]);
71        elevation = DEFAULT_DP;
72      }
73
74      var newClass = elevation == DISABLE_DP ? '' : 'md-whiteframe-' + elevation + 'dp';
75      attr.$updateClass(newClass, oldClass);
76      oldClass = newClass;
77    });
78  }
79}
80
81
82})(window, window.angular);