Created
March 1, 2012 19:22
-
-
Save roberocity/1952451 to your computer and use it in GitHub Desktop.
jQuery Plugins
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
(function( $ ) { | |
$.fn.maxHeight = function() { | |
var max = 0; | |
this.each(function() { | |
max = Math.max(max, $(this).height() ); | |
}); | |
return max; | |
}; | |
$.fn.equalizeHeight = function() { | |
var max = this.maxHeight(); | |
this.each(function() { | |
$(this).height(max); | |
}); | |
}; | |
})( jQuery ); |
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
//<script type="text/javascript"> | |
// $(document).ready(function() { | |
// var mx = $('.m').equalizeHeight(); | |
// $('#max').text(mx); | |
// $('body').placeholder(); | |
// // or with custom class name $('body').placeholder({placeholderClass:'css_class_name'}); | |
// }); | |
//</script> | |
// css | |
// .placeholder { color: #ccc; } | |
(function( $ ) { | |
jQuery.support.placeholder = false; | |
test = document.createElement('input'); | |
if('placeholder' in test) jQuery.support.placeholder = true; | |
$.fn.placeholder = function( options ) { | |
var settings = $.extend( { | |
'placeholderClass' : 'placeholder' | |
}, options); | |
if(!jQuery.support.placeholder) { | |
this.each(function() { | |
$('form', this).bind('submit', function() { | |
$('input[placeholder]', this).each(function() { | |
if($(this).val() == $(this).attr('placeholder')) $(this).val(''); | |
}); | |
}); | |
$('input[placeholder]', this).each(function() { | |
$(this).val($(this).attr('placeholder')); | |
$(this).addClass(settings.placeholderClass); | |
$(this).bind('focus', function() { | |
if($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) { | |
$(this).removeClass(settings.placeholderClass); | |
$(this).val(''); | |
} | |
}); | |
$(this).bind('blur', function() { | |
if($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) { | |
$(this).addClass(settings.placeholderClass); | |
$(this).val($(this).attr('placeholder')); | |
} | |
}); | |
}); | |
}); | |
} | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment