From 77bcf794e674bc5800154b84b4a5cae3871491a9 Mon Sep 17 00:00:00 2001 From: Rutger Spruyt Date: Thu, 7 Apr 2016 07:49:02 +0200 Subject: [PATCH] Added destroy option Added destroy option. This will fire then the options value is a string with the value 'destroy', it will remove the span and event listener. --- jquery.auto-grow-input.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jquery.auto-grow-input.js b/jquery.auto-grow-input.js index c59fc2e..ccd3ebb 100644 --- a/jquery.auto-grow-input.js +++ b/jquery.auto-grow-input.js @@ -10,6 +10,18 @@ var event = 'oninput' in document.createElement('input') ? 'input' : 'keydown'; $.fn.autoGrowInput = function(options){ + if (options === 'destroy') { + this.each(function() { + var input = $(this); + input.off(event + '.autogrow autogrow'); + var span = input.data("autogrowSpan"); + span.remove(); + input.data('autogrowSpan',''); + }); + + return this; + } + var o = $.extend({ maxWidth: 500, minWidth: 20, comfortZone: 0 }, options); this.each(function(){ @@ -38,6 +50,7 @@ else if (newWidth < o.minWidth) newWidth = o.minWidth; if (newWidth != input.width()) input.width(newWidth); }; + input.data("autogrowSpan", span); input.on(event+'.autogrow autogrow', check); // init on page load check();