Created
January 7, 2010 18:52
-
-
Save moneal/271455 to your computer and use it in GitHub Desktop.
little jQuery snippets that I use on most sites.
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
| $(document).ready(function () { | |
| $('a.new-window, a[rel=external]').live("click", function(){ | |
| window.open(this.href); | |
| return false; | |
| }); | |
| jQuery.fn.center = function (onTopOf) { | |
| this.css("position","absolute"); | |
| if (onTopOf == null) { | |
| this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px"); | |
| this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px"); | |
| } else { | |
| var pos = $(onTopOf).position(); | |
| this.css("top", pos.top + ( $(onTopOf).height() - this.height() ) / 2+ "px"); | |
| this.css("left", pos.left + ( $(onTopOf).width() - this.width() ) / 2+ "px"); | |
| } | |
| return this; | |
| } | |
| $("li:last-child").addClass("last-child"); | |
| $("li:first-child").addClass("first-child"); | |
| $("input[type=text]").addClass("text"); | |
| $("input[type=password]").addClass("text"); | |
| $("input[type=submit]").addClass("submit"); | |
| $("img[align='right']","#content").addClass("align-right"); | |
| $("img[align='left']","#content").addClass("align-left"); | |
| $("img[align='center']","#content").addClass("align-center"); | |
| $("img").removeAttr("vspace"); | |
| $("img").removeAttr("hspace"); | |
| swapValues = []; | |
| $(".swapValue").addClass("swapDefault"); | |
| $(".swapValue").each(function(i){ | |
| swapValues[i] = $(this).val(); | |
| $(this).focus(function(){ | |
| if ($(this).val() == swapValues[i]) { | |
| $(this).val(""); | |
| $(this).removeClass("swapDefault"); | |
| } | |
| }).blur(function(){ | |
| if ($.trim($(this).val()) == "") { | |
| $(this).val(swapValues[i]); | |
| $(this).addClass("swapDefault"); | |
| } | |
| }); | |
| }); | |
| if($.browser.msie){ | |
| $("#topNav li").hover( | |
| function () { | |
| $(this).addClass('sfhover'); | |
| }, | |
| function () { | |
| $(this).removeClass('sfhover'); | |
| } | |
| ); | |
| } | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment