Sha256: e9d5796dd97fd3ba0128ba7ca6ad383d786b39629dcfdee177f0daedb8d5884c

Contents?: true

Size: 1.59 KB

Versions: 50

Compression:

Stored size: 1.59 KB

Contents

// clear inputs with starter values
new function($) {
  $.fn.prefilledInput = function() {

    var focus = function () {
      $(this).removeClass('prefilled');
      if (this.value == this.prefilledValue) {
        this.value = '';
      }
    };

    var blur = function () {
      if (this.value == '') {
        $(this).addClass('prefilled').val(this.prefilledValue);
      } else if (this.value != this.prefilledValue) {
        $(this).removeClass('prefilled');
      }
    };

    var extractPrefilledValue = function () {
      if (this.title) {
        this.prefilledValue = this.title;
        this.title = '';
      } else if (this.id) {
        this.prefilledValue = $('label[for=' + this.id + ']').hide().text();
      }
      if (this.prefilledValue) {
        this.prefilledValue = this.prefilledValue.replace(/\*$/, '');
      }
    };

    var initialize = function (index) {
      if (!this.prefilledValue) {
        this.extractPrefilledValue = extractPrefilledValue;
        this.extractPrefilledValue();
        $(this).trigger('blur');
      }
    };

    return this.filter(":input").
      focus(focus).
      blur(blur).
      each(initialize);
  };

  var clearPrefilledInputs = function () {
    var form = this.form || this;
    $(form).find("input.prefilled, textarea.prefilled").val("");
  };

  var prefilledSetup = function () {
    $('input.prefilled, textarea.prefilled').prefilledInput();
    $('form').submit(clearPrefilledInputs);
    $('input:submit, button:submit').click(clearPrefilledInputs);
  };

  $(document).ready(prefilledSetup);
  $(document).ajaxComplete(prefilledSetup);
}(jQuery);

Version data entries

50 entries across 50 versions & 5 rubygems

Version Path
tirantes-1.0.8 templates/javascripts/prefilled_input.js
tirantes-1.0.7 templates/javascripts/prefilled_input.js
prop_up-0.0.4 templates/javascripts/prefilled_input.js
suspenders-1.7.0 templates/javascripts/prefilled_input.js
suspenders-1.6.0 templates/javascripts/prefilled_input.js
prop_up-0.0.3 templates/javascripts/prefilled_input.js
prop_up-0.0.2 templates/javascripts/prefilled_input.js
prop_up-0.0.1 templates/javascripts/prefilled_input.js
railslove-suspenders-0.1.3 templates/javascripts/prefilled_input.js
railslove-suspenders-0.1.2 templates/javascripts/prefilled_input.js
railslove-suspenders-0.1.1 templates/javascripts/prefilled_input.js
suspenders-1.5.1 templates/javascripts/prefilled_input.js
suspenders-1.5.0 templates/javascripts/prefilled_input.js
suspenders-1.4.0 templates/javascripts/prefilled_input.js
railslove-suspenders-0.1.0 templates/javascripts/prefilled_input.js
suspenders-1.3.0 templates/javascripts/prefilled_input.js
suspenders-1.2.2 templates/javascripts/prefilled_input.js
suspenders-1.2.1 templates/javascripts/prefilled_input.js
suspenders-1.2.0 templates/javascripts/prefilled_input.js
tsrails-2.0.3 template/files/prefilled_input.js