Skip to content

Instantly share code, notes, and snippets.

View natedoesweb's full-sized avatar

Nate Smith natedoesweb

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Linktree Style Page</title>
<style>
body {
margin: 0;
padding: 0;
@natedoesweb
natedoesweb / DomBasedRouter.js
Last active November 23, 2023 09:52
ES6 module implementation of Paul Irish's DOM based routing
export default (routes) => {
return {
fire (func,funcname, args){
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && routes[func] && typeof routes[func][funcname] == 'function'){
routes[func][funcname](args);
}
},
load() {
var bodyId = document.body.id;
@natedoesweb
natedoesweb / throttleRequests.js
Created July 28, 2017 18:07
Throttle calling a provided function on every element in the calling array.
function throttle(set, limit, threshold, callback) {
let timer = 0;
window.setInterval(() => {
timer++;
}, threshold);
let i = 0;
let requestChunk = timer;
let requestsSent = 0;
while (i < set.length) {
// requests within limit
@natedoesweb
natedoesweb / concatStrings.js
Last active November 3, 2016 23:29
Append or prepend a string to a predefined string
var prepend = concatStrings('prependWith-'),
append = concatStrings('-appendWith', true);
console.log(prepend('baseString')); // outputs prependWith-baseString
console.log(append('baseString')); // outputs baseString-appendWith
function concatStrings (classFragmentA, reverse) {
return function (classFragmentB) {
var fragments = [classFragmentA, classFragmentB];
return (reverse) ? fragments.reverse().join('') : fragments.join('');
/*
* Author: Nathanael Smith
* Description: This module stores functions in a run queue until they're needed to be executed.
*/
var ExeQue = (function(){
function store (location, func) {
var queue = getQueue(location).concat(func);
if (location instanceof jQuery) {
@natedoesweb
natedoesweb / listingorder.css
Last active August 26, 2015 18:22
css listing order
.module {
// extends
// includes
// element styles
// media queries
// element states
@natedoesweb
natedoesweb / autoTab.js
Created June 13, 2013 23:24
Auto Tab Form fields with maxlength set
(function(){
var autoTab = {
keysPressed : 0,
init : function () {
this.keyEvents();
},
keyEvents : function () {
var self = this; self.keyEvents.validKey = false;
$('input[maxlength]').on('keypress', function(e){
self.keyEvents.validKey = true;
// Normalize & Layout
article, aside, details, figcaption, figure, footer,
header, hgroup, nav, section, summary { display: block; }
audio, canvas, video {
display: inline-block;
*display: inline;
*zoom: 1;
}
audio:not([controls]) { display: none; }
[hidden] { display: none; }
@natedoesweb
natedoesweb / blocks-equalize.js
Last active December 16, 2015 17:18
Match all blocks in a set to the same height.
$(function(){
$('.block-grid').each(function(index){
var blocks = $.makeArray($(this).find('.block')).sort(sortByHeight)[0];
$(this).find('.block').height($(blocks).height());
});
});
function sortByHeight(a,b) {
return ($(b).height() - $(a).height());
}
@natedoesweb
natedoesweb / speedbump.js
Created January 11, 2013 00:35
External Link Speedbump
// external link speedbump
$.expr[":"].external = function (a) {
// DO NOT INCLUDE THE FOLLOWING MATCHES: EMAIL LINKS, TELEPHONE LINKS, HOSTNAME
return !a.href.match(/^mailto\:/) && !a.href.match(/^tel\:/) && a.hostname != location.hostname
};
$('a:external').click(function(e){
e.preventDefault();
href = $(this).attr('href');
$.colorbox({
href: '/_diffs/templates/portal_pop_up-speedbump.html',