kist-fauxanchor
Simulate default anchor action.
When run on anchor elements, it "hijacks" standard action and gives you option of running some operation (e.g. logging some statistics, sending analytics data, executing long AJAX request, etc.) before basic action or in conjuction with alternative action.
Installation
npm install kist-fauxanchor --save bower install kist-fauxanchor --save
API
$Element.fauxAnchor([options])
Returns: jQuery
Picks up necessary data from data attributes on element: href
for URL and target
for window name when run on non-anchor elements, or standard href
and target
attributes when run on standard anchor elements.
options
Type: Object|String
Object
Options defined as All methods have their this
property pointed to element on which the plugin was initiated.
basic
Type: Function
Arguments: [Event], [Default action]
Custom action to trigger on basic action (default click, left mouse button click, etc.).
Alias for this method is primary
.
alternative
Type: Function
Arguments: [Event], [Alternative action]
Custom action to trigger on alternative action (⌃ or ⌘ + left mouse button click, middle mouse button click, etc.).
Alias for this method is secondary
.
condition
Type: Function
Arguments: [Event]
If function returns true, link will be activated.
focus
Type: Boolean
Default value: true
Should the unfocusable element be focusable.
contextMenu
Type: Boolean
Default value: true
Should the unfocusable element have context menu.
anchorPreventDefault
Type: Boolean
Default value: true
Should anchor default action be prevented.
String
Options defined as Type: String
destroy
Destroy plugin instance.
prevent
Prevent plugin instance from activating actions.
unprevent
Unprevent plugin instance actions prevention.
Examples
Default structure for faux anchor.
Some content Some content
Run on list item.
;
Run on standard anchor.
;
Set custom actions.
;
Set custom actions as aliases.
;
Set condition upon which links should be activated.
;
Set option which determines should the unfocusable element be focusable.
;
Prevent plugin instance action.
;
Unprevent plugin instance action.
;
Destroy plugin instance.
;
Browser support
Tested in IE8+ and all modern browsers.
License
MIT © Ivan Nikolić