Show More
@@ -1,24 +1,25 b'' | |||
|
1 | 1 | <link rel="import" href="../../../../../../bower_components/paper-button/paper-button.html"> |
|
2 | 2 | <link rel="import" href="../../../../../../bower_components/paper-toast/paper-toast.html"> |
|
3 | <link rel="import" href="../../../../../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html"> | |
|
3 | 4 | <link rel="import" href="../rhodecode-unsafe-html/rhodecode-unsafe-html.html"> |
|
4 | 5 | <dom-module id="rhodecode-toast"> |
|
5 | 6 | <template> |
|
6 | 7 | <style include="shared-styles"></style> |
|
7 | 8 | <link rel="stylesheet" href="rhodecode-toast.css"> |
|
8 | 9 | <template is="dom-if" if="[[hasToasts]]"> |
|
9 | 10 | <div class$="container toast-message-holder [[conditionalClass(isFixed)]]"> |
|
10 | 11 | <template is="dom-repeat" items="[[toasts]]"> |
|
11 | 12 | <div class$="alert alert-[[item.level]]"> |
|
12 | 13 | <rhodecode-unsafe-html text="[[item.message]]"></rhodecode-unsafe-html> |
|
13 | 14 | </div> |
|
14 | 15 | </template> |
|
15 | 16 | |
|
16 | 17 | <div class="toast-close"> |
|
17 | 18 | <button on-tap="dismissNotifications" class="btn btn-default">[[_gettext('Close')]]</button> |
|
18 | 19 | </div> |
|
19 | 20 | </div> |
|
20 | 21 | </template> |
|
21 | 22 | </template> |
|
22 | 23 | |
|
23 | 24 | <script src="rhodecode-toast.js"></script> |
|
24 | 25 | </dom-module> |
@@ -1,75 +1,92 b'' | |||
|
1 | 1 | Polymer({ |
|
2 | 2 | is: 'rhodecode-toast', |
|
3 | 3 | properties: { |
|
4 | 4 | toasts: { |
|
5 | 5 | type: Array, |
|
6 | 6 | value: function(){ |
|
7 | 7 | return [] |
|
8 | 8 | } |
|
9 | 9 | }, |
|
10 | 10 | isFixed: { |
|
11 | 11 | type: Boolean, |
|
12 | 12 | value: false |
|
13 | 13 | }, |
|
14 | 14 | hasToasts: { |
|
15 | 15 | type: Boolean, |
|
16 | 16 | computed: '_computeHasToasts(toasts.*)' |
|
17 | }, | |
|
18 | keyEventTarget: { | |
|
19 | type: Object, | |
|
20 | value: function() { | |
|
21 | return document.body; | |
|
22 | } | |
|
17 | 23 | } |
|
18 | 24 | }, |
|
25 | behaviors: [ | |
|
26 | Polymer.IronA11yKeysBehavior | |
|
27 | ], | |
|
19 | 28 | observers: [ |
|
20 | 29 | '_changedToasts(toasts.splices)' |
|
21 | 30 | ], |
|
22 | 31 | |
|
32 | keyBindings: { | |
|
33 | 'esc:keyup': '_hideOnEsc' | |
|
34 | }, | |
|
35 | ||
|
36 | _hideOnEsc: function (event) { | |
|
37 | return this.dismissNotifications(); | |
|
38 | }, | |
|
39 | ||
|
23 | 40 | _computeHasToasts: function(){ |
|
24 | 41 | return this.toasts.length > 0; |
|
25 | 42 | }, |
|
26 | 43 | |
|
27 | 44 | _debouncedCalc: function(){ |
|
28 | 45 | // calculate once in a while |
|
29 | 46 | this.debounce('debouncedCalc', this.toastInWindow, 25); |
|
30 | 47 | }, |
|
31 | 48 | |
|
32 | 49 | conditionalClass: function(){ |
|
33 | 50 | return this.isFixed ? 'fixed': ''; |
|
34 | 51 | }, |
|
35 | 52 | |
|
36 | 53 | toastInWindow: function() { |
|
37 | 54 | if (!this._headerNode){ |
|
38 | 55 | return true |
|
39 | 56 | } |
|
40 | 57 | var headerHeight = this._headerNode.offsetHeight; |
|
41 | 58 | var scrollPosition = window.scrollY; |
|
42 | 59 | |
|
43 | 60 | if (this.isFixed){ |
|
44 | 61 | this.isFixed = 1 <= scrollPosition; |
|
45 | 62 | } |
|
46 | 63 | else{ |
|
47 | 64 | this.isFixed = headerHeight <= scrollPosition; |
|
48 | 65 | } |
|
49 | 66 | }, |
|
50 | 67 | |
|
51 | 68 | attached: function(){ |
|
52 | 69 | this._headerNode = document.querySelector('.header', document); |
|
53 | 70 | this.listen(window,'scroll', '_debouncedCalc'); |
|
54 | 71 | this.listen(window,'resize', '_debouncedCalc'); |
|
55 | 72 | this._debouncedCalc(); |
|
56 | 73 | }, |
|
57 | 74 | _changedToasts: function(newValue, oldValue){ |
|
58 | 75 | $.Topic('/favicon/update').publish({count: this.toasts.length}); |
|
59 | 76 | }, |
|
60 | 77 | dismissNotifications: function(){ |
|
61 | 78 | $.Topic('/favicon/update').publish({count: 0}); |
|
62 | 79 | this.splice('toasts', 0); |
|
63 | 80 | }, |
|
64 | 81 | handleNotification: function(data){ |
|
65 | 82 | if (!templateContext.rhodecode_user.notification_status && !data.message.force) { |
|
66 | 83 | // do not act if notifications are disabled |
|
67 | 84 | return |
|
68 | 85 | } |
|
69 | 86 | this.push('toasts',{ |
|
70 | 87 | level: data.message.level, |
|
71 | 88 | message: data.message.message |
|
72 | 89 | }); |
|
73 | 90 | }, |
|
74 | 91 | _gettext: _gettext |
|
75 | 92 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now