Skip to content

Instantly share code, notes, and snippets.

View lekoala's full-sized avatar

Thomas Portelange lekoala

View GitHub Profile
@lekoala
lekoala / db.yml
Created February 9, 2024 16:34
Faster dev/build with SilverStripe
---
Name: fast-db
After: '#databaseconnectors'
---
SilverStripe\ORM\Connect\DBSchemaManager:
fix_table_case_on_build: false
check_and_repair_on_build: false
SilverStripe\ORM\DatabaseAdmin:
show_record_counts: false
@lekoala
lekoala / ImprovedController.php
Last active February 9, 2024 08:17
Using Attributes for SilverStripe routing
<?php
trait ImprovedController
{
/**
* Override default mechanisms for ease of use
*
* @link https://docs.silverstripe.org/en/5/developer_guides/controllers/access_control/
* @param string $action
* @return boolean
import styles from "./node_modules/@melloware/coloris/dist/coloris.min.css";
import Coloris from "./node_modules/@melloware/coloris/dist/esm/coloris.js";
// Example
/* <label for="primary_color-input" class="form-label">Primary color</label>
<coloris-input data-config='{"swatches": ["#fff", "#000"] }'>
<input type="text" class="form-control" id="primary_color-input" name="primary_color">
</coloris-input> */
const themeMode = document.documentElement.dataset.bsTheme ? document.documentElement.dataset.bsTheme : "auto";
/**
* Entwine is inspired by a js lib (https://github.com/hafriedlander/jquery.entwine)
* that allows binding behaviour to a give selector
*
* This library is a modern take on the same subject
*
* All elements get their own event listeners attached. This is an alternative approach
* to have one big delegator that deals with everything (see listen.js if that's what you want)
* I'm actually not sure what's the course of action ? :-)
*
/**
* Delegate listener to any events on any elements
* Set passive elements by default
* Avoid listening multiple times to the same event for the same handler
*/
const supportedPassiveTypes = [
"scroll",
"wheel",
"touchstart",
/**
* Listen to any events on any elements
* Set passive elements by default
* Avoid listening multiple times to the same event for the same handler
* Support a virtual "connected" event that allows triggering code only once
*/
const CONNECTED = "connected";
const supportedPassiveTypes = [
"scroll",
/**
* @callback ElementCallback
* @param {HTMLElement} el
* @returns {void}
*/
const set = new WeakSet();
/**
* Initialize an element exactly once
// Split bootstrap media queries by stylesheet
// @link https://alistapart.com/article/mobile-first-css-is-it-time-for-a-rethink/
// Sample usage:
// <link href="/css/default.min.css" rel="stylesheet" />
// <link href="/css/mobile.min.css" media="screen and (max-width: 767.98px)" rel="stylesheet" />
// <link href="/css/tablet.min.css" media="screen and (min-width: 768px) and (max-width: 991.98px)" rel="stylesheet" />
// <link href="/css/desktop.min.css" media="screen and (min-width: 992px)" rel="stylesheet" />
// <link href="/css/print.min.css" media="print" rel="stylesheet" />
@lekoala
lekoala / print.scss
Created February 20, 2023 17:09
bootstrap 5 print styles
@import "../bootstrap/bootstrap-common";
// Print styles
@media print {
// Our custom styles
*,
*::before,
*::after {
text-shadow: none !important;
box-shadow: none !important;
@lekoala
lekoala / toaster.js
Created February 21, 2022 15:09
Bootstrap 5 Toaster
"use strict";
/**
* Create a toast object
*
* @param {string} attr.body Body content. Can also be filled with html tags (eg: Hello <b>World</b>)
* @param {string} attr.header (none) Header content. Can also be filled with html tags (eg : <h6 class="mb-0">Success</h6>)
* @param {string} attr.className (none) Additional classes for toast element (eg: 'border-0 bg-danger text-white')
* @param {boolean} attr.animation (true) Apply transition to the toast
* @param {boolean} attr.autohide (true) Auto hide the toast