Skip to content

Instantly share code, notes, and snippets.

View upalexgill's full-sized avatar

Alex Gill upalexgill

View GitHub Profile
// Alerts
@include alert-variant($background, $border, $text-color);
// Background Variant
@include bg-variant($parent, $color);
// Border Radius
@include border-top-radius($radius);
@include border-right-radius($radius);
@include border-bottom-radius($radius);
@upalexgill
upalexgill / drupal-gardens-overrides.css
Last active July 12, 2017 15:10
Drupal Gardens CSS Overrides
.region-header .page-element,
.region-header .block,
.page-width {
width: auto;
}
.block + .block,
.wrapper-content .block + .block,
.form-item, .form-actions,
.block .menu,
.views-row,
@upalexgill
upalexgill / karma.conf.js
Created July 21, 2020 10:31
Karma config
module.exports = function(config) {
config.set({
frameworks: ['mocha', 'chai', 'commonjs'],
files: [
'test/**/*.+(spec|test).+(js|jsx|mjs)',
{ pattern: 'test/**/*', included: false, served: true }
],
browsers: ['Chrome'],
plugins: [
'karma-*'
function createArrayOfObjects (len) {
let arr = []
for (let i = 0; i < len; i++) {
arr.push({
key: i
});
}
return arr
}
@upalexgill
upalexgill / fade.js
Last active July 21, 2020 15:08
Fade in/out
function fadeIn(el, duration, callback) {
el.style.opacity = 0
let last = +new Date()
function fade () {
el.style.opacity = +el.style.opacity + (+new Date() - last) / duration
last = +new Date()
if (+el.style.opacity < 1) {
(window.requestAnimationFrame && window.requestAnimationFrame(fade)) || setTimeout(fade, 250)
} else {
if (typeof callback === 'function') callback()
const data = [
{id: 0, parentId: 1},
{id: 1, parentId: 1},
{id: 2, parentId: 2},
{id: 3, parentId: 2}
];
const grouped = data.reduce((obj, node) => {
const key = node && node.parentId || node.id
obj[key] = obj[key] || []
const color = "rgb(0, 0, 0)"
const rgb = colour.match(/\d+/g) // rgb: [0: 0, 1: 0, 2: 0]
const getContrastColour = rgb => {
// http://www.w3.org/TR/AERT#color-contrast
const brightness = Math.round(
(parseInt(rgb[0], 10) * 299 +
parseInt(rgb[1], 10) * 587 +
parseInt(rgb[2], 10) * 114) /
1000
@upalexgill
upalexgill / Scroll to invalid input
Created November 24, 2020 12:24
Fixes HTML5 validation messages not displaying correctly
// jQuery dependency for cross-browser scroll (animate).
const scrollToInvalid = e => {
const navbarHeight = $(".navbar").height();
const navbarOffset = navbarHeight + 30;
$(e.target).addClass("invalid");
$('html, body').animate({scrollTop: $($(".invalid")[0]).offset().top - navbarOffset }, 0);
setTimeout(() => {
$(".invalid").removeClass("invalid");
@upalexgill
upalexgill / Drupal Toolbar & Sticky Header!
Last active December 4, 2020 19:40
Enables Drupal Toolbar & Sticky Header to work together
(function custom(Drupal, $) {
Drupal.behaviors.customStickyHeader = {
attach(context) {
const header = document.getElementById(HEADER_ID); // Change HEADER_ID for valid selector.
const getHeaderHeight = () => header ? header.getBoundingClientRect().height : 0;
const setDisplaceLoggedIn = (event, offsets) => {
header.style.marginTop = `${offsets.top}px` || `0px`;
document.body.style.left = offsets.left;
document.body.style.paddingTop = `${offsets.top + getHeaderHeight()}px`;
@upalexgill
upalexgill / ThreeJS: Model test
Last active March 13, 2021 22:46
Example using model from clara.io
import * as THREE from "https://threejsfundamentals.org/threejs/resources/threejs/r125/build/three.module.js";
import { OrbitControls } from "https://threejsfundamentals.org/threejs/resources/threejs/r125/examples/jsm/controls/OrbitControls.js";
import { OBJLoader } from "https://threejsfundamentals.org/threejs/resources/threejs/r125/examples/jsm/loaders/OBJLoader.js";
let camera, light, controls, scene, renderer;
init();
animate();
function init() {
scene = new THREE.Scene();