discourse/app/assets/javascripts/wizard/addon/components/image-preview-logo.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.1 KiB
JavaScript
Raw Normal View History

import { action } from "@ember/object";
import { drawHeader } from "wizard/lib/preview";
import WizardPreviewBaseComponent from "./wizard-preview-base";
2016-09-17 04:12:56 +08:00
export default WizardPreviewBaseComponent.extend({
width: 400,
height: 100,
2016-09-17 04:12:56 +08:00
image: null,
didInsertElement() {
this._super(...arguments);
this.field.addListener(this.imageChanged);
},
willDestroyElement() {
this._super(...arguments);
this.field.removeListener(this.imageChanged);
},
@action
2016-09-17 04:12:56 +08:00
imageChanged() {
this.reload();
},
images() {
return { image: this.field.value };
2016-09-17 04:12:56 +08:00
},
paint({ ctx, colors, font, width, height }) {
2016-09-17 04:12:56 +08:00
const headerHeight = height / 2;
drawHeader(ctx, colors, width, headerHeight);
const image = this.image;
2016-09-17 04:12:56 +08:00
const headerMargin = headerHeight * 0.2;
const imageHeight = headerHeight - headerMargin * 2;
const ratio = imageHeight / image.height;
this.scaleImage(
image,
headerMargin,
headerMargin,
image.width * ratio,
imageHeight
);
2016-09-17 04:12:56 +08:00
this.drawPills(colors, font, height / 2);
2016-09-17 04:12:56 +08:00
},
});