Severed Crossed Fingers

When your calling ain’t calling back to you
I’ll be side-stage mouthing lines for you
Humiliated by age, terrified of youth
I got hope but my hope isn’t helping you

Wake up puddle-eyed, sleeping in a suit
The truth is ugly well, I feel ugly too
We’ll be heroes on every bar stool
Seeing double beats not seeing one of you

Spitting our guts from their gears
Draining our spleen over years
Found my severed crossed fingers in the rubble there

Well you stole the heart right out my chest
Changed the words that I know best
Found my severed crossed fingers in the rubble there

St. Vincent

Assigning DOM Elements to a Plugin

After writing hundreds of jQuery plugins, I found this pattern for assigning DOM elements to a plugin using data attributes. Here goes:

Markup

In the markup, add data attributes that follow this pattern: data-plugin-elem-mypluginname

<div class="carousel-container">
	<div class="carousel-wrap" data-plugin-elem-mypluginname="carouselWrap">
		<div class="carousel" data-plugin-elem-mypluginname="carousel">
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
			<div class="carouselTile" data-plugin-elem-mypluginname="carouselTile"></div>
		</div>
	</div>

	<div class="controls">
		<a class="prev" href="#todo-prev" data-direction="prev" data-plugin-elem-mypluginname="controlPrev">
			&laquo;Prev
		</a>

		<a class="next" href="#todo-next" data-direction="next" data-plugin-elem-mypluginname="controlNext">
			&raquo;Next
		</a>
	</div>
</div>

Having the assignment in a data attribute accomplishes two things:

  1. The attribute name includes the plugin name so the markup clearly defines the association between the element and the plugin
  2. The classes are left to be used only by CSS as they were intended. If you’re working with a web designer, they can rename and reorganize the CSS classes as they see fit without disabling your plugin’s functionality and throwing Javascript errors.

Javascript Plugin

In the plugin, pull all the elements into one object for easy access:

$.fn.myPluginName = function( options ) {

	var getPluginElements = function() {

		var $pluginEls 	= _$elem.find('[data-plugin-elem-mypluginname]');
		var $els 		= {};

		$.each($pluginEls, function(i, el) {

			var $el 	= $(el);
			var elKey 	= $el.data('plugin-elem-mypluginname');

			if (typeof $els[elKey] == 'object') {
				$els[elKey] 	= $els[elKey].add($el);
			} else {
				$els[elKey] 	= $el;
			}
		});

		return $els;
	};

	var _$elem 	= $(this);
	var _$els 	= getPluginElements();

	// Your code goes here!
};

Then you can access the object properties directly as a jQuery element:

_$els.controlPrev.click();

_$els.carousel.animate(
	{ 'left': -1000 },
	{
		'duration': 1500,
		'easing': 'easeInOutQuint',
		'queue': false
	}
);

$.each(_$els.carouselTile, function(i, el) {
	// Your code goes here!
});

Sky High

… throwing him up like an angel, high above the red earth, deep into the sparkling blank, the tender sky that never once let him down, preserving his attachment to youth, propriety and kindness, his plane almost, but never quite, outracing his whoops of joy, trailing him in his sudden turn to the wind, followed then by a near vertical climb up to the angles of the sun, and I was barely eight and still with him and yes, that was the thought that flickered madly through me, a brief instant of communion, possessing me with warmth and ageless ease, causing me to smile again and relax as if memory alone could lift the heart like the wind lifts a wing, and so I renewed my kisses with even greater enthusiasm, caressing and in turn devouring their dark lips, dark with wine and fleeting love, an ancient memory love had promised but then finally never gave, until there were too many kisses to count or remember, and the memory of love proved not love at all and needed a replacement, which our bodies found, and then the giggles subsided, and the laughter dimmed, and darkness enfolded all of us and we gave away our childhood for nothing and we died and condoms littered the floor and Christina threw up in the sink and Amber chuckled and kissed me a little more, but in a way that told me it was time to leave.

–House of Leaves, Mark Z. Danielewski

Cleanliness Godliness

  1. Naturally an animal wants to clean itself after the kill.
  2. Translate modern society in which clean and flawless appearance are symbols of dominance.
  3. Infer my proclivity for trusting unkempt people is instinctual.