This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
co = checkout | |
ci = commit | |
st = status | |
br = branch | |
hist = log --decorate --oneline --graph --date=short --abbrev-commit | |
histdate = log --decorate --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short --abbrev-commit | |
type = cat-file -t | |
dump = cat-file -p | |
w = whatchanged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gulp Dependencies | |
var gulp = require('gulp'); | |
var rename = require('gulp-rename'); | |
// Build Dependencies | |
var browserify = require('gulp-browserify'); | |
var uglify = require('gulp-uglify'); | |
// Style Dependencies | |
var sass = require('gulp-sass'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//two events, same callback | |
$( "div" ).on( "mouseenter mouseleave", function() { | |
console.log( "mouse hovered over or left a div" ); | |
}); | |
//two events, each with own callback | |
$( "div" ).on({ | |
mouseenter: function() { | |
console.log( "hovered over a div" ); | |
}, | |
mouseleave: function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//event listener with anonymous callback function | |
$('mySelector').on('myEvent', function(e) { | |
/**callback function(s) here **/ | |
}); | |
//event listener with a defined callback function | |
function someFunction(e){ | |
/**callback function(s) here **/ | |
}; | |
$('mySelector').on('myEvent', someFunction ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//traditional way | |
$( "#list a" ).on( "click", function() { | |
console.log( $( this ).text('I was clicked!') ); | |
}); | |
//event delegation way | |
$( "#list" ).on( "click", "a", function() { | |
console.log( $( this ).text('I was clicked!') ); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//call the accordion plugin | |
$('.accordion').accordion(); | |
//trigger the custom event and set it | |
panel.trigger('panelOpener'); | |
$(".panel").on("panelOpener", function() { | |
// Developer 1: do Ajax stuff | |
}); | |
$(".panel").on("panelOpener", function() { | |
// Developer 2: do saving stuff | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//calls handler once and sets up subsequent action | |
$( "button" ).one( "click", firstClick ); | |
function firstClick() { | |
$('p').text( "You just clicked this for the first time!" ); | |
// Set up the new handler for subsequent clicks with $(this).click | |
// (omit if no further click responses are needed) | |
$( this ).click( function(){ | |
$('p').text( "You\'ve clicked this before!" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//general toggling - use another variable | |
var x = 0; | |
$('#toggle-btn').click(function(e){ | |
if( x == 1 ){ | |
$(this).removeClass('clicked'); | |
x = 0; | |
} else { | |
$(this).addClass('clicked'); | |
x = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tear down all click handlers on a selector | |
$( "p" ).off( "click" ); | |
// Tear down a particular click handler by passing its name in the second parameter | |
var firstHandler = function() { console.log( "some action" ); }; | |
var secondHandler = function() { console.log( "another action" ); }; | |
// both click handlers attached to "p" by chaining | |
$( "p" ).on( "click", firstHandler ).on( "click", secondHandler ); | |
// tear down only firstHandler - secondHandler still attached |