|
| 1 | +<link rel="import" href="../polymer/polymer.html"> |
| 2 | +<link rel="import" href="../overlay-container/animated-overlay-behavior.html"> |
| 3 | +<link rel="import" href="../app-localize-behavior/app-localize-behavior.html"> |
| 4 | +<link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> |
| 5 | +<link rel="import" href="../offthread-image/offthread-image.html"> |
| 6 | + |
| 7 | +<!-- |
| 8 | +`file-uploader-completed-overlay` |
| 9 | +
|
| 10 | +@demo demo/index.html |
| 11 | +--> |
| 12 | +<dom-module id="file-uploader-completed-overlay"> |
| 13 | + <template> |
| 14 | + <style> |
| 15 | + :host { |
| 16 | + background: white; |
| 17 | + border-radius: 4px; |
| 18 | + bottom: 30px; |
| 19 | + box-shadow: 0 16px 24px 2px rgba(0,0,0,0.14), 0 6px 30px 5px rgba(0,0,0,0.12), 0 8px 10px -5px rgba(0,0,0,0.2); |
| 20 | + display: inline-block; |
| 21 | + left: 30px; |
| 22 | + overflow: hidden; |
| 23 | + position: fixed; |
| 24 | + right: 30px; |
| 25 | + width: 100%; |
| 26 | + } |
| 27 | + |
| 28 | + @media(min-width: 642px) { |
| 29 | + :host { |
| 30 | + bottom: 50px; |
| 31 | + right: auto; |
| 32 | + width: 320px; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + .header { |
| 37 | + @apply(--layout-horizontal); |
| 38 | + @apply(--layout-center); |
| 39 | + padding: 8px 20px; |
| 40 | + } |
| 41 | + |
| 42 | + .header__title { |
| 43 | + @apply(--layout-flex); |
| 44 | + font-size: 18px; |
| 45 | + } |
| 46 | + |
| 47 | + .header__close { |
| 48 | + border-radius: 50%; |
| 49 | + cursor: pointer; |
| 50 | + fill: var(--paper-grey-500); |
| 51 | + height: 22px; |
| 52 | + margin-right: -8px; |
| 53 | + padding: 8px; |
| 54 | + width: 22px; |
| 55 | + } |
| 56 | + |
| 57 | + .header__close:hover { |
| 58 | + background: var(--paper-grey-200); |
| 59 | + } |
| 60 | + |
| 61 | + #files { |
| 62 | + @apply(--layout-horizontal); |
| 63 | + @apply(--layout-wrap); |
| 64 | + max-height: 224px; |
| 65 | + overflow-y: auto; |
| 66 | + } |
| 67 | + |
| 68 | + .file__image { |
| 69 | + height: 100%; |
| 70 | + width: 100%; |
| 71 | + } |
| 72 | + </style> |
| 73 | + |
| 74 | + <div id="container"> |
| 75 | + <div class="header"> |
| 76 | + <div class="header__title">[[_computeHeaderTitle(_files.length, localize)]]</div> |
| 77 | + <svg class="header__close" on-tap="_closeTapped" viewBox="0 0 24 24"> |
| 78 | + <path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" /> |
| 79 | + </svg> |
| 80 | + </div> |
| 81 | + |
| 82 | + <div id="files"></div> |
| 83 | + </div> |
| 84 | + |
| 85 | + </template> |
| 86 | +</dom-module> |
| 87 | + |
| 88 | +<script> |
| 89 | +(function() { |
| 90 | + 'use strict'; |
| 91 | + |
| 92 | + Polymer({ |
| 93 | + |
| 94 | + is: 'file-uploader-completed-overlay', |
| 95 | + |
| 96 | + properties: { |
| 97 | + |
| 98 | + language: { |
| 99 | + type: String, |
| 100 | + value: 'en' |
| 101 | + }, |
| 102 | + |
| 103 | + resources: { |
| 104 | + value: _ => { |
| 105 | + return { |
| 106 | + 'en': { |
| 107 | + 'HeaderTitle': '{length, plural, one {1 item uploaded} other {{length} items uploaded}}' |
| 108 | + }, |
| 109 | + 'es': { |
| 110 | + 'HeaderTitle': 'Se {length, plural, one {ha subido 1 elemento} other {han subido {length} elementos}}' |
| 111 | + } |
| 112 | + }; |
| 113 | + } |
| 114 | + }, |
| 115 | + |
| 116 | + // @override AnimatedOverlayBehavior |
| 117 | + noCancelOnEscKey: { |
| 118 | + type: Boolean, |
| 119 | + value: true |
| 120 | + }, |
| 121 | + |
| 122 | + // @override AnimatedOverlayBehavior |
| 123 | + noCancelOnPopState: { |
| 124 | + type: Boolean, |
| 125 | + value: true |
| 126 | + }, |
| 127 | + |
| 128 | + _files: Array |
| 129 | + |
| 130 | + }, |
| 131 | + |
| 132 | + behaviors: [ |
| 133 | + AnimatedOverlayBehavior, |
| 134 | + Polymer.AppLocalizeBehavior |
| 135 | + ], |
| 136 | + |
| 137 | + listeners: { |
| 138 | + 'overlay-opened': '_overlayOpened', |
| 139 | + 'overlay-closed-animation-finish': '_overlayAnimatedOut', |
| 140 | + }, |
| 141 | + |
| 142 | + addFiles(files) { |
| 143 | + if (Array.isArray(this._files)) { |
| 144 | + this._files = this._files.concat(files).slice(0).reverse(); |
| 145 | + } else { |
| 146 | + this._files = files; |
| 147 | + } |
| 148 | + }, |
| 149 | + |
| 150 | + _overlayOpened() { |
| 151 | + this._renderThumbnails(); |
| 152 | + }, |
| 153 | + |
| 154 | + _overlayAnimatedOut() { |
| 155 | + this.$.files.innerHTML = ''; |
| 156 | + }, |
| 157 | + |
| 158 | + _renderThumbnails() { |
| 159 | + if (!this._files) { |
| 160 | + return; |
| 161 | + } |
| 162 | + |
| 163 | + this.$.files.innerHTML = ''; |
| 164 | + const fragment = document.createDocumentFragment(); |
| 165 | + |
| 166 | + this._files.forEach((file, index) => { |
| 167 | + const el = document.createElement('offthread-image'); |
| 168 | + |
| 169 | + el.setAttribute('class', 'file'); |
| 170 | + el.style = this._computeFileStyle(this._files.length, index); |
| 171 | + el.sizing = 'cover'; |
| 172 | + el.src = this._computeImageUrl(file); |
| 173 | + fragment.appendChild(el); |
| 174 | + }); |
| 175 | + |
| 176 | + Polymer.dom(this.$.files).appendChild(fragment); |
| 177 | + }, |
| 178 | + |
| 179 | + _computeImageUrl(file) { |
| 180 | + const isImage = /image\/.*/.exec(file.type); |
| 181 | + |
| 182 | + if (isImage) { |
| 183 | + return URL.createObjectURL(file); |
| 184 | + } |
| 185 | + }, |
| 186 | + |
| 187 | + _computeFileStyle(filesLength, fileIndex) { |
| 188 | + let styleAttr = ''; |
| 189 | + |
| 190 | + if (filesLength === 1) { |
| 191 | + styleAttr = 'height: 200px; width: 100%;' |
| 192 | + } else { |
| 193 | + styleAttr = 'width: calc(50% - 1px); height: 100px; margin-bottom: 2px;'; |
| 194 | + } |
| 195 | + |
| 196 | + if (filesLength > 1 && !(fileIndex % 2)) { |
| 197 | + styleAttr += ' margin-right: 2px;'; |
| 198 | + } |
| 199 | + |
| 200 | + return styleAttr; |
| 201 | + }, |
| 202 | + |
| 203 | + _computeHeaderTitle(filesLength) { |
| 204 | + return this.localize('HeaderTitle', 'length', String(filesLength)); |
| 205 | + }, |
| 206 | + |
| 207 | + _closeTapped() { |
| 208 | + this._files = []; |
| 209 | + this.opened = false; |
| 210 | + } |
| 211 | + |
| 212 | + }); |
| 213 | + |
| 214 | +}()); |
| 215 | +</script> |
0 commit comments