Skip to content

Instantly share code, notes, and snippets.

View hkfoster's full-sized avatar

Kyle Foster hkfoster

  • Richmond, Virginia
View GitHub Profile
@hkfoster
hkfoster / interval.js
Created April 20, 2024 20:53
A turnkey requestAnimationFrame replacement for setInterval
/**
* Interval 0.0.2
* A turnkey requestAnimationFrame replacement for setInterval
* @author Kyle Foster (@hkfoster)
* @license MIT
**/
const interval = {
set: (fn, delay) => {
if (!window.requestAnimationFrame) return window.setInterval(fn, delay)
@hkfoster
hkfoster / syntax.scss
Created March 3, 2017 02:08
Compose Articles Syntax Highlighting
/* ===================================== *
* Preformatted text
* ------------------------------------- */
$color-code: #58728A;
$color-code-background: #EDF5F7;
$color-code-punctuation: #7EC9FF;
$color-code-tag: #DD2F41;
$color-code-selector: #F69523;
$color-code-keyword: #25C894;
@hkfoster
hkfoster / module-template.js
Last active May 9, 2016 19:14
A simple boilerplate for UMD JS modules
/**
* MyModule 0.0.1
* A short description of your module
* @author Me (@me)
* @license MIT
*/
;( function( root, factory ) {
if ( typeof define === 'function' && define.amd ) {
define( factory );
@hkfoster
hkfoster / typewriter.js
Last active August 29, 2015 14:22
Headline Typewriter Animation
/**
* Typewriter.js 0.0.1
* @author Kyle Foster (@hkfoster)
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
var typewriter = ( function() {
var headline = document.querySelector( '.typewriter' );
@hkfoster
hkfoster / lightbox.js
Last active August 29, 2015 14:22
A Simple Lightbox Trigger
/**
* Lightbox.js 0.0.1
* @author Kyle Foster (@hkfoster)
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
var lightBoxInit = ( function() {
var triggers = document.querySelectorAll( '[rel="modal"]' );
@hkfoster
hkfoster / spectral.js
Last active November 13, 2015 20:16
A full-text search engine for Ghost based on lunr.js
/**
* Spectral.js 0.0.6
* Full-text search for the Ghost blogging platform
* @author Kyle Foster (@hkfoster)
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
// Lunr 0.6.0 | lunrjs.com | by Oliver Nightingale | @license MIT
!function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.6.0",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.utils.asString=function(t){return void 0===t||null===t?"":t.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].spli
@hkfoster
hkfoster / validation.js
Last active May 2, 2017 00:08
Native JS HTML5 form validation.
/**
* HTML5 Form Validation 0.0.1
* @author Kyle Foster (@hkfoster)
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
var formValidation = ( function() {
var init = function() {
@hkfoster
hkfoster / wrapnodes.js
Created March 17, 2015 20:36
Native JS node-wrapping function
function wrapNodes( nodes, type ) {
for ( var index = 0; index < nodes.length; index++ ) {
var node = nodes[ index ],
wrapper = document.createElement( type );
node.parentNode.insertBefore( wrapper, node );
wrapper.appendChild( node );
}
}
@hkfoster
hkfoster / fancysands.js
Last active May 15, 2019 11:56
Wrap ampersands with <span class="amp"></span> for styling
/**
* Fancysands v0.0.1
* Wrap ampersands with <span class="amp"></span> for styling
* @author Kyle Foster (@hkfoster)
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
( function( window ) {
'use strict';
@hkfoster
hkfoster / nodefromstring.js
Last active August 29, 2015 14:02
Native JS Node From String Function
/**
* Node From String Function
* @author Kyle Foster
* @license MIT (http://www.opensource.org/licenses/mit-license.php/)
*/
var nodeFromString = function( string ) {
var match = /^<([a-z]+)/g.exec( string ),
tag = match[ 1 ],
wrapper = 'div',
outliers = {