Font Awesome direct support

This commit is contained in:
Robert Bendun 2021-04-19 15:08:57 +02:00
parent c26931c8df
commit 36513e5869
2 changed files with 24 additions and 14 deletions

View File

@ -5,13 +5,13 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Styles -->
<!-- Dependencies -->
<script src="fontawesome/js/all.min.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
<link rel="stylesheet" href="styles.css">
<!-- <link rel="stylesheet" href="fontawesome/css/all.min.css"> -->
<!-- Styles -->
<link rel="stylesheet" href="styles.css">
<!-- Modules -->
<script src="modules/configuration.js"></script>

View File

@ -3,27 +3,37 @@ class Product {
* Stwórz produkt o określonej nazwie i ikonie
* @param {string} name
* @param {string} icon
* @example const product = new Product('apple', 'fa-apple')
* @example const product = new Product('apple', 'fa-apple-alt')
*/
constructor(name, icon) {
this.name = name;
this.icon = icon;
const match = /^([a-z]+)-(.*)/.exec(icon);
if (match) {
const [_, prefix, iconName] = match;
const result = FontAwesome.findIconDefinition({ prefix, iconName });
if (!result)
throw new Error('Font Awesome does NOT have this icon');
this.icon = String.fromCodePoint(parseInt(result.icon[3], 16));
} else {
this.icon = icon;
}
}
equals(other) {
return this.name === other.name
return this.name === other.name;
}
static get REGISTRY() {
return {
empty: new Product('', ''),
apple: new Product('apple', '\uf5d1'),
bacon: new Product('bacon', '\uf7e5'),
bone: new Product('bone', '\uf5d7'),
bread: new Product('bread', '\uf7ec'),
candyCane: new Product('candy cane', '\uf786'),
carrot: new Product('carrot', '\uf787'),
cheese: new Product('cheese', '\uf7ef')
apple: new Product('apple', 'fa-apple-alt'),
bacon: new Product('bacon', 'fa-bacon'),
bone: new Product('bone', 'fa-bone'),
bread: new Product('bread', 'fa-bread-slice'),
candyCane: new Product('candy cane', 'fa-candy-cane'),
carrot: new Product('carrot', 'fa-carrot'),
cheese: new Product('cheese', 'fa-cheese')
};
}