Advertisement
Guest User

Untitled

a guest
May 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function($){
  2.     $.fn.placeholder = function(options) {this.each(function() {
  3.         var cfg = $.extend({
  4.             data_prefix: '_ph_',
  5.             placeholder_class: 'placeholder',
  6.             webkit_disable: true
  7.         }, options);
  8.  
  9.         if ($.browser.webkit && cfg.webkit_disable) return false;
  10.  
  11.         if($(this).attr("type") == "password") {
  12.  
  13.             var placeholder = $(this)
  14.                 .clone(false)
  15.                 .data(cfg.data_prefix + 'original', $(this))
  16.                 .attr('type', 'text')
  17.                 .removeAttr('name')
  18.                 .removeAttr('id')
  19.                 .removeAttr('placeholder')
  20.                 .addClass(cfg.placeholder_class)
  21.                 .val($(this).attr('placeholder'))
  22.                 .insertAfter(this);
  23.  
  24.             $(this).data(cfg.data_prefix + 'placeholder', placeholder);
  25.  
  26.             var original = $(this);
  27.  
  28.             if (original.val() === '') {
  29.                 placeholder.show();
  30.                 original.hide();
  31.             }
  32.             else {
  33.                 placeholder.hide();
  34.                 original.show();
  35.             }
  36.  
  37.             placeholder.focus(function() {
  38.                 $(this).hide().data(cfg.data_prefix + 'original').show().focus();
  39.             });
  40.  
  41.             original.blur(function() {
  42.                 if ($(this).val() == '') {
  43.                     $(this).hide().data(cfg.data_prefix + 'placeholder').show();
  44.                 }
  45.             });
  46.  
  47.         } else {
  48.  
  49.             if($(this).val() === "" || $(this).val() === $(this).attr("placeholder")) {
  50.                 $(this).val($(this).attr("placeholder"));
  51.                 $(this).addClass(cfg.placeholder_class);
  52.             }
  53.  
  54.             $(this).focus(function() {
  55.                 if($(this).val() === $(this).attr("placeholder")) {
  56.                     $(this).removeClass(cfg.placeholder_class);
  57.                     $(this).val("");
  58.                 }
  59.             }).blur(function() {
  60.                 if($(this).val() === "") {
  61.                     $(this).addClass(cfg.placeholder_class);
  62.                     $(this).val($(this).attr("placeholder"));
  63.                 }
  64.             });
  65.         }
  66.     });}
  67. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement