Skip to content

Instantly share code, notes, and snippets.

View matijs's full-sized avatar
:dependabot:
Scouting turtles

matijs matijs

:dependabot:
Scouting turtles
View GitHub Profile
@matijs
matijs / switcher-es5.js
Last active December 8, 2016 22:47
Stylesheet switcher sans ES6 features
(function() {
window.addEventListener( 'load', function() {
var links = Array.prototype.slice.call( document.querySelectorAll( 'link[title]') );
var uniqueTitles = links.reduce( function( titles, link ) {
if ( titles.indexOf( link.title ) === -1 ) {
titles.push( link.title );
}
return titles;
}, []);
var title = window.sessionStorage && window.sessionStorage.getItem( 'title' ) || '';
@matijs
matijs / switcher.js
Created December 8, 2016 15:25
Stylesheet Switcher
(function() {
const links = Array.from( document.querySelectorAll( 'link[title]' ) );
const styles = Array.from( new Set( links.map( link => link.title ) ) );
let title = localStorage.getItem( 'title' );
function selectStyle( title ) {
links.forEach( link => {
link.disabled = true;
link.disabled = link.title !== title;
});
@matijs
matijs / camelCase.js
Last active November 3, 2016 14:18
Convert foo-bar-baz into a camelCased version
const camelCase = str => str.split( /[_,-]+/ ).map( ( item, index ) => index === 0 ? item : item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
).join('');
@matijs
matijs / .scss-lint.yml
Last active August 4, 2016 10:36
All SCSS Linter options, quite restrictive, see https://github.com/brigade/scss-lint/blob/master/lib/scss_lint/linter/README.md for an explanation of the options.
---
linters:
BangFormat:
space_before_bang: true
space_after_bang: false
BemDepth:
enabled: false
BorderZero:
enabled: true
convention: none
function isInteractiveElement( element ) {
if ( [ 'A', 'BUTTON', 'DETAILS', 'EMBED', 'IFRAME', 'KEYGEN', 'LABEL', 'SELECT', 'TEXTAREA' ].indexOf( element.nodeName ) !== -1 ) {
return true;
}
if ( element.nodeName === 'INPUT' && element.type !== 'hidden' ) {
return true;
}
if ( ['AUDIO', 'VIDEO'].indexOf( element.nodeName ) > -1 && element.hasAttribute('controls') ) {
return true;
}
@matijs
matijs / qsaHelper.js
Created June 23, 2016 05:36
Helper function to return querySelectorAll results as an array
function $_( selectors, baseElement ) {
var elements = (baseElement || document).querySelectorAll( selectors );
return Array.prototype.slice.call( elements );
}
@matijs
matijs / insert-script.js
Created March 9, 2016 18:37
Sure fire DOM Element insertion
function insertScript(url, onload, onerror) {
var ref = document.getElementsByTagName('script')[0];
var script = document.createElement('script');
script.src = url;
if (typeof onload === 'function') {
script.onload = onload;
}
if (typeof onerror === 'function') {
script.onerror = onerror;
}
@matijs
matijs / .editorconfig
Last active February 9, 2016 14:21
Sensible EditorConfig defaults
# For more information about the properties used in
# this file, please see the EditorConfig documentation:
# http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
@matijs
matijs / textarea-keyboard-save.js
Created January 26, 2016 12:26
Trigger a click on a 'save' button by pressing cmd/ctrl-s in a textarea (adapt as needed)
(function() {
'use strict';
document.addEventListener('keydown', function(event) {
var S = 83,
activeElement = document.activeElement,
saveButtonId,
saveButton;
if ((event.key === S || event.keyCode === S) && (event.metaKey || event.ctrlKey) && activeElement.nodeName === 'TEXTAREA') {
@matijs
matijs / scrollbarsize.js
Last active December 30, 2015 21:39
calculate the size of the scrollbar
var scrollbarSize = (function() {
var inner = document.createElement( "div" ),
outer = document.createElement( "div" );
inner.style.width = "100%";
inner.style.height = "60px";
outer.style.position = "absolute";
outer.style.top = "0";
outer.style.left = "0";
outer.style.visibility = "hidden";
outer.style.width = "50px";