Created
January 13, 2009 15:09
-
-
Save sunny/46480 to your computer and use it in GitHub Desktop.
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
// Small jQuery addons by Sunny Ripert | |
// Returns a boolean to know if jQuery object contains elements | |
// Example: | |
// $('body').exists() # => true | |
// $('#doesnt_exist').exists() # => false | |
$.fn.exists = function() { | |
return $(this).length > 0; | |
} | |
// Makes links open in popups | |
// Example: | |
// $('a.popup').popup(300, 200) | |
$.fn.popup = function(width, height) { | |
$(this).each(function(i, elem) { | |
$(elem).click(function() { | |
window.open(elem.href, "", 'width='+width+',height='+height+',scrollbars=yes'); | |
return false; | |
}); | |
}); | |
} | |
// Create a tooltip from an anchor link which shows the linked element you hover the link | |
// Note: Adds the "help" class to the link and the "tooltip" class on the linked element. | |
// Example: | |
// <a href="#about" class="tip">About</a> | |
// <p id="about">Interesting facts here</p> | |
// <script>$('a.tip').tooltipize()</script> | |
$.fn.tooltipize = function() { | |
return $(this).each(function(i, elem) { | |
var link = $(elem).eq(0); | |
var tip = $(link.attr('href')).eq(0); | |
tip.hide().addClass('tooltip').css({opacity: 0.85}); | |
link.addClass('help'); | |
link.attr('title', '').find('img').attr('alt', ''); // désactive le title | |
link.click(function(){ return false }); // désactive le clic | |
// affiche et recalcule la position au survol | |
link.hover( | |
function() { // afficher | |
tip.show().css({ | |
left: 30 + link.offset().left + 'px', | |
top: 20 + link.offset().top + 'px' | |
}); | |
}, | |
function() { // cacher | |
// IE déplace des blocs au survol si on | |
// fait tip.hide() plutôt qu'un déplacement | |
tip.css({ left: -8000, top: -8000 }); | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment