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