Skip to content
This repository
Browse code

[textinput] Move _keyup function into the widget prototype and attach…

… it with ._on() to ensure removal upon destroy()
  • Loading branch information...
commit 34220031ce30e80a47e7fd49a22f4bfac6ec0733 1 parent 3593a88
Gabriel "_|Nix|_" Schulhof authored

Showing 1 changed file with 13 additions and 16 deletions. Show diff stats Hide diff stats

  1. 29  js/widgets/forms/textinput.js
29  js/widgets/forms/textinput.js
@@ -105,33 +105,23 @@ $.widget( "mobile.textinput", $.mobile.widget, {
105 105
 
106 106
 		// Autogrow
107 107
 		if ( input.is( "textarea" ) ) {
108  
-			var extraLineHeight = 15,
109  
-				keyupTimeoutBuffer = 100,
  108
+			var keyupTimeoutBuffer = 100,
110 109
 				keyupTimeout;
111 110
 
112  
-			this._keyup = function() {
113  
-				var scrollHeight = input[ 0 ].scrollHeight,
114  
-					clientHeight = input[ 0 ].clientHeight;
115  
-
116  
-				if ( clientHeight < scrollHeight ) {
117  
-					input.height(scrollHeight + extraLineHeight);
118  
-				}
119  
-			};
120  
-
121 111
 			input.keyup(function() {
122 112
 				clearTimeout( keyupTimeout );
123  
-				keyupTimeout = setTimeout( self._keyup, keyupTimeoutBuffer );
  113
+				keyupTimeout = setTimeout( $.proxy( self, "_keyup" ), keyupTimeoutBuffer );
124 114
 			});
125 115
 
126 116
 			// binding to pagechange here ensures that for pages loaded via
127 117
 			// ajax the height is recalculated without user input
128  
-			$( document ).one( "pagechange", this._keyup );
  118
+			$( document ).one( "pagechange", $.proxy( this, "_keyup" ) );
129 119
 
130 120
 			// Issue 509: the browser is not providing scrollHeight properly until the styles load
131 121
 			if ( $.trim( input.val() ) ) {
132 122
 				// bind to the window load to make sure the height is calculated based on BOTH
133 123
 				// the DOM and CSS
134  
-				$( window ).load( this._keyup );
  124
+				this._on( window, { load: "_keyup" } );
135 125
 			}
136 126
 		}
137 127
 		if ( input.attr( "disabled" ) ) {
@@ -139,8 +129,15 @@ $.widget( "mobile.textinput", $.mobile.widget, {
139 129
 		}
140 130
 	},
141 131
 
142  
-	_destroy: function() {
143  
-		$( window ).unbind( "load", this._keyup );
  132
+	// Used with a textarea to recalculate its height
  133
+	_keyup: function() {
  134
+		var scrollHeight = this.element[ 0 ].scrollHeight,
  135
+			clientHeight = this.element[ 0 ].clientHeight,
  136
+			extraLineHeight = 15;
  137
+
  138
+		if ( clientHeight < scrollHeight ) {
  139
+			this.element.height( scrollHeight + extraLineHeight );
  140
+		}
144 141
 	},
145 142
 
146 143
 	disable: function() {

0 notes on commit 3422003

Please sign in to comment.
Something went wrong with that request. Please try again.