github.com/hernad/nomad@v1.6.112/ui/app/components/image-file.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import Component from '@ember/component'; 7 import { computed } from '@ember/object'; 8 import { 9 classNames, 10 tagName, 11 attributeBindings, 12 } from '@ember-decorators/component'; 13 import classic from 'ember-classic-decorator'; 14 15 @classic 16 @tagName('figure') 17 @classNames('image-file') 18 @attributeBindings('data-test-image-file') 19 export default class ImageFile extends Component { 20 'data-test-image-file' = true; 21 22 src = null; 23 alt = null; 24 size = null; 25 26 // Set by updateImageMeta 27 width = 0; 28 height = 0; 29 30 @computed('src') 31 get fileName() { 32 if (!this.src) return undefined; 33 return this.src.includes('/') ? this.src.match(/^.*\/(.*)$/)[1] : this.src; 34 } 35 36 updateImageMeta(event) { 37 const img = event.target; 38 this.setProperties({ 39 width: img.naturalWidth, 40 height: img.naturalHeight, 41 }); 42 } 43 }