1. (function($){
  2.  
  3. /* ----
  4.   superLink jQuery plugin
  5.   (c) James Padolsey
  6.   ----
  7.   Contributors:
  8.   Brian Fisher
  9.   */
  10.  
  11. $.fn.superLink = function(link) {
  12. link = link || 'a:first';
  13. return this.each(function(){
  14.  
  15. var $container = $(this),
  16. $targetLink = $(link, $container).clone(true);
  17.  
  18. /* Take all current mouseout handlers of $container and
  19.   transfer them to the mouseout handler of $targetLink */
  20. var mouseouts = $(this).data('events') && $(this).data('events').mouseout;
  21. if (mouseouts) {
  22. $.each(mouseouts, function(i, fn){
  23. $targetLink.mouseout(function(e){
  24. fn.call($container, e);
  25. });
  26. });
  27. delete $(this).data('events').mouseout;
  28. }
  29.  
  30. /* Take all current mouseover handlers of $container and
  31.   transfer them to the mouseover handler of $targetLink */
  32. var mouseovers = $(this).data('events') && $(this).data('events').mouseover;
  33. if (mouseovers) {
  34. $.each(mouseovers, function(i, fn){
  35. $targetLink.mouseover(function(e){
  36. fn.call($container, e);
  37. });
  38. });
  39. delete $(this).data('events').mouseover;
  40. }
  41.  
  42. $container.mouseover(function(){
  43. $targetLink.show();
  44. });
  45.  
  46. $targetLink
  47. .click(function(){
  48. $targetLink.blur();
  49. })
  50. .mouseout(function(e){
  51. $targetLink.hide();
  52. })
  53. .css({
  54. position: 'absolute',
  55. top: $container.offset().top,
  56. left: $container.offset().left,
  57. /* IE requires background to be set */
  58. backgroundColor: '#FFF',
  59. display: 'none',
  60. opacity: 0,
  61. width: $container.outerWidth(),
  62. height: $container.outerHeight(),
  63. padding: 0
  64. })
  65. .appendTo('body');
  66.  
  67. });
  68. };
  69.  
  70. })(jQuery);

ALL COPYRIGHT © James Padolsey unless otherwise specified
Go back to the top