Skip to content

Instantly share code, notes, and snippets.

@roberocity
Created March 1, 2012 19:22
Show Gist options
  • Save roberocity/1952451 to your computer and use it in GitHub Desktop.
Save roberocity/1952451 to your computer and use it in GitHub Desktop.
jQuery Plugins
(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 );
//<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