Skip to content

Instantly share code, notes, and snippets.

View middisp's full-sized avatar

Peter Middis middisp

  • Peter Middis Web Services
  • Newcastle
View GitHub Profile
queryStringCheck = () => {
var qs = location.search.substring(1);
var qsObj = {};
qs = qs.split('&');
qs.forEach(q => {
var splitq = q.split('=');
qsObj[splitq[0]] = splitq[1].replace(/%20/g, ' ');
});
*, *:before, *:after {box-sizing: border-box}
[hidden] {display: none !important}
[disabled] {pointer-events:none; opacity: 0.3}
.horizontal {display: flex; flex-direction: row; justify-content: space-between}
.vertical {display: flex; flex-direction: column}
.center {justify-content: center; align-items: center}
.flex {flex: 1}
html {
box-sizing: inherit;
--spacing-xs: 8px;
ease(value, power = 3) {
return 1 - Math.pow(1 - value, power);
}
@middisp
middisp / in_viewport.js
Created September 19, 2016 14:42 — forked from MakingJamie/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@middisp
middisp / for.less
Last active August 29, 2015 14:25
Less For Loop
/*
* Material Colors
*/
@m-white: #ffffff;
@m-black: #000000;
@m-blue: #2196F3;
@m-red: #F44336;
@m-purple: #9C27B0;
@m-deeppurple: #673AB7;
@m-lightblue: #03A9F4;
function foo(args) {
var i, j, k;
// ...
// j acquires some interesting value
// Who called foo when j took this interesting value?
//
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
@middisp
middisp / bling.js
Last active August 29, 2015 14:23 — forked from paulirish/bling.js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
};
NodeList.prototype.__proto__ = Array.prototype;
@middisp
middisp / visited.js
Created June 3, 2015 09:03
Saves visited internal links to localStorage and adds visited data attribute.
// http://joelcalifa.com/blog/revisiting-visited
localStorage.setItem('visited-'+window.location.pathname,true);
var links = document.getElementsByTagName('a');
for (i=0;i<links.length;i++) {
var link = links[i];
if (link.host == window.location.host
&& localStorage.getItem('visited-' + link.pathname + '/')) {
link.dataset.visited = true;
}
}
@middisp
middisp / readme.md
Last active August 29, 2015 14:22
SDM - Simple DOM Module

#sdm

"simple dom module" for selecting and making dom elements. it exposes two globals in the window namespace $ and $$

api:

// NOTE: all functions either return the element or an array
// no NodeLists, so you can call `forEach` and friends directly
@middisp
middisp / isLeapYear.js
Created May 28, 2015 07:55
Confirms if the year entered is a leap year
/* Courtesy of http://stackoverflow.com/users/201078/trueblueaussie */
/* @y: number */
ily = function(y) {return !(y & 3 || !(y % 25) && y & 15);};