Sha256: 59c9d2769da8266fd4e00b30b3f22888846f1a42d00788aebaa8cb3ae3852c91

Contents?: true

Size: 1.16 KB

Versions: 45

Compression:

Stored size: 1.16 KB

Contents

/**
 * Version 0.0.1
 * tiny effect to display an input field when clicking on a label
 * Didier Lafforgue
 */
$.fn.editableField = function(settings) {

  var destroy = false;

  if ('destroy' == settings) {
    destroy = true
  } else {
    settings = $.extend({}, settings);
  }

  function getText(element) {
    if (element.is('select')) {
      return element[0].options[element[0].options.selectedIndex].text;
    } else {
      return element.val();
    }
  }

  return this.each(function() {
    if (destroy) {
      $(this).unbind('mouseenter').unbind('mouseleave');
      $(this).prev('.editable').unbind('click').remove();
    } else {
      var input = $(this).hide();
      var label = $('<em></em>').addClass('editable').html(getText(input));
      var timer = null;

      input.before(label);

      label.bind('click', function() {
        label.hide();
        input.show().focus();
      });

      input.hover(function() {
        clearTimeout(timer);
      }, function() {
        timer = setTimeout(function() { input.hide(); label.show() }, 1000);
      }).change(function() {
        input.hide();
        label.show().html(getText(input))
      });
    }
  });
}

Version data entries

45 entries across 45 versions & 3 rubygems

Version Path
locomotive_cms-2.5.7 vendor/assets/javascripts/locomotive/editable_field.js
locomotivecms-3.0.0.pre.alpha.2 vendor/assets/javascripts/locomotive/editable_field.js
locomotivecms-3.0.0.pre.alpha vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.6 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.6.rc2 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.6.rc1 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.5 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.4 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.3 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.2 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.1 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.0 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.0.rc3 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.0.rc2 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.5.0.rc1 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.4.1 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.4.0 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.3.1 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.3.0 vendor/assets/javascripts/locomotive/editable_field.js
locomotive_cms-2.2.3 vendor/assets/javascripts/locomotive/editable_field.js