Optimize some components
All checks were successful
continuous-integration/drone/push Build is passing

- Use binding of this over `document.querySelector` calls
- Use else if over a chained else and if condition
This commit is contained in:
2020-03-29 19:49:01 +02:00
parent 02974aa00c
commit 59f287af2b
3 changed files with 12 additions and 12 deletions

View File

@@ -6,12 +6,14 @@
export let className = null
// Variables
let counter
const numbers = [...Array(10).keys()]
// Reactive variables depending on currentIndex
$: actualIndex = currentIndex + 1
$: amount = String(actualIndex).length
$: index = (actualIndex < 10) ? String(actualIndex).padStart(2, '0') : String(actualIndex)
$: digits = index.split('')
let counter
const numbers = [...Array(10).keys()]
/*

View File

@@ -2,6 +2,7 @@
import { onMount } from 'svelte'
// Variables
let toggleEl
let toggleLayout
let layoutSetting
@@ -17,17 +18,16 @@
const layoutGridClass = 'photos--grid'
const layoutListClass = 'photos--list'
const grid = document.querySelector('.photos')
const toggle = document.querySelector('.toggle')
const pill = toggle.querySelector('.pill')
const pill = toggleEl.querySelector('.pill')
// Change active pill
const toggleAnimate = (elem, pill, toggle) => {
pill.style.width = Math.round(elem.getBoundingClientRect().width) + 'px'
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggle.getBoundingClientRect().left) + 'px'
pill.style.left = Math.round(elem.getBoundingClientRect().left - toggleEl.getBoundingClientRect().left) + 'px'
}
// Init of first option
toggleAnimate(document.querySelector(`.toggle [data-layout="${layoutSetting}"]`), pill, toggle)
toggleAnimate(toggleEl.querySelector(`[data-layout="${layoutSetting}"]`), pill, toggleEl)
// Toggle layout
toggleLayout = event => {
@@ -48,10 +48,10 @@
}
// Animate the active pill
toggleAnimate(clicked, pill, toggle)
toggleAnimate(clicked, pill, toggleEl)
// Add/Remove active classes
document.querySelectorAll('.toggle button').forEach(button => button.classList.remove('active'))
toggleEl.querySelectorAll('button').forEach(button => button.classList.remove('active'))
clicked.classList.add('active')
// Remember this setting
@@ -60,7 +60,7 @@
})
</script>
<div class="toggle">
<div class="toggle" bind:this={toggleEl}>
<button data-layout="list" class:active={layoutSetting === 'list'} on:click={toggleLayout}>
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="17" viewBox="0 0 19 17">
<g class="anim">

View File

@@ -54,12 +54,10 @@
</div>
<p class="pagination__caption style-caps">See more photos</p>
{:else}
{#if $currentLocation}
{:else if $currentLocation}
<div class="pagination__message">
<h3>That's all folks!</h3>
<p class="pagination__caption style-caps">Come back later to check out <br>new photos of {$currentLocation.name}</p>
</div>
{/if}
{/if}
</section>