Skip to content
Snippets Groups Projects
Commit 92bfd84d authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

change markup for advertisements "sponsored"

parent 8ea1367a
No related branches found
No related tags found
2 merge requests!2246Translated using Weblate (German),!2244Resolve "Rework Startpage"
...@@ -117,7 +117,7 @@ class TilesController extends Controller ...@@ -117,7 +117,7 @@ class TilesController extends Controller
try { try {
$result = json_decode($result); $result = json_decode($result);
foreach ($result->data as $result_tile) { foreach ($result->data as $result_tile) {
$tiles[] = new Tile(title: $result_tile->title, image: $result_tile->image, image_alt: $result_tile->title . " Image", url: $result_tile->url, classes: "advertisement"); $tiles[] = new Tile(title: $result_tile->title, image: $result_tile->image, image_alt: $result_tile->title . " Image", url: $result_tile->url, advertisement: true);
} }
} catch (Exception $e) { } catch (Exception $e) {
Log::error($e); Log::error($e);
......
...@@ -17,6 +17,7 @@ class Tile implements \JsonSerializable ...@@ -17,6 +17,7 @@ class Tile implements \JsonSerializable
public string $url; public string $url;
public string $classes = ""; public string $classes = "";
public string $image_classes = ""; public string $image_classes = "";
public bool $advertisement = false;
/** /**
* *
* @param string $title Title to show for the Tile * @param string $title Title to show for the Tile
...@@ -26,7 +27,7 @@ class Tile implements \JsonSerializable ...@@ -26,7 +27,7 @@ class Tile implements \JsonSerializable
* @param string $classes Additional css classes to append for the tile * @param string $classes Additional css classes to append for the tile
* @param string $image_classes Additional css classes to append to the image of the tile * @param string $image_classes Additional css classes to append to the image of the tile
*/ */
public function __construct(string $title, string $image, string $image_alt, string $url, string $classes = "", string $image_classes = "") public function __construct(string $title, string $image, string $image_alt, string $url, string $classes = "", string $image_classes = "", bool $advertisement = false)
{ {
$this->title = $title; $this->title = $title;
try { try {
...@@ -41,6 +42,7 @@ class Tile implements \JsonSerializable ...@@ -41,6 +42,7 @@ class Tile implements \JsonSerializable
$this->url = $url; $this->url = $url;
$this->classes = $classes; $this->classes = $classes;
$this->image_classes = $image_classes; $this->image_classes = $image_classes;
$this->advertisement = $advertisement;
} }
public function jsonSerialize() public function jsonSerialize()
......
<?php
return [
"sponsored" => "Gesponsert"
];
\ No newline at end of file
<?php
return [
"sponsored" => "Sponsored"
];
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
let tile_count = tile_container.querySelectorAll("a").length; let tile_count = tile_container.querySelectorAll("a").length;
let advertisements = []; let advertisements = [];
let fetch_timeout = null;
fetchAdvertisements().then(() => udpateInterface()); fetchAdvertisements().then(() => udpateInterface());
async function fetchAdvertisements() { async function fetchAdvertisements() {
...@@ -12,9 +13,15 @@ ...@@ -12,9 +13,15 @@
if (advertisements.length >= desired_tile_count - regular_tile_count) return; if (advertisements.length >= desired_tile_count - regular_tile_count) return;
let update_url = document.querySelector("meta[name=tiles-update-url]").content; let update_url = document.querySelector("meta[name=tiles-update-url]").content;
update_url += "&count=" + (desired_tile_count - tile_count); update_url += "&count=" + (desired_tile_count - tile_count);
return new Promise((resolve, reject) => {
return fetch(update_url).then(response => response.json()).then(response => { if (fetch_timeout != null) return resolve();
advertisements = response; fetch_timeout = setTimeout(() => {
fetch(update_url).then(response => response.json()).then(response => {
advertisements = response;
fetch_timeout = null;
resolve();
}).catch(e => reject(e));
}, 500);
}); });
} }
function udpateInterface() { function udpateInterface() {
...@@ -47,6 +54,7 @@ ...@@ -47,6 +54,7 @@
let client_width = document.querySelector("html").clientWidth; let client_width = document.querySelector("html").clientWidth;
let desired_tile_count = 8; let desired_tile_count = 8;
if (client_width > 9 * tile_width + 8 * tile_gap) { if (client_width > 9 * tile_width + 8 * tile_gap) {
// Largest Screen Size => Up to 8 Tiles in one row // Largest Screen Size => Up to 8 Tiles in one row
desired_tile_count = max_tiles; desired_tile_count = max_tiles;
...@@ -61,10 +69,13 @@ ...@@ -61,10 +69,13 @@
desired_tile_count = 2; desired_tile_count = 2;
} }
console.log(client_width, tile_width, tile_gap, desired_tile_count);
console.log("Six Tiles", tile_width * 6 + 5 * tile_gap);
if (native_tile_count + min_advertisements > desired_tile_count) { if (native_tile_count + min_advertisements > desired_tile_count) {
desired_tile_count *= 2; desired_tile_count *= 2;
} }
return desired_tile_count; return desired_tile_count;
} }
window.addEventListener("resize", e => { window.addEventListener("resize", e => {
......
...@@ -7,16 +7,17 @@ div#tiles-container { ...@@ -7,16 +7,17 @@ div#tiles-container {
div#tiles { div#tiles {
flex-grow: 0; flex-grow: 0;
width: 100%; width: 100%;
@tile_width: 13ch; @tile_width: 115px;
@tile_gap: 16px;
@nine_row_width: calc(calc(9 * @tile_width) + calc(8 * 1rem));
@eight_row_width: calc(calc(8 * @tile_width) + calc(7 * 1rem)); @nine_row_width: calc(calc(9 * @tile_width) + calc(8 * @tile_gap));
@seven_row_width: calc(calc(7 * @tile_width) + calc(6 * 1rem)); @eight_row_width: calc(calc(8 * @tile_width) + calc(7 * @tile_gap));
@six_row_width: calc(calc(6 * @tile_width) + calc(5 * 1rem)); @seven_row_width: calc(calc(7 * @tile_width) + calc(6 * @tile_gap));
@five_row_width: calc(calc(5 * @tile_width) + calc(4 * 1rem)); @six_row_width: calc(calc(6 * @tile_width) + calc(5 * @tile_gap));
@four_row_width: calc(calc(4 * @tile_width) + calc(3 * 1rem)); @five_row_width: calc(calc(5 * @tile_width) + calc(4 * @tile_gap));
@three_row_width: calc(calc(3 * @tile_width) + calc(2 * 1rem)); @four_row_width: calc(calc(4 * @tile_width) + calc(3 * @tile_gap));
@two_row_width: calc(calc(2 * @tile_width) + calc(1 * 1rem)); @three_row_width: calc(calc(3 * @tile_width) + calc(2 * @tile_gap));
@two_row_width: calc(calc(2 * @tile_width) + calc(1 * @tile_gap));
@media(max-width: @nine_row_width) { @media(max-width: @nine_row_width) {
width: @seven_row_width; width: @seven_row_width;
...@@ -39,7 +40,7 @@ div#tiles-container { ...@@ -39,7 +40,7 @@ div#tiles-container {
justify-content: center; justify-content: center;
padding-top: 8dvh; padding-top: 8dvh;
gap: 1rem; gap: @tile_gap;
margin-inline: auto; margin-inline: auto;
height: max-content; height: max-content;
...@@ -77,13 +78,18 @@ div#tiles-container { ...@@ -77,13 +78,18 @@ div#tiles-container {
>div.title { >div.title {
font-size: .8rem; font-size: .8rem;
color: fade(@text-color, 40%); color: fade(@text-color, 60%);
transition: color 0.5s; transition: color 0.5s;
width: @tile_width; width: @tile_width;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
text-align: center; text-align: center;
line-height: 1;
>div.sub-title {
height: 1em;
}
} }
&:hover { &:hover {
...@@ -92,7 +98,11 @@ div#tiles-container { ...@@ -92,7 +98,11 @@ div#tiles-container {
} }
>div.title { >div.title {
color: @text-color; >div.main-title {
color: @text-color;
}
} }
} }
} }
......
<a href="{{$tile->url}}" class="{{ $tile->classes }}"> <a href="{{$tile->url}}" class="{{ $tile->advertisement ? "advertisement " : "" }}{{ $tile->classes }}" {{ $tile->advertisement ? 'rel=nofollow target=_blank' : ''}}>
<div class="image"> <div class="image">
<img src="{{$tile->image}}" alt="{{$tile->image_alt}}" class="{{$tile->image_classes}}"> <img src="{{$tile->image}}" alt="{{$tile->image_alt}}" class="{{$tile->image_classes}}">
</div> </div>
<div class="title">{{$tile->title}}</div> <div class="title">
<div class="main-title">{{$tile->title}}</div>
<div class="sub-title">
@if($tile->advertisement)
@lang('tiles.sponsored')
@endif
</div>
</div>
</a> </a>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment