jellyfin-web/dashboard-ui/bower_components/iron-overlay-behavior/iron-overlay-backdrop.html

165 lines
4.2 KiB
HTML
Raw Normal View History

2015-06-19 09:36:51 -07:00
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<!--
`iron-overlay-backdrop` is a backdrop used by `Polymer.IronOverlayBehavior`. It should be a
singleton.
### Styling
The following custom properties and mixins are available for styling.
Custom property | Description | Default
-------------------------------------------|------------------------|---------
`--iron-overlay-backdrop-background-color` | Backdrop background color | #000
`--iron-overlay-backdrop-opacity` | Backdrop opacity | 0.6
`--iron-overlay-backdrop` | Mixin applied to `iron-overlay-backdrop`. | {}
`--iron-overlay-backdrop-opened` | Mixin applied to `iron-overlay-backdrop` when it is displayed | {}
-->
<dom-module id="iron-overlay-backdrop">
<style>
:host {
position: fixed;
top: 0;
left: 0;
2016-04-15 12:20:04 -07:00
width: 100%;
height: 100%;
2015-06-19 09:36:51 -07:00
background-color: var(--iron-overlay-backdrop-background-color, #000);
opacity: 0;
transition: opacity 0.2s;
2016-03-19 12:39:52 -07:00
pointer-events: none;
2015-06-19 09:36:51 -07:00
@apply(--iron-overlay-backdrop);
}
2016-05-03 19:18:05 -07:00
:host(.opened) {
2015-06-19 09:36:51 -07:00
opacity: var(--iron-overlay-backdrop-opacity, 0.6);
2016-03-19 12:39:52 -07:00
pointer-events: auto;
2015-06-19 09:36:51 -07:00
@apply(--iron-overlay-backdrop-opened);
}
</style>
<template>
<content></content>
</template>
</dom-module>
<script>
(function() {
2016-05-03 19:18:05 -07:00
'use strict';
2015-06-19 09:36:51 -07:00
Polymer({
is: 'iron-overlay-backdrop',
properties: {
/**
* Returns true if the backdrop is opened.
*/
opened: {
reflectToAttribute: true,
type: Boolean,
2016-05-03 19:18:05 -07:00
value: false,
observer: '_openedChanged'
2015-06-19 09:36:51 -07:00
}
},
2016-01-29 19:43:11 -07:00
listeners: {
2016-05-03 19:18:05 -07:00
'transitionend': '_onTransitionend'
},
created: function() {
// Used to cancel previous requestAnimationFrame calls when opened changes.
this.__openedRaf = null;
},
attached: function() {
this.opened && this._openedChanged(this.opened);
2016-01-29 19:43:11 -07:00
},
2015-06-19 09:36:51 -07:00
/**
2016-05-03 19:18:05 -07:00
* Appends the backdrop to document body if needed.
2015-06-19 09:36:51 -07:00
*/
prepare: function() {
2016-05-03 19:18:05 -07:00
if (this.opened && !this.parentNode) {
2015-06-19 09:36:51 -07:00
Polymer.dom(document.body).appendChild(this);
}
},
/**
2016-05-03 19:18:05 -07:00
* Shows the backdrop.
2015-06-19 09:36:51 -07:00
*/
open: function() {
2016-05-03 19:18:05 -07:00
this.opened = true;
2015-06-19 09:36:51 -07:00
},
/**
2016-05-03 19:18:05 -07:00
* Hides the backdrop.
2015-06-19 09:36:51 -07:00
*/
close: function() {
2016-05-03 19:18:05 -07:00
this.opened = false;
2015-06-19 09:36:51 -07:00
},
/**
* Removes the backdrop from document body if needed.
*/
complete: function() {
2016-05-03 19:18:05 -07:00
if (!this.opened && this.parentNode === document.body) {
2015-06-19 09:36:51 -07:00
Polymer.dom(this.parentNode).removeChild(this);
}
2016-01-29 19:43:11 -07:00
},
2016-05-03 19:18:05 -07:00
_onTransitionend: function(event) {
2016-01-29 19:43:11 -07:00
if (event && event.target === this) {
this.complete();
}
2016-05-03 19:18:05 -07:00
},
_openedChanged: function() {
if (this.opened) {
// Auto-attach.
this.prepare();
} else {
// Animation might be disabled via the mixin or opacity custom property.
// If it is disabled in other ways, it's up to the user to call complete.
var cs = window.getComputedStyle(this);
if (cs.transitionDuration === '0s' || cs.opacity == 0) {
this.complete();
}
}
if (!this.isAttached) {
return;
}
2015-06-19 09:36:51 -07:00
2016-05-03 19:18:05 -07:00
// Always cancel previous requestAnimationFrame.
if (this.__openedRaf) {
window.cancelAnimationFrame(this.__openedRaf);
this.__openedRaf = null;
}
// Force relayout to ensure proper transitions.
this.scrollTop = this.scrollTop;
this.__openedRaf = window.requestAnimationFrame(function() {
this.__openedRaf = null;
this.toggleClass('opened', this.opened);
}.bind(this));
}
2015-06-19 09:36:51 -07:00
});
})();
</script>