Initial Commit
This commit is contained in:
parent
4c352bf02e
commit
1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions
49
plugins/jetpack/_inc/lib/tracks/tracks-ajax.js
Normal file
49
plugins/jetpack/_inc/lib/tracks/tracks-ajax.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* global jpTracksAJAX, jQuery */
|
||||
|
||||
(function( $, jpTracksAJAX ) {
|
||||
|
||||
$( document ).ready( function () {
|
||||
$( 'body' ).on( 'click', '.jptracks a, a.jptracks', function( event ) {
|
||||
|
||||
// We know that the jptracks element is either this, or its ancestor
|
||||
var $jptracks = $( this ).closest( '.jptracks' );
|
||||
|
||||
var data = {
|
||||
tracksNonce: jpTracksAJAX.jpTracksAJAX_nonce,
|
||||
action: 'jetpack_tracks',
|
||||
tracksEventType: 'click',
|
||||
tracksEventName: $jptracks.attr( 'data-jptracks-name' ),
|
||||
tracksEventProp: $jptracks.attr( 'data-jptracks-prop' ) || false
|
||||
};
|
||||
|
||||
// We need an event name at least
|
||||
if ( undefined === data.tracksEventName ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var url = $( this ).attr( 'href' );
|
||||
var target = $( this ).get( 0 ).target;
|
||||
if ( url && target && '_self' !== target ) {
|
||||
var newTabWindow = window.open( '', target );
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: jpTracksAJAX.ajaxurl,
|
||||
data: data
|
||||
} ).always( function() {
|
||||
// Continue on to whatever url they were trying to get to.
|
||||
if ( url ) {
|
||||
if ( newTabWindow ) {
|
||||
newTabWindow.location = url;
|
||||
return;
|
||||
}
|
||||
window.location = url;
|
||||
}
|
||||
} );
|
||||
});
|
||||
});
|
||||
|
||||
})( jQuery, jpTracksAJAX );
|
Reference in a new issue