Skip to content

Instantly share code, notes, and snippets.

View automagisch's full-sized avatar

Koen Houtman automagisch

View GitHub Profile
@automagisch
automagisch / fullscreen.js
Last active July 15, 2020 08:57
FullScreen API prefix-polyfill class (ES6)
/*
Description:
A utility class that shims the default native Fullscreen API implementations
in JavaScript (for the browser). Does nothing if FullScreen is not available
due to browser support / client browser configuration.
Usage:
@automagisch
automagisch / Hookable.js
Last active November 1, 2017 15:06
ES6 Hookable class
/*
Note: handy class to extend when you want a dead simple hook cycle system for anything you'll want to make
triggerable.
usage:
const Hookable = require('./path/to/Hookable...');
class SomeClass extends Hookable {
@automagisch
automagisch / svg-loader.js
Created September 29, 2017 12:58
ES6 Module for SVG find-load-and-replace
/*
SVGLoader 0.1
* dependencies: jQuery
- finds all occurences of any HTML element containing `[data-svg-src]`
- tries to load that svg
- if sucessfull, injects that svg code after the placeholder
- if unsuccessfull, handles that with caution and allows a custom callback
for when it's very wishable to handle that error on the frontend (such as
@automagisch
automagisch / _casper-tweak.scss
Last active September 22, 2017 15:18
CasperJS missing flexbox properties workaround
/*
In favor of casper.js (regressive UI testing): a very tiny and hacky fix
to get around the flexbox issues... Idea is to have this class put on the body
when we're running phantomjs.
@NOTE: There is only a class on the body 'body.casper-env' that is allowed to
make changes to minimize complexity.
@NOTE: Only apply the casper-env fix when it's needed in the test env. ofcourse
we still need (AND SHOULD) test without making any modifcations. This fix
/*
jQuery plugin for dynamically loading pages
$("#pageHolder").loadPage({
file: 'index.html',
effect: 'slide|fade',
duration: 1000
}).then(function() {
// done loading, this = $(html)
}, function(error) {
/*
SASS Class helpers
to make these work, include them in some imported file (like variables.scss or mixins.scss) and
extend them on classes like so:
ul {
@extend %reset-list;
}
@automagisch
automagisch / color-management.scss
Last active June 9, 2017 12:30
Automated SCSS Color Management
/*
defines base colors, all colors to use are described in this map.
works pretty well with a color palette generator like http://coolors.co/
palette in this example: https://coolors.co/def200-242038-315659-e3efeb-028090
MAP ui-colors (
[STRING] color-name: [HEX] hex-value
)
*/
@automagisch
automagisch / parseHeaderString.js
Created February 28, 2017 11:05
Parse a header string to a key-value format wrapped in an Array
/*
@description A function that takes in some headers as a string containing newlines.
It will split the string on its newlines, and then will split it into
a key-value pair for easy deploying into HTML.
@param headerStr [String]
@returns headers [Array]
*/
function parseHeaderString(headerStr) {
@automagisch
automagisch / jqueryutils.form-parser.js
Last active May 24, 2016 12:53
jQuery form field parser with support for radio's and checkboxes
/*
* jQuery utilities
* Takes in a form element and rips out all the values in a simple key-value pair
*/
$(function() {
$.fn.parseFormFields = function(props) {
// define some default settings with default values
@automagisch
automagisch / polyfill.js
Created May 3, 2016 15:30 — forked from gerred/polyfill.js
Canvas Polyfill
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)