forked from MapComplete/MapComplete
Refactoring: remove old, no longer needed classes
This commit is contained in:
parent
b8de80bee3
commit
61f20d0092
14 changed files with 60 additions and 293 deletions
|
|
@ -1,82 +0,0 @@
|
|||
import { Utils } from "../../Utils"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export default class Img extends BaseUIElement {
|
||||
private readonly _src: string
|
||||
private readonly _rawSvg: boolean
|
||||
private readonly _options: { readonly fallbackImage?: string }
|
||||
|
||||
/** @deprecated
|
||||
*/
|
||||
constructor(
|
||||
src: string,
|
||||
rawSvg = false,
|
||||
options?: {
|
||||
fallbackImage?: string
|
||||
}
|
||||
) {
|
||||
super()
|
||||
if (src === undefined || src === "undefined") {
|
||||
throw "Undefined src for image"
|
||||
}
|
||||
this._src = src
|
||||
this._rawSvg = rawSvg
|
||||
this._options = options
|
||||
}
|
||||
|
||||
static AsData(source: string) {
|
||||
if (Utils.runningFromConsole) {
|
||||
return source
|
||||
}
|
||||
try {
|
||||
return `data:image/svg+xml;base64,${btoa(source)}`
|
||||
} catch (e) {
|
||||
console.error("Cannot create an image for", source.slice(0, 100))
|
||||
console.trace("Cannot create an image for the given source string due to ", e)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
static AsImageElement(source: string, css_class: string = "", style = ""): string {
|
||||
return `<img class="${css_class}" style="${style}" alt="" src="${Img.AsData(source)}">`
|
||||
}
|
||||
|
||||
AsMarkdown(): string {
|
||||
if (this._rawSvg === true) {
|
||||
console.warn("Converting raw svgs to markdown is not supported")
|
||||
return undefined
|
||||
}
|
||||
let src = this._src
|
||||
if (this._src.startsWith("./")) {
|
||||
src = "https://mapcomplete.org/" + src
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
if (this._rawSvg) {
|
||||
const e = document.createElement("div")
|
||||
e.innerHTML = this._src
|
||||
return e
|
||||
}
|
||||
|
||||
const el = document.createElement("img")
|
||||
el.src = this._src
|
||||
el.onload = () => {
|
||||
el.style.opacity = "1"
|
||||
}
|
||||
el.onerror = () => {
|
||||
if (this._options?.fallbackImage) {
|
||||
if (el.src === this._options.fallbackImage) {
|
||||
// Sigh... nothing to be done anymore
|
||||
return
|
||||
}
|
||||
el.src = this._options.fallbackImage
|
||||
}
|
||||
}
|
||||
return el
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
|
||||
export default class Lazy extends BaseUIElement {
|
||||
private readonly _f: () => BaseUIElement
|
||||
|
||||
constructor(f: () => BaseUIElement) {
|
||||
super()
|
||||
this._f = f
|
||||
}
|
||||
|
||||
protected InnerConstructElement(): HTMLElement {
|
||||
// The caching of the BaseUIElement will guarantee that _f will only be called once
|
||||
return this._f().ConstructElement()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
import { VariableUiElement } from "./VariableUIElement"
|
||||
import Locale from "../i18n/Locale"
|
||||
import Link from "./Link"
|
||||
import SvelteUIElement from "./SvelteUIElement"
|
||||
import Translate from "../../assets/svg/Translate.svelte"
|
||||
import Constants from "../../Models/Constants"
|
||||
|
||||
/**
|
||||
* The little 'translate'-icon next to every icon + some static helper functions
|
||||
*/
|
||||
export default class LinkToWeblate extends VariableUiElement {
|
||||
constructor(context: string, availableTranslations: object) {
|
||||
super(
|
||||
Locale.language.map(
|
||||
(ln) => {
|
||||
if (Locale.showLinkToWeblate.data === false) {
|
||||
return undefined
|
||||
}
|
||||
if (availableTranslations["*"] !== undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (context === undefined || context.indexOf(":") < 0) {
|
||||
return undefined
|
||||
}
|
||||
const icon = new SvelteUIElement(Translate).SetClass(
|
||||
"rounded-full inline-block w-3 h-3 ml-1 weblate-link self-center"
|
||||
)
|
||||
if (availableTranslations[ln] === undefined) {
|
||||
icon.SetClass("bg-red-400")
|
||||
}
|
||||
return new Link(icon, LinkToWeblate.hrefToWeblate(ln, context), true).SetClass(
|
||||
"weblate-link"
|
||||
)
|
||||
},
|
||||
[Locale.showLinkToWeblate]
|
||||
)
|
||||
)
|
||||
this.SetClass("enable-links")
|
||||
const self = this
|
||||
Locale.showLinkOnMobile.addCallbackAndRunD((showOnMobile) => {
|
||||
if (showOnMobile) {
|
||||
self.RemoveClass("hidden-on-mobile")
|
||||
} else {
|
||||
self.SetClass("hidden-on-mobile")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the url to Hosted weblate
|
||||
*
|
||||
* LinkToWeblate.hrefToWeblate("nl", "category:some.context") // => "https://translate.mapcomplete.org/translate/mapcomplete/category/nl/?offset=1&q=context%3A%3D%22some.context%22"
|
||||
*/
|
||||
public static hrefToWeblate(language: string, contextKey: string): string {
|
||||
if (contextKey === undefined || contextKey.indexOf(":") < 0) {
|
||||
return undefined
|
||||
}
|
||||
const [category, ...rest] = contextKey.split(":")
|
||||
const key = rest.join(":")
|
||||
|
||||
const baseUrl = Constants.weblate + "translate/mapcomplete/"
|
||||
return baseUrl + category + "/" + language + "/?offset=1&q=context%3A%3D%22" + key + "%22"
|
||||
}
|
||||
|
||||
public static hrefToWeblateZen(
|
||||
language: string,
|
||||
category: "core" | "themes" | "layers" | "shared-questions" | "glossary" | string,
|
||||
searchKey: string
|
||||
): string {
|
||||
const baseUrl = Constants.weblate + "zen/mapcomplete/"
|
||||
// ?offset=1&q=+state%3A%3Ctranslated+context%3Acampersite&sort_by=-priority%2Cposition&checksum=
|
||||
return (
|
||||
baseUrl +
|
||||
category +
|
||||
"/" +
|
||||
language +
|
||||
"?offset=1&q=+state%3A%3Ctranslated+context%3A" +
|
||||
encodeURIComponent(searchKey) +
|
||||
"&sort_by=-priority%2Cposition&checksum="
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<script lang="ts">
|
||||
import Locale from "../i18n/Locale"
|
||||
import LinkToWeblate from "./LinkToWeblate"
|
||||
import Translate from "../../assets/svg/Translate.svelte"
|
||||
import { LanguageIcon } from "@babeard/svelte-heroicons/solid"
|
||||
import Translations from "../i18n/Translations"
|
||||
|
||||
/**
|
||||
* Shows a small icon which will open up weblate; a contributor can translate the item for 'context' there
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
{#if !!context && context.indexOf(":") > 0}
|
||||
{#if $linkOnMobile}
|
||||
<a
|
||||
href={LinkToWeblate.hrefToWeblate($language, context)}
|
||||
href={Translations.hrefToWeblate($language, context)}
|
||||
target="_blank"
|
||||
class="weblate-link mx-1"
|
||||
tabindex="-1"
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
</a>
|
||||
{:else if $linkToWeblate}
|
||||
<a
|
||||
href={LinkToWeblate.hrefToWeblate($language, context)}
|
||||
href={Translations.hrefToWeblate($language, context)}
|
||||
class="weblate-link hidden-on-mobile"
|
||||
target="_blank"
|
||||
tabindex="-1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue