Keeps your page running smoothly...
JQuery Lubricants (JQL) provides a number of helper functions intended to make code a bit more streamlined (and fun!).
Here's a rundown of what's inside...
Evaluates and returns it argument if the current selection is empty:
$selection.or('.alternative')
$selection.or($('.alternative'))
$selection.or(function () { $('.alternative') })
A new and improved map that can apply a method based on the given string:
$selection.map('offset')
$selection.map($.fn.offset)
Determines the maximum over the current selection of the given attribute:
$selection.max('width')
$selection.max($.fn.width)
Determines the minimum over the current selection of the given attribute:
$selection.min('width')
$selection.min($.fn.width)
A shortcut for .offset().top
intended to be used with the methods above:
$selection.top()
$selection.offset().top
A shortcut for .offset().left
intended to be used with the methods above:
$selection.left()
$selection.offset().left
A shortcut for .offset().right
intended to be used with the methods above:
$selection.right()
$selection.offset().right
A shortcut for .offset().bottom
intended to be used with the methods above:
$selection.bottom()
$selection.offset().bottom
A shortcut for .parent().parent()
:
$selection.grandparent()
$selection.parent().parent()
Swaps the class(es) on the left with the class(es) on the right:
$selection.swapClass ('off', 'on')
$selection.swapClass ({ off: 'on', down: 'up' })
Selects absolute and relative local URLS (sans protocol).
Selects URLs from the current domain.
Selects URLs from any external domain:
$ (document).on('click', ':external-url(href)', function () { this.target = '_blank' })