rhodecode-toast.html
233 lines
| 7.4 KiB
| text/html
|
HtmlLexer
r703 | <link rel="import" href="../../../../../../bower_components/paper-button/paper-button.html"> | |||
r3172 | <link rel="import" | |||
href="../../../../../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html"> | ||||
r703 | <link rel="import" href="../rhodecode-unsafe-html/rhodecode-unsafe-html.html"> | |||
<dom-module id="rhodecode-toast"> | ||||
<template> | ||||
r3171 | <style include="shared-styles"> | |||
/* inset border for buttons - does not work in ie */ | ||||
/* rounded borders */ | ||||
/* rounded borders - bottom only */ | ||||
/* rounded borders - top only */ | ||||
/* text shadow */ | ||||
/* centers text in a circle - input diameter of circle and color */ | ||||
/* pill version of the circle */ | ||||
.absolute-center { | ||||
margin: auto; | ||||
position: absolute; | ||||
top: 0; | ||||
left: 0; | ||||
bottom: 0; | ||||
right: 0; | ||||
} | ||||
r3172 | ||||
r3171 | .top-left-rounded-corner { | |||
-webkit-border-top-left-radius: 2px; | ||||
-khtml-border-radius-topleft: 2px; | ||||
border-top-left-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .top-right-rounded-corner { | |||
-webkit-border-top-right-radius: 2px; | ||||
-khtml-border-radius-topright: 2px; | ||||
border-top-right-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .bottom-left-rounded-corner { | |||
-webkit-border-bottom-left-radius: 2px; | ||||
-khtml-border-radius-bottomleft: 2px; | ||||
border-bottom-left-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .bottom-right-rounded-corner { | |||
-webkit-border-bottom-right-radius: 2px; | ||||
-khtml-border-radius-bottomright: 2px; | ||||
border-bottom-right-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .top-left-rounded-corner-mid { | |||
-webkit-border-top-left-radius: 2px; | ||||
-khtml-border-radius-topleft: 2px; | ||||
border-top-left-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .top-right-rounded-corner-mid { | |||
-webkit-border-top-right-radius: 2px; | ||||
-khtml-border-radius-topright: 2px; | ||||
border-top-right-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .bottom-left-rounded-corner-mid { | |||
-webkit-border-bottom-left-radius: 2px; | ||||
-khtml-border-radius-bottomleft: 2px; | ||||
border-bottom-left-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .bottom-right-rounded-corner-mid { | |||
-webkit-border-bottom-right-radius: 2px; | ||||
-khtml-border-radius-bottomright: 2px; | ||||
border-bottom-right-radius: 2px; | ||||
} | ||||
r3172 | ||||
r3171 | .alert { | |||
margin: 10px 0; | ||||
} | ||||
r3172 | ||||
r3171 | .toast-close { | |||
margin: 0; | ||||
float: right; | ||||
cursor: pointer; | ||||
} | ||||
r3172 | ||||
r3171 | .toast-message-holder { | |||
background: rgba(255, 255, 255, 0.25); | ||||
} | ||||
r3172 | ||||
r3171 | .toast-message-holder.fixed { | |||
position: fixed; | ||||
padding: 10px 0; | ||||
margin-left: 10px; | ||||
margin-right: 10px; | ||||
top: 0; | ||||
left: 0; | ||||
right: 0; | ||||
z-index: 100; | ||||
} | ||||
</style> | ||||
r1483 | <template is="dom-if" if="[[hasToasts]]"> | |||
r1484 | <div class$="container toast-message-holder [[conditionalClass(isFixed)]]"> | |||
r1483 | <template is="dom-repeat" items="[[toasts]]"> | |||
<div class$="alert alert-[[item.level]]"> | ||||
r3172 | <div on-click="dismissNotification" class="toast-close" index-pos="[[index]]"> | |||
r1513 | <span>[[_gettext('Close')]]</span> | |||
</div> | ||||
r1483 | <rhodecode-unsafe-html text="[[item.message]]"></rhodecode-unsafe-html> | |||
r703 | </div> | |||
</template> | ||||
</div> | ||||
r1483 | </template> | |||
r703 | </template> | |||
r3149 | <script> | |||
r3172 | ||||
class RhodecodeToast extends Polymer.mixinBehaviors([Polymer.IronA11yKeysBehavior], Polymer.Element) { | ||||
static get is() { | ||||
return 'rhodecode-toast'; | ||||
} | ||||
static get properties() { | ||||
return { | ||||
toasts: { | ||||
type: Array, | ||||
value() { | ||||
return [] | ||||
} | ||||
}, | ||||
isFixed: { | ||||
type: Boolean, | ||||
value: false | ||||
}, | ||||
hasToasts: { | ||||
type: Boolean, | ||||
computed: '_computeHasToasts(toasts.*)' | ||||
}, | ||||
keyEventTarget: { | ||||
type: Object, | ||||
value() { | ||||
return document.body; | ||||
} | ||||
r3149 | } | |||
} | ||||
r3172 | } | |||
get keyBindings() { | ||||
return { | ||||
'esc:keyup': '_hideOnEsc' | ||||
} | ||||
} | ||||
r3149 | ||||
r3172 | static get observers() { | |||
return [ | ||||
'_changedToasts(toasts.splices)' | ||||
] | ||||
} | ||||
r3149 | ||||
r3172 | _hideOnEsc(event) { | |||
r3149 | return this.dismissNotifications(); | |||
r3172 | } | |||
r3149 | ||||
r3172 | _computeHasToasts() { | |||
r3149 | return this.toasts.length > 0; | |||
r3172 | } | |||
r3149 | ||||
r3172 | _debouncedCalc() { | |||
r3149 | // calculate once in a while | |||
this.debounce('debouncedCalc', this.toastInWindow, 25); | ||||
r3172 | } | |||
r3149 | ||||
r3172 | conditionalClass() { | |||
return this.isFixed ? 'fixed' : ''; | ||||
} | ||||
r3149 | ||||
r3172 | toastInWindow() { | |||
if (!this._headerNode) { | ||||
r3149 | return true | |||
} | ||||
var headerHeight = this._headerNode.offsetHeight; | ||||
var scrollPosition = window.scrollY; | ||||
r3172 | if (this.isFixed) { | |||
r3149 | this.isFixed = 1 <= scrollPosition; | |||
} | ||||
r3172 | else { | |||
r3149 | this.isFixed = headerHeight <= scrollPosition; | |||
} | ||||
r3172 | } | |||
r3149 | ||||
r3172 | connectedCallback() { | |||
super.connectedCallback(); | ||||
r3149 | this._headerNode = document.querySelector('.header', document); | |||
r3172 | this.listen(window, 'scroll', '_debouncedCalc'); | |||
this.listen(window, 'resize', '_debouncedCalc'); | ||||
r3149 | this._debouncedCalc(); | |||
r3172 | } | |||
_changedToasts(newValue, oldValue) { | ||||
r3149 | $.Topic('/favicon/update').publish({count: this.toasts.length}); | |||
r3172 | } | |||
dismissNotification(e) { | ||||
$.Topic('/favicon/update').publish({count: this.toasts.length - 1}); | ||||
r3149 | var idx = e.target.parentNode.indexPos | |||
this.splice('toasts', idx, 1); | ||||
r3172 | } | |||
dismissNotifications() { | ||||
r3149 | $.Topic('/favicon/update').publish({count: 0}); | |||
this.splice('toasts', 0); | ||||
r3172 | } | |||
handleNotification(data) { | ||||
r3149 | if (!templateContext.rhodecode_user.notification_status && !data.message.force) { | |||
// do not act if notifications are disabled | ||||
return | ||||
} | ||||
r3172 | this.push('toasts', { | |||
r3149 | level: data.message.level, | |||
message: data.message.message | ||||
}); | ||||
r3172 | } | |||
_gettext(x){ | ||||
return _gettext(x) | ||||
} | ||||
} | ||||
customElements.define(RhodecodeToast.is, RhodecodeToast); | ||||
r3149 | ||||
</script> | ||||
r703 | </dom-module> | |||