Created
January 19, 2016 18:15
-
-
Save rudyryk/75a15acc889e0706bcd2 to your computer and use it in GitHub Desktop.
jQuery plugin for "smart" links like back button etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
jQuery plugin for "smart" links like back button etc. | |
Example: | |
// Handle elements with `data-href` as links | |
$('[data-href]').smartLinks('href'); | |
// Handle elements with `data-back` as back button | |
$('[data-back]').smartLinks('back'); | |
(c) 2016 Alexey Kinev <[email protected]> | |
The MIT License, https://opensource.org/licenses/MIT | |
*/ | |
(function ( $ ) { | |
$.fn.smartLinks = function( opts ) { | |
if ( opts == 'href' ) { | |
$( this ).off( 'click' ).on( 'click', function( e ) { | |
e.preventDefault(); | |
window.location.href = $( this ).data( 'href' ); | |
}); | |
} else if ( opts == 'back' ) { | |
$( this ).off( 'click' ).on( 'click', function( e ) { | |
e.preventDefault(); | |
window.history.back(); | |
}); | |
} | |
}; | |
}( jQuery )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment