mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:52:45 +08:00
DEV: migrate CdnImg to gjs (#27797)
This commit is contained in:
parent
c080ac0094
commit
a60e1b35ed
28
app/assets/javascripts/discourse/app/components/cdn-img.gjs
Normal file
28
app/assets/javascripts/discourse/app/components/cdn-img.gjs
Normal file
|
@ -0,0 +1,28 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
||||
|
||||
export default class CdnImg extends Component {
|
||||
get cdnSrc() {
|
||||
return getURLWithCDN(this.args.src);
|
||||
}
|
||||
|
||||
get style() {
|
||||
if (this.args.width && this.args.height) {
|
||||
return htmlSafe(`--aspect-ratio: ${this.args.width / this.args.height};`);
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
{{#if @src}}
|
||||
<img
|
||||
...attributes
|
||||
src={{this.cdnSrc}}
|
||||
width={{@width}}
|
||||
height={{@height}}
|
||||
style={{this.style}}
|
||||
alt=""
|
||||
/>
|
||||
{{/if}}
|
||||
</template>
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{{#if this.src}}
|
||||
<img
|
||||
...attributes
|
||||
src={{this.cdnSrc}}
|
||||
width={{this.width}}
|
||||
height={{this.height}}
|
||||
style={{this.style}}
|
||||
alt=""
|
||||
/>
|
||||
{{/if}}
|
|
@ -1,20 +0,0 @@
|
|||
import Component from "@ember/component";
|
||||
import { htmlSafe } from "@ember/template";
|
||||
import { getURLWithCDN } from "discourse-common/lib/get-url";
|
||||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
|
||||
export default Component.extend({
|
||||
tagName: "",
|
||||
|
||||
@discourseComputed("src")
|
||||
cdnSrc(src) {
|
||||
return getURLWithCDN(src);
|
||||
},
|
||||
|
||||
@discourseComputed("width", "height")
|
||||
style(width, height) {
|
||||
if (width && height) {
|
||||
return htmlSafe(`--aspect-ratio: ${width / height};`);
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Reference in New Issue
Block a user