|
1 | | -angular.module('toastBasicDemo', ['ngMaterial']) |
| 1 | +(function() { |
| 2 | + angular.module('toastBasicDemo', ['ngMaterial']) |
| 3 | + .controller('AppCtrl', AppCtrl); |
2 | 4 |
|
3 | | -.controller('AppCtrl', function($scope, $mdToast) { |
4 | | - var last = { |
| 5 | + function AppCtrl($mdToast, $log) { |
| 6 | + var ctrl = this; |
| 7 | + var last = { |
5 | 8 | bottom: false, |
6 | 9 | top: true, |
7 | 10 | left: false, |
8 | 11 | right: true |
9 | 12 | }; |
10 | 13 |
|
11 | | - $scope.toastPosition = angular.extend({},last); |
| 14 | + ctrl.toastPosition = angular.extend({}, last); |
12 | 15 |
|
13 | | - $scope.getToastPosition = function() { |
14 | | - sanitizePosition(); |
| 16 | + ctrl.getToastPosition = function() { |
| 17 | + sanitizePosition(); |
15 | 18 |
|
16 | | - return Object.keys($scope.toastPosition) |
17 | | - .filter(function(pos) { return $scope.toastPosition[pos]; }) |
18 | | - .join(' '); |
19 | | - }; |
| 19 | + return Object.keys(ctrl.toastPosition) |
| 20 | + .filter(function(pos) { |
| 21 | + return ctrl.toastPosition[pos]; |
| 22 | + }).join(' '); |
| 23 | + }; |
20 | 24 |
|
21 | | - function sanitizePosition() { |
22 | | - var current = $scope.toastPosition; |
| 25 | + function sanitizePosition() { |
| 26 | + var current = ctrl.toastPosition; |
23 | 27 |
|
24 | | - if ( current.bottom && last.top ) current.top = false; |
25 | | - if ( current.top && last.bottom ) current.bottom = false; |
26 | | - if ( current.right && last.left ) current.left = false; |
27 | | - if ( current.left && last.right ) current.right = false; |
| 28 | + if (current.bottom && last.top) { |
| 29 | + current.top = false; |
| 30 | + } |
| 31 | + if (current.top && last.bottom) { |
| 32 | + current.bottom = false; |
| 33 | + } |
| 34 | + if (current.right && last.left) { |
| 35 | + current.left = false; |
| 36 | + } |
| 37 | + if (current.left && last.right) { |
| 38 | + current.right = false; |
| 39 | + } |
28 | 40 |
|
29 | | - last = angular.extend({},current); |
30 | | - } |
| 41 | + last = angular.extend({}, current); |
| 42 | + } |
31 | 43 |
|
32 | | - $scope.showSimpleToast = function() { |
33 | | - var pinTo = $scope.getToastPosition(); |
| 44 | + ctrl.showSimpleToast = function() { |
| 45 | + var pinTo = ctrl.getToastPosition(); |
34 | 46 |
|
35 | | - $mdToast.show( |
36 | | - $mdToast.simple() |
| 47 | + $mdToast.show( |
| 48 | + $mdToast.simple() |
37 | 49 | .textContent('Simple Toast!') |
38 | 50 | .position(pinTo) |
39 | | - .hideDelay(3000) |
40 | | - ); |
41 | | - }; |
42 | | - |
43 | | - $scope.showActionToast = function() { |
44 | | - var pinTo = $scope.getToastPosition(); |
45 | | - var toast = $mdToast.simple() |
46 | | - .textContent('Marked as read') |
47 | | - .actionKey('z') |
48 | | - .actionHint('Press the Control-"z" key combination to ') |
49 | | - .action('UNDO') |
50 | | - .dismissHint('Activate the Escape key to dismiss this toast.') |
51 | | - .highlightAction(true) |
52 | | - .highlightClass('md-accent') // Accent is used by default, this just demonstrates the usage. |
53 | | - .position(pinTo) |
54 | | - .hideDelay(0); |
55 | | - |
56 | | - $mdToast.show(toast).then(function(response) { |
57 | | - if (response === 'ok') { |
58 | | - alert('You selected the \'UNDO\' action.'); |
59 | | - } |
60 | | - }); |
61 | | - }; |
| 51 | + .hideDelay(3000)) |
| 52 | + .then(function() { |
| 53 | + $log.log('Toast dismissed.'); |
| 54 | + }).catch(function() { |
| 55 | + $log.log('Toast failed or was forced to close early by another toast.'); |
| 56 | + }); |
| 57 | + }; |
62 | 58 |
|
63 | | -}) |
| 59 | + ctrl.showActionToast = function() { |
| 60 | + var pinTo = ctrl.getToastPosition(); |
| 61 | + var toast = $mdToast.simple() |
| 62 | + .textContent('Marked as read') |
| 63 | + .actionKey('z') |
| 64 | + .actionHint('Press the Control-"z" key combination to ') |
| 65 | + .action('UNDO') |
| 66 | + .dismissHint('Activate the Escape key to dismiss this toast.') |
| 67 | + .highlightAction(true) |
| 68 | + // Accent is used by default, this just demonstrates the usage. |
| 69 | + .highlightClass('md-accent') |
| 70 | + .position(pinTo) |
| 71 | + .hideDelay(0); |
64 | 72 |
|
65 | | -.controller('ToastCtrl', function($scope, $mdToast) { |
66 | | - $scope.closeToast = function() { |
67 | | - $mdToast.hide(); |
68 | | - }; |
69 | | -}); |
| 73 | + $mdToast.show(toast) |
| 74 | + .then(function(response) { |
| 75 | + if (response === 'ok') { |
| 76 | + alert('You selected the \'UNDO\' action.'); |
| 77 | + } else { |
| 78 | + $log.log('Toast dismissed.'); |
| 79 | + } |
| 80 | + }).catch(function() { |
| 81 | + $log.log('Toast failed or was forced to close early by another toast.'); |
| 82 | + }); |
| 83 | + }; |
| 84 | + } |
| 85 | +})(); |
0 commit comments