Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- $.fn.placeholder = function(options) {this.each(function() {
- var cfg = $.extend({
- data_prefix: '_ph_',
- placeholder_class: 'placeholder',
- webkit_disable: true
- }, options);
- if ($.browser.webkit && cfg.webkit_disable) return false;
- if($(this).attr("type") == "password") {
- var placeholder = $(this)
- .clone(false)
- .data(cfg.data_prefix + 'original', $(this))
- .attr('type', 'text')
- .removeAttr('name')
- .removeAttr('id')
- .removeAttr('placeholder')
- .addClass(cfg.placeholder_class)
- .val($(this).attr('placeholder'))
- .insertAfter(this);
- $(this).data(cfg.data_prefix + 'placeholder', placeholder);
- var original = $(this);
- if (original.val() === '') {
- placeholder.show();
- original.hide();
- }
- else {
- placeholder.hide();
- original.show();
- }
- placeholder.focus(function() {
- $(this).hide().data(cfg.data_prefix + 'original').show().focus();
- });
- original.blur(function() {
- if ($(this).val() == '') {
- $(this).hide().data(cfg.data_prefix + 'placeholder').show();
- }
- });
- } else {
- if($(this).val() === "" || $(this).val() === $(this).attr("placeholder")) {
- $(this).val($(this).attr("placeholder"));
- $(this).addClass(cfg.placeholder_class);
- }
- $(this).focus(function() {
- if($(this).val() === $(this).attr("placeholder")) {
- $(this).removeClass(cfg.placeholder_class);
- $(this).val("");
- }
- }).blur(function() {
- if($(this).val() === "") {
- $(this).addClass(cfg.placeholder_class);
- $(this).val($(this).attr("placeholder"));
- }
- });
- }
- });}
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement