Skip to content
This repository

Fixed memory leaks for issue 4419 #4427

Closed
wants to merge 3 commits into from

1 participant

Michael Ridland
Michael Ridland
rid00z commented

Fixed for slider forms and textinput forms. There might also be similar issues in other forms.

rid00z added some commits
Michael Ridland rid00z Fixed memory leak issue 4419 6702759
Michael Ridland rid00z Revert "Fixed memory leak issue 4419"
This reverts commit 67027598b5926b94427f5821b9d248678a19ef07.
deace7f
Michael Ridland rid00z Fixed memory leaks for issue 4419
Fixed for slider forms and textinput forms. There might also be similar
issues in other forms.
7ea39b2
Michael Ridland rid00z closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

May 24, 2012
Michael Ridland rid00z Fixed memory leak issue 4419 6702759
Michael Ridland rid00z Revert "Fixed memory leak issue 4419"
This reverts commit 67027598b5926b94427f5821b9d248678a19ef07.
deace7f
Michael Ridland rid00z Fixed memory leaks for issue 4419
Fixed for slider forms and textinput forms. There might also be similar
issues in other forms.
7ea39b2
This page is out of date. Refresh to see the latest.
122 js/jquery.mobile.forms.slider.js
@@ -16,7 +16,67 @@ $.widget( "mobile.slider", $.mobile.widget, {
16 16 initSelector: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')",
17 17 mini: false
18 18 },
19   -
  19 +
  20 + virtualMouseUp: function () {
  21 + var self = this,
  22 + domHandle = document.createElement('a'),
  23 + handle = $(domHandle);
  24 +
  25 + if (self.dragging) {
  26 +
  27 + self.dragging = false;
  28 +
  29 + if (cType === "select") {
  30 +
  31 + // make the handle move with a smooth transition
  32 + handle.addClass("ui-slider-handle-snapping");
  33 +
  34 + if (self.mouseMoved) {
  35 +
  36 + // this is a drag, change the value only if user dragged enough
  37 + if (self.userModified) {
  38 + self.refresh(self.beforeStart == 0 ? 1 : 0);
  39 + }
  40 + else {
  41 + self.refresh(self.beforeStart);
  42 + }
  43 +
  44 + }
  45 + else {
  46 + // this is just a click, change the value
  47 + self.refresh(self.beforeStart == 0 ? 1 : 0);
  48 + }
  49 +
  50 + }
  51 +
  52 + self.mouseMoved = false;
  53 +
  54 + return false;
  55 + }
  56 + },
  57 +
  58 + preventScreenDrag: function (event) {
  59 + var self = this,
  60 + domHandle = document.createElement('a'),
  61 + handle = $(domHandle);
  62 +
  63 + if (self.dragging) {
  64 + // self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
  65 + self.mouseMoved = true;
  66 +
  67 + if (cType === "select") {
  68 + // make the handle move in sync with the mouse
  69 + handle.removeClass("ui-slider-handle-snapping");
  70 + }
  71 +
  72 + self.refresh(event);
  73 +
  74 + // only after refresh() you can calculate self.userModified
  75 + self.userModified = self.beforeStart !== control[0].selectedIndex;
  76 + return false;
  77 + }
  78 + },
  79 +
20 80 _create: function() {
21 81
22 82 // TODO: Each of these should have comments explain what they're for
@@ -146,23 +206,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
146 206 });
147 207
148 208 // prevent screen drag when slider activated
149   - $( document ).bind( "vmousemove", function( event ) {
150   - if ( self.dragging ) {
151   - // self.mouseMoved must be updated before refresh() because it will be used in the control "change" event
152   - self.mouseMoved = true;
153   -
154   - if ( cType === "select" ) {
155   - // make the handle move in sync with the mouse
156   - handle.removeClass( "ui-slider-handle-snapping" );
157   - }
158   -
159   - self.refresh( event );
160   -
161   - // only after refresh() you can calculate self.userModified
162   - self.userModified = self.beforeStart !== control[0].selectedIndex;
163   - return false;
164   - }
165   - });
  209 + $( document ).bind("vmousemove", self.preventScreenDrag);
166 210
167 211 slider.bind( "vmousedown", function( event ) {
168 212 self.dragging = true;
@@ -178,40 +222,7 @@ $.widget( "mobile.slider", $.mobile.widget, {
178 222 })
179 223 .bind( "vclick", false );
180 224
181   - slider.add( document )
182   - .bind( "vmouseup", function() {
183   - if ( self.dragging ) {
184   -
185   - self.dragging = false;
186   -
187   - if ( cType === "select") {
188   -
189   - // make the handle move with a smooth transition
190   - handle.addClass( "ui-slider-handle-snapping" );
191   -
192   - if ( self.mouseMoved ) {
193   -
194   - // this is a drag, change the value only if user dragged enough
195   - if ( self.userModified ) {
196   - self.refresh( self.beforeStart == 0 ? 1 : 0 );
197   - }
198   - else {
199   - self.refresh( self.beforeStart );
200   - }
201   -
202   - }
203   - else {
204   - // this is just a click, change the value
205   - self.refresh( self.beforeStart == 0 ? 1 : 0 );
206   - }
207   -
208   - }
209   -
210   - self.mouseMoved = false;
211   -
212   - return false;
213   - }
214   - });
  225 + $( document ).bind("vmouseup", self.virtualMouseUp)
215 226
216 227 slider.insertAfter( control );
217 228
@@ -293,7 +304,12 @@ $.widget( "mobile.slider", $.mobile.widget, {
293 304
294 305 this.refresh(undefined, undefined, true);
295 306 },
296   -
  307 +
  308 + _destory: function () {
  309 + $(document).unbind("vmousemove", this.preventScreenDrag);
  310 + $(document).unbind("vmouseup", this.virtualMouseUp);
  311 + },
  312 +
297 313 refresh: function( val, isfromControl, preventInputUpdate ) {
298 314
299 315 if ( this.options.disabled || this.element.attr('disabled')) {
20 js/jquery.mobile.forms.textinput.js
@@ -16,7 +16,16 @@ $.widget( "mobile.textinput", $.mobile.widget, {
16 16 initSelector: "input[type='text'], input[type='search'], :jqmData(type='search'), input[type='number'], :jqmData(type='number'), input[type='password'], input[type='email'], input[type='url'], input[type='tel'], textarea, input[type='time'], input[type='date'], input[type='month'], input[type='week'], input[type='datetime'], input[type='datetime-local'], input[type='color'], input:not([type])",
17 17 clearSearchButtonText: "clear text"
18 18 },
19   -
  19 +
  20 + keyup: function () {
  21 + var input = this.element,
  22 + scrollHeight = input[0].scrollHeight,
  23 + clientHeight = input[0].clientHeight;
  24 +
  25 + if (clientHeight < scrollHeight) {
  26 + input.height(scrollHeight + extraLineHeight);
  27 + }
  28 + },
20 29 _create: function() {
21 30
22 31 var input = this.element,
@@ -121,17 +130,22 @@ $.widget( "mobile.textinput", $.mobile.widget, {
121 130
122 131 // binding to pagechange here ensures that for pages loaded via
123 132 // ajax the height is recalculated without user input
124   - $( document ).one( "pagechange", keyup );
  133 + $( document ).one("pagechange", self.keyup);
125 134
126 135 // Issue 509: the browser is not providing scrollHeight properly until the styles load
127 136 if ( $.trim( input.val() ) ) {
128 137 // bind to the window load to make sure the height is calculated based on BOTH
129 138 // the DOM and CSS
130   - $( window ).load( keyup );
  139 + $( window ).load(self.keyup);
131 140 }
132 141 }
133 142 },
134 143
  144 + _destroy: function () {
  145 + $(document).unbind("pagechange", this.keyup);
  146 + $(window).unbind("load", this.keyup);
  147 + },
  148 +
135 149 disable: function(){
136 150 ( this.element.attr( "disabled", true ).is( "[type='search'],:jqmData(type='search')" ) ?
137 151 this.element.parent() : this.element ).addClass( "ui-disabled" );
2  js/jquery.ui.widget.js
@@ -247,12 +247,14 @@ $.Widget.prototype = {
247 247 // we can probably remove the unbind calls in 2.0
248 248 // all event bindings should go through this._bind()
249 249 this.element
  250 + .unbind() // elements created dynamically don't have widget in event name
250 251 .unbind( "." + this.widgetName )
251 252 // 1.9 BC for #7810
252 253 // TODO remove dual storage
253 254 .removeData( this.widgetName )
254 255 .removeData( this.widgetFullName );
255 256 this.widget()
  257 + .unbind() // elements created dynamically don't have widget in event name
256 258 .unbind( "." + this.widgetName )
257 259 .removeAttr( "aria-disabled" )
258 260 .removeClass(

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.