Skip to content

Instantly share code, notes, and snippets.

View jtulk's full-sized avatar

Justin Tulk jtulk

  • El Paso, Texas
View GitHub Profile
@jtulk
jtulk / gist:11384949
Created April 28, 2014 21:44
Hide Element on Clicking Away
$('body').on "click", ->
//If element to hide is open
$('.elementToHide').hide()
$('.elementToHide').on "click", (e) ->
e.stopPropagation()
@jtulk
jtulk / gist:f8fc762421835c2aea83
Created August 21, 2014 01:45
Attach .active to <a> tags in #main nav
activeMenuStyles = ->
loc = "/" + window.location.pathname.split("/")[1]
style = (link) ->
href = $(link).attr('href')
if href == loc
$(link).addClass('active')
menuLinks = $('#main > a')
@jtulk
jtulk / smoothscroll
Last active August 29, 2015 14:05
Smoothscroll intrapage links w/ .scroll-link class
$('nav').find('a').on 'click', ->
that = $(this)
target = $(this.hash)
if !target.length
target = $('[name=' + this.hash.slice(1) +']')
$('html,body').animate({
scrollTop: target.offset().top
}, 1000, ->
#update the url hash
@jtulk
jtulk / index.html
Last active August 29, 2015 14:23
Trying out Bl.ocks.org with D3 and JSON-Generator
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
@jtulk
jtulk / _D3-JSONGenerator.md
Last active August 29, 2015 14:23
Using D3 and JSON-Generator

Experimenting with Gist, Gistup, Bl.ocks.org, D3, JSON-Generator, and some vanilla javascript.

@jtulk
jtulk / sample.js
Created August 10, 2015 17:42
Examples for a blog post on rewriting jQuery's .each() in Vanilla JS
// Select all HTML elements with class .text-input
var $inputs = $('.text-input');
// Create event handling functions
function textInputFocusHandler(){ console.log('focus');}
function textInputBlurHandler(){ console.log('blur'); }
// Attach focus & blur handlers to selected inputs
$inputs.on('focus', textInputFocusHandler);
$inputs.on('blur', textInputBlurHandler);
@jtulk
jtulk / sample.js
Created August 10, 2015 17:45
Example #2: Rewriting jQuery's .each() in Vanilla JS
// Select all HTML elements with class .text-input
var inputs = document.getElementsByClassName('text-input');
// Create event handling functions
function textInputFocusHandler(){ console.log('focus');}
function textInputBlurHandler(){ console.log('blur'); }
// Attach focus & blur handlers to selected inputs
inputs.addEventListener('focus', textInputFocusHandler);
inputs.addEventListener('blur', textInputBlurHandler);
@jtulk
jtulk / sample.js
Created August 10, 2015 17:46
Example #3: Rewriting jQuery's .each() in Vanilla JS
// Attach focus & blur handlers to the first selected input
inputs[0].addEventListener('focus', textInputFocusHandler);
inputs[0].addEventListener('blur', textInputBlurHandler);
@jtulk
jtulk / sample.js
Last active August 29, 2015 14:27
Example #4: Rewriting jQuery's .each() in Vanilla JS
// Loop through the elements in the array-like object
// and attach an event listener to each element
inputs.forEach(function(el, index, array){
el.addEventListener('focus', textInputFocusHandler);
el.addEventListener('blur', textInputBlurHandler);
});
@jtulk
jtulk / sample.js
Created August 10, 2015 17:48
Example #5: Rewriting jQuery's .each() in Vanilla JS
// Use the Array.prototype.forEach method and the
// .call method to loop through the array-like object
Array.prototype.forEach.call(inputs, function(el, index, array){
el.addEventListener('focus', textInputFocusHandler);
el.addEventListener('blur', textInputBlurHandler);
});