& working with new HTML5 APIs
( gul.ly/10x )
boazsender.com
github.com/boazsender
@boazsender
boaz on freenode (/msg boaz)
window.addEventListener('eventtype', function( eventObj ){
// do stuff with your event object
});
$(elem).bind('eventtype', function( eventObj ){
// do stuff with your event object
});
$('.targeted').click(function( eventObj ){
// do stuff with your event object
console.log( eventObj.target )
});
$(elem).bind('☺_video_☆_capture__☆_event_☺', function( event ){
event.videoBuffer // nope
event.videoBuffer // nope
});
$(elem).bind('☺_video_☆_capture__☆_event_☺', function( event ){
event.originalEvent.videBuffer // mhmmm
});
$('.clicklogger').click(function( event ){
var extraProps = [];
$.each( event.originalEvent, function( index, prop ){
if ( ! event[ index ] ) {
extraProps.push( index )
}
})
console.log("event:", event)
console.log("original event:", event.originalEvent)
console.log("extra props", extraProps)
})
// Native DOM interface
window.addEventListener('click', function(){ ... });
// jQuery interface
$(elem).bind('click', function(){ ... });
// jQuery shorthand interface
$(elem).click(function(){ ... });
MDC HashChangeEvent, jQuery Hashchange Plugin [source]
// Native DOM interface
window.addEventListener( 'hashchange', function(){ ... } )
// jQuery interface
$(window).bind( 'hashchange', function(){ ... } )
// jQuery Hashchange Plugin interface
$(window).hashchange( function(){ ... } )
// Native DOM interface
window.addEventListener( 'popstate', function(){ ... } );
// jQuery interface
$(window).bind( 'popstate', function(){ ... } );
// Native DOM interface
window.addEventListener( 'message', function(){ ... } )
// jQuery interface
$(window).bind( 'message', function(){ ... } )
$('.popupDemo').click(function(){
// Make a Popup
var popup = window
.open(
"http://localhost:8888/talks/understanding-jquery-events/popup.html",
"Bocoup",
"width=400,height=800"
);
setTimeout(function(){
popup
.postMessage(
"Marco",
"http://localhost:8888/talks/understanding-jquery-events/popup.html"
);
}, 1000)// Send a message to the Popup
// Listen to messages from the popup
$(window).bind('message', function( event ){
console.log( event.originalEvent.data )
});
// What's in the popup
$(window).bind('message', function( event ){
$('body').html( event.originalEvent.data )
event.originalEvent.source
.postMessage(
event.originalEvent.data + "? well, polo",
event.originalEvent.origin
);
});
// Native DOM interface
window.addEventListener( 'drop', function(){ ... } )
// jQuery interface
$(window).bind( 'drop', function(){ ... } )
var dropzone = $('#dropzone')
.bind('dragenter', function( event ){
event.stopPropagation();
event.preventDefault();
$('#tank').css('background', '#061552');
})
.bind('dragover', function(){
$('#tank').css('background', '#248aba');
})
.bind( 'drop', function( event ) {
event.stopPropagation();
event.preventDefault();
var files = event.originalEvent.dataTransfer.files;
$.each( files, function(index, file){
var fileReader = new FileReader();
fileReader.onload = (function(file) {
return function( event ) {
$('#tank').html( file.fileName +
'
' +
'<img src=' + event.target.result + '></p>')
};
})(file);
fileReader.readAsDataURL(file);
});
});
W3C Media Events Test Page, MDC Media Events List, Popcorn.js
// Native DOM interface
document
.getElementById('video')
.addEventListener('timeupdate', function(e){ ... })
// jQuery interface
$('#video').bind('timeupdate', function(){ ... })
timeStamp:
$('#video').bind('timeupdate', function( event ){
console.log( event )
})
// Native DOM interface
document
.getElementById( 'audio' )
.addEventListener( 'MozAudioAvailable', function(){ ... });
// jQuery interface
$('audio').bind( 'MozAudioAvailable', function(){ ... });
$('#audio').bind('timeupdate', function( event ){
console.log( event )
})
props: "altKey attrChange attrName bubbles button" +
"cancelable charCode clientX clientY ctrlKey currentTarget" +
"data detail eventPhase fromElement handler keyCode layerX" +
"layerY metaKey newValue offsetX offsetY pageX pageY" +
"prevValue relatedNode relatedTarget screenX screenY" +
"shiftKey srcElement target toElement view wheelDelta" +
"which".split(" "),
for ( var i = this.props.length, prop; i; ) {
prop = this.props[ --i ];
event[ prop ] = originalEvent[ prop ];
}
jQuery.event.props.push( 'dataTransfer' );
jQuery.event.props["drop"] = { dataTransfer: undefined };
console.log( jQuery.event.props );
console.log( jQuery.event.props[ 'drop' ] );