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