Add favicon support

This commit is contained in:
Schmelczer András 2019-12-23 17:36:43 +01:00
parent dbb48fbde6
commit 29e1546eb2
27 changed files with 92 additions and 109 deletions

View file

@ -0,0 +1,38 @@
import { TimelineElement } from "../../../model/portfolio";
import { html } from "../../../model/misc";
import "./timeline-element.scss";
export const generate = (
{ date, title, picture, description, more, link }: TimelineElement,
showMore: string,
showLess: string
): html => `
<section class="timeline-element">
<div class="line">
<p class="date-wide-screen">${date}</p>
</div>
<div class="card">
<h2>${title}</h2>
<p class="date-narrow-screen">${date}</p>
<img src="${picture}" alt="${picture}"/>
<p class="description">${description}</p>
${
more
? `
<div id="more"></div>
<div class="buttons">
<a id="show-more">${showMore}</a>
<a id="show-less">${showLess}</a>
</div>
`
: ""
}
${
link
? `
<a href="${link}" target="_blank">${link}</a>`
: ""
}
</div>
</section>
`;

View file

@ -0,0 +1,103 @@
@import "../../../style/mixins";
@import "../../../style/vars";
.timeline-element {
display: flex;
.date-narrow-screen,
.date-wide-screen {
@include insignificant-font();
}
.line {
@media (max-width: $breakpoint-width) {
display: none;
}
position: relative;
margin: 0 $small-margin 0 $icon-size / 2;
border-left: $line-width solid $normal-text-color;
&:before {
content: "";
@include square($icon-size);
position: absolute;
top: 33%;
left: -0.5 * $icon-size - (1.5 * $line-width);
border: $line-width solid $normal-text-color;
border-radius: 100%;
background: $background;
}
.date-wide-screen {
position: relative;
top: calc(33% + #{$icon-size} + 2ch);
transform: rotate(30deg);
margin: 0 $normal-margin 0 calc(#{$line-width} + 1ex);
width: 100px;
}
}
&:not(:first-of-type) .card {
margin-top: $normal-margin;
}
.card {
@include card();
overflow: hidden;
& > *:not(:first-child) {
margin-top: $line-height;
}
h2 {
@include sub-title-font();
}
.date-narrow-screen {
@media (min-width: $breakpoint-width) {
display: none;
}
margin: $small-margin 0 0 0;
color: $light-text-color;
}
img {
cursor: pointer;
}
.description {
font-style: italic;
}
#more {
overflow: hidden;
height: 0;
margin-top: 0;
transition: height $slow-transition-time;
}
.buttons {
position: relative;
margin-top: $small-margin;
* {
transition: opacity $slow-transition-time;
}
#show-more {
opacity: 1;
}
#show-less {
opacity: 0;
visibility: hidden;
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
}
}
}

View file

@ -0,0 +1,72 @@
import { TimelineElement } from "../../../model/portfolio";
import { PageContent } from "../../content/content";
import { PageElement } from "../../../framework/page-element";
import { createElement } from "../../../framework/element-factory";
import { generate } from "./timeline-element.html";
export class PageTimelineElement extends PageElement {
private isOpen;
private more: HTMLElement;
public constructor(
timelineElement: TimelineElement,
showMore: string,
showLess: string
) {
const root = createElement(generate(timelineElement, showMore, showLess));
if (timelineElement.more) {
const content = new PageContent(timelineElement.more);
super([content]);
this.isOpen = false;
this.more = root.querySelector("#more");
this.more.appendChild(content.getElement());
window.addEventListener("resize", this.handleResize.bind(this));
root
.querySelector(".buttons")
.addEventListener("click", this.toggleOpen.bind(this));
} else super();
this.setElement(root);
}
private toggleOpen() {
const showMore = this.getElement().querySelector(
"#show-more"
) as HTMLElement;
const showLess = this.getElement().querySelector(
"#show-less"
) as HTMLElement;
if (this.isOpen) {
this.more.style.height = "0";
PageTimelineElement.show(showMore);
PageTimelineElement.hide(showLess);
} else {
this.openMoreToFullHeight();
PageTimelineElement.hide(showMore);
PageTimelineElement.show(showLess);
}
this.isOpen = !this.isOpen;
}
private static hide(element: HTMLElement) {
element.style.opacity = "0";
setTimeout(() => (element.style.visibility = "hidden"), 350);
}
private static show(element: HTMLElement) {
element.style.visibility = "visible";
element.style.opacity = "1";
}
private openMoreToFullHeight() {
this.more.style.height = `${this.more.scrollHeight.toString()}px`;
}
private handleResize() {
if (this.isOpen) {
this.more.style.height = "auto";
setTimeout(this.openMoreToFullHeight.bind(this), 200);
}
}
}

View file

@ -0,0 +1,6 @@
import { html } from "../../model/misc";
import "./timeline.scss";
export const generate = (): html => `
<main id="timeline"></main>
`;

View file

@ -0,0 +1,5 @@
@import "../../style/vars";
main#timeline {
margin-top: $normal-margin;
}

View file

@ -0,0 +1,21 @@
import { TimelineElement } from "../../model/portfolio";
import { PageElement } from "../../framework/page-element";
import { createElement } from "../../framework/element-factory";
import { PageTimelineElement } from "./timeline-element/timeline-element";
import { generate } from "./timeline.html";
export class PageTimeline extends PageElement {
public constructor(
timeline: Array<TimelineElement>,
showMore: string,
showLess: string
) {
const root = createElement(generate());
const elements = timeline.map(
e => new PageTimelineElement(e, showMore, showLess)
);
root.append(...elements.map(e => e.getElement()));
super(elements);
this.setElement(root);
}
}