Using the prettyPhoto plugin to open modal-style content containers, and trying to integrate with Google Analytics\' Event Tracking to track when videos get opened.
Ideally, you would be able to add your event binding before any others, so that it executes first.
Unfortunately, jQuery doesn't seem to include any such facility.
However, I've coded a preBind method, which seems to do the trick:
$.fn.preBind = function(type, data, fn) {
this.bind(type, data, fn);
var currentBindings = this.data('events')[type];
var currentBindingsLastIndex = currentBindings.length - 1;
var newBindings = [];
newBindings.push(currentBindings[currentBindingsLastIndex]);
$.each(currentBindings, function (index) {
if (index < currentBindingsLastIndex)
newBindings.push(this);
});
this.data('events')[type] = newBindings;
return this;
};
Usage:
$('#button').bind('click', function() {
console.log('world');
});
// 2nd apostrophe for the selector was missing
$('#button').preBind('click', function() {
console.log('hello');
});
$('#button').click();
// Output:
//
// > "hello"
// > "world"