Skip to content

Instantly share code, notes, and snippets.

The jQuery special events API is a fairly flexible system by which you can specify bind and unbind hooks as well as default actions for custom events. In using this API, you can create custom events that do more than just execute bound event handlers when triggered--these "special" events can modify the event object passed to event handlers, trigger other entirely different events, or execute complex setup and teardown code when event handlers are bound to or unbound from elements.

Note that this article uses some advanced jQuery techniques and assumes you understand the concepts of custom events and event delegation using bubbling.

Also, because this article is rather long, it has been broken up into sections. I'd recommend reading it in order, one section at a time, because techniques used in subsequent examples often reference those used in previo

@cowboy
cowboy / shebangs
Last active December 11, 2015 22:09 — forked from miketaylr/shebang
#!/ricky martin
ytgfrgty6trfgty5rgy65trgy67t5rr4e3wsde43swde43swa6ylop;/[[[[[[[[[[[[[[[[[[0-9=-0q1 ``````` ]]]]]]]]]]]]]]]]]]';lo..........jmuik,lo.p;.lojmua ?:>l,./;;l,kmjn mk,bvhn098765tr4890p8iu7t5r4ety67890-=0p9otyfr /'/
@cowboy
cowboy / grunt-contrib-plugins-0.4.0rc7.md
Last active December 11, 2015 14:18
Grunt plugins updated to work with grunt 0.4.0rc7
@cowboy
cowboy / Gruntfile.js
Created January 9, 2013 22:09
grunt: lineman idea
module.exports = function(grunt) {
require('lineman').init(grunt);
grunt.initConfig({
// stuff
});
// Default task.
grunt.registerTask('default', ['run']);
};
@cowboy
cowboy / Gruntfile.js
Last active December 10, 2015 21:19
Grunt: a dynamic banner can include src file lists!
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
// This has to be attached as a property of either grunt, global, or set
// in the config like so (the names here are arbitrary).
_util: {path: require('path')},
// Task config.
banner_test: {
options: {
banner: '/* (c) <%= grunt.template.today("yyyy") %>, etc.' +
@cowboy
cowboy / call-invo-cursion.js
Last active March 30, 2023 01:59
JavaScript: call invo-cursion?
// OOP
console.log( 'OHAI'.blink() );
// Call invocation
console.log( String.prototype.blink.call('OHAI') );
// $ always makes things look awesome.
var $ = Function.prototype.call;
// Very explicit call invocation
@cowboy
cowboy / Gruntfile.js
Last active December 10, 2015 15:39
grunt: why you might want to use file src-dest mapping expansions
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
minify: {
nofiles: {},
manual: {
files: [
// Why specify all src-dest mappings manually...
{src: 'lib/grunt.js', dest: 'build/grunt.min.js'},
@cowboy
cowboy / Cowboy-Exploration-Achievements-Setup.lua
Last active December 10, 2015 11:38
WoW: Exploration Achievements in GatherMate2
-- Exploration Achievements in GatherMate2 - v0.1.1 - 2013-01-04
-- by "Cowboy" Ben Alman
--
-- Requires GatherMate2 to be installed
-- Run this script ONLY ONCE in something like _DevPad
-- Remove the added nodes by re-importing GatherMate2 data.
local zones={}
zones["The Jade Forest"] = 806
zones["Dread Wastes"] = 858
@cowboy
cowboy / thing.js
Last active December 10, 2015 00:59
JavaScript: possible Node.js Ctor/.create export pattern
function Thing(prop) {
this.prop = prop;
}
Thing.prototype.toString = function() {
return "My prop is: " + this.prop;
};
// Export constructor and a .create method
function exportify(Ctor) {