Skip to content

Instantly share code, notes, and snippets.

View mattConn's full-sized avatar
👾
UX engineer @ Harbour

Matt mattConn

👾
UX engineer @ Harbour
View GitHub Profile
@mattConn
mattConn / jquery_keybinding.js
Last active November 22, 2016 03:11
JQuery switch statement for key binding.
$(document).keyup(function(e) { //keydown can be used as well.
switch(e.which) {
case 37: //left; any keycode can be used for each case.
alert('keycode: '+e.which);
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
@mattConn
mattConn / import_JSON_into_jade_gulpfile.js
Created September 19, 2016 01:27
Import JSON into Jade via Gulp.
var gulp = require('gulp'),
jade = require('gulp-jade'),
data = require('gulp-data'),
fs = require('fs');
gulp.task('jade', function(){
return gulp.src('src/jade/*.jade')
.pipe(data( function(file) {
return JSON.parse(fs.readFileSync('src/data.json'));
} ))
var newHTML = [
'<div class="foo">',
'<p>Readable HTML in JavaScript.</p>',
'</div>'
].join('');
@mattConn
mattConn / get_any_element_on_click.js
Last active August 27, 2016 23:26
Get any element in a document on click, hover, etc. Can access properties of "event.target" like you would typically access an element's properties, i.e. "event.target.style".
// getting an event's target
function getElementByEvent(event){
console.log(event.target);
}
// get the target
var element = document.getElementsByClassName('element')[0];
//adding event listener to target
element.addEventListener('click', function(event){