Sha256: a0310505bb35f17eddc2f4c6193f0fed971d49a5b51d7cfd944b1080d113ff22

Contents?: true

Size: 1.92 KB

Versions: 13

Compression:

Stored size: 1.92 KB

Contents

//
// jQuery autoHint
//
// v0.2.0
// Ken Seal hunzinker@gmail.com
// License: MIT

(function($) {

  var methods = {

    init: function() {
      return this.each(function() {
        var $this = $(this);
        $this.autoHint('addHints');
        $this.autoHint('focusHint');
        $this.autoHint('blurHint');
      });
    },

    // Add hints to the form elements.
    addHints: function() {
      return this.each(function() {
        var $this = $(this);
        if ($this.attr('title') === '') {
          return;
        }

        if ($this.val() === '') {
          $this.val($this.attr('title'));

          if (!$this.hasClass('auto-hint')) {
            $this.addClass('auto-hint');
          }
        } else {
          $this.removeClass('auto-hint');
        }
      });
    },

    // Remove hint and class on focus.
    focusHint: function() {
      return this.focus(function() {
        var $this = $(this);
        if ($this.val() === $this.attr('title')) {
          $this.val('');
          $this.removeClass('auto-hint');
        }
      });
    },

    // Retain value or add hint.
    blurHint: function() {
      return this.blur(function() {
        var $this = $(this);
        if ($this.val() === '' && $this.attr('title') !== '') {
          $this.val($this.attr('title'));
          $this.addClass('auto-hint');
        }
      });
    },

    // Remove hints.
    removeHints: function() {
      return this.each(function() {
        var $this = $(this);
        if ($this.val() === $this.attr('title')) {
          $this.val('');
        }
      });
    }

  };

  $.fn.autoHint = function(method) {

    if (methods[method]) {
      return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
      return methods.init.apply(this, arguments);
    } else {
      $.error('Method ' +  method + ' does not exist for jQuery autoHint.');
    }

  };

})(jQuery);

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
quorum-0.8.2 vendor/assets/javascripts/jquery.autohint.js
quorum-0.8.1 vendor/assets/javascripts/jquery.autohint.js
quorum-0.8.0 vendor/assets/javascripts/jquery.autohint.js
quorum-0.7.1 vendor/assets/javascripts/jquery.autohint.js
quorum-0.7.0 vendor/assets/javascripts/jquery.autohint.js
quorum-0.6.0 vendor/assets/javascripts/jquery.autohint.js
quorum-0.5.2 vendor/assets/javascripts/jquery.autohint.js
quorum-0.5.1 vendor/assets/javascripts/jquery.autohint.js
quorum-0.5.0 vendor/assets/javascripts/jquery.autohint.js
quorum-0.4.0 vendor/assets/javascripts/jquery.autohint.js
quorum-0.3.3 vendor/assets/javascripts/jquery.autohint.js
quorum-0.3.2 vendor/assets/javascripts/jquery.autohint.js
quorum-0.3.1 vendor/assets/javascripts/jquery.autohint.js