I think you look at it from the point of view of the user. You should think about it from a developer's point of view. Consider the following example. In this example, we provide the user with the following functions:
- When a user clicks on a link, our plugin displays a warning
- There are two possibilities:
- User can use our function (see warning)
- Or, you might want to define your own functionality.
Allows you to define our plugin
$('a').on('click', function (e) {
How is this feature used now?
In this case, the user chooses to use the default function, and therefore a click on the href button is displayed.
$('#case1').on('slide', function (e) {
In this case, the user selects the definition of user functionality and, therefore, e.preventDefault used. (Which falls into our plugin definition in isDefaultPrevented() )
$('#case2').on('slide', function (e) { e.preventDefault(); });
Full example:
$('a').on('click', function (e) { var slideEvent = $.Event('slide'); e.preventDefault(); $(this).trigger(slideEvent); if (slideEvent.isDefaultPrevented()) { alert('is default prevented'); return; } alert('clicked on href'); }) $('#case1').on('slide', function (e) {
$('a').on('click', function (e) { var slideEvent = $.Event('slide'); e.preventDefault(); $(this).trigger(slideEvent); if (slideEvent.isDefaultPrevented()) { alert('is default prevented'); return; } alert('clicked on href'); }) $('#case1').on('slide', function (e) {
a { font-size: 3em; text-decoration: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="http://stackoverflow.com/" id="case1">Case 1</a> <a href="http://stackoverflow.com/" id="case2">Case 2</a>
Dhiraj
source share