rhodecode-toast.js
92 lines
| 2.3 KiB
| application/javascript
|
JavascriptLexer
r703 | Polymer({ | |||
is: 'rhodecode-toast', | ||||
properties: { | ||||
toasts: { | ||||
type: Array, | ||||
value: function(){ | ||||
return [] | ||||
} | ||||
r1483 | }, | |||
isFixed: { | ||||
type: Boolean, | ||||
value: false | ||||
}, | ||||
hasToasts: { | ||||
type: Boolean, | ||||
computed: '_computeHasToasts(toasts.*)' | ||||
r1486 | }, | |||
keyEventTarget: { | ||||
type: Object, | ||||
value: function() { | ||||
return document.body; | ||||
} | ||||
r703 | } | |||
}, | ||||
r1486 | behaviors: [ | |||
Polymer.IronA11yKeysBehavior | ||||
], | ||||
r703 | observers: [ | |||
'_changedToasts(toasts.splices)' | ||||
], | ||||
r1483 | ||||
r1486 | keyBindings: { | |||
'esc:keyup': '_hideOnEsc' | ||||
}, | ||||
_hideOnEsc: function (event) { | ||||
return this.dismissNotifications(); | ||||
}, | ||||
r1483 | _computeHasToasts: function(){ | |||
return this.toasts.length > 0; | ||||
}, | ||||
_debouncedCalc: function(){ | ||||
// calculate once in a while | ||||
this.debounce('debouncedCalc', this.toastInWindow, 25); | ||||
}, | ||||
conditionalClass: function(){ | ||||
return this.isFixed ? 'fixed': ''; | ||||
}, | ||||
toastInWindow: function() { | ||||
if (!this._headerNode){ | ||||
return true | ||||
} | ||||
var headerHeight = this._headerNode.offsetHeight; | ||||
var scrollPosition = window.scrollY; | ||||
if (this.isFixed){ | ||||
this.isFixed = 1 <= scrollPosition; | ||||
} | ||||
else{ | ||||
this.isFixed = headerHeight <= scrollPosition; | ||||
} | ||||
}, | ||||
attached: function(){ | ||||
this._headerNode = document.querySelector('.header', document); | ||||
this.listen(window,'scroll', '_debouncedCalc'); | ||||
this.listen(window,'resize', '_debouncedCalc'); | ||||
this._debouncedCalc(); | ||||
}, | ||||
r703 | _changedToasts: function(newValue, oldValue){ | |||
r882 | $.Topic('/favicon/update').publish({count: this.toasts.length}); | |||
r703 | }, | |||
dismissNotifications: function(){ | ||||
r882 | $.Topic('/favicon/update').publish({count: 0}); | |||
r703 | this.splice('toasts', 0); | |||
}, | ||||
r787 | handleNotification: function(data){ | |||
if (!templateContext.rhodecode_user.notification_status && !data.message.force) { | ||||
// do not act if notifications are disabled | ||||
return | ||||
} | ||||
this.push('toasts',{ | ||||
level: data.message.level, | ||||
message: data.message.message | ||||
}); | ||||
}, | ||||
r703 | _gettext: _gettext | |||
}); | ||||