This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function traverse (values, numCols) { | |
var numRows = values.length / numCols; | |
for (var i = 0, length = values.length; i < length; i++) { | |
var row = (i % length / numCols) << 0; // = Math.floor | |
var col = i % numCols; | |
console.log(row, col); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace modules\wirelab; | |
use Craft; | |
use craft\elements\Entry; | |
use Twig\Extension\AbstractExtension; | |
use Twig\TwigFilter; | |
use Twig\TwigFunction; | |
class WirelabTwigExtension extends AbstractExtension |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some usefull tips to debug in templates: | |
```twig | |
{{ dump(_context) }} | |
{{ dump(_context|keys) }} | |
{{ dump(myProductQuery.rawSQL()) }} | |
``` | |
If you ever lose the overview of what template is used at what url, you can use this snippet in each template to show the template name as a regular html comment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { debounce } from 'ts-debounce'; | |
export function initLinksWithSubmenu(el: HTMLElement) { | |
// find all links with children | |
const links = el.querySelectorAll<HTMLElement>("li.has-children > a"); | |
let mouseover = false; | |
const debouncedClose = debounce(async (el: HTMLElement) => toggle(el, false), 1500); | |
const toggle = (el?: HTMLElement, value?: boolean) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getScreenPoint = (clientX, clientY, el) => { | |
const boundingRect = el.getBoundingClientRect(); | |
return new THREE.Vector2( | |
(clientX - boundingRect.left) * (el.offsetWidth / boundingRect.width), | |
(clientY - boundingRect.top) * (el.offsetHeight / boundingRect.height) | |
); | |
}; | |
export const screenToLatLng = (view, vector) => { | |
const direction = view.screenToWorld(vector); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace craft\contentmigrations; | |
use Craft; | |
use craft\db\Migration; | |
use craft\elements\User; | |
/** | |
* m240105_091858_disablePermissionUtilityFindReplace migration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Include in the head of the base page template #} | |
{% set currentElement = craft.app.urlManager.matchedElement %} | |
{% set sites = craft.app.getSites().getGroupById(currentSite.groupId).getSites()|filter(s => s.baseUrl is not empty) %} | |
{% set altLinks = [] %} | |
{% for site in sites %} | |
{% set title = craft.app.i18n.getLocaleById(site.language).displayName %} | |
{% set url = site.getBaseUrl() %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Generates a list of site links with icon | |
Basic Example: | |
{% embed 'partials/_sites.twig' %}{% endembed %} | |
Advanced Example: | |
{% embed 'partials/_sites.twig' %} | |
{% block sites %} | |
{% if languages is defined and languages is not empty %} | |
<ul class="rounded-2xl border divide-y divide-gray-200 py-2"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function initNavigation() { | |
const navigation = document.querySelector<HTMLElement>("[data-navigation]"); | |
if (navigation) initSticky(navigation); | |
} | |
function initStickyBehaviour(root: HTMLElement) { | |
// hide the top navigation on scroll | |
const topNav = root.querySelector<HTMLElement>("[data-topnav]"); | |
if (!topNav) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Random integer from <low, high> interval | |
export function randInt(low: number, high: number) { | |
return low + Math.floor(Math.random() * (high - low + 1)); | |
} | |
// Random float from <low, high> interval | |
export function randFloat(low: number, high: number) { | |
return low + Math.random() * (high - low); | |
} |
NewerOlder