virtuallist: Prevent replacing contents on nonexist element
authorYoumin Ha <youmin.ha@samsung.com>
Thu, 24 Jan 2013 08:19:16 +0000 (17:19 +0900)
committerYoumin Ha <youmin.ha@samsung.com>
Thu, 24 Jan 2013 11:50:15 +0000 (20:50 +0900)
When a page having virtuallist is inactive, while 'move callback timer'
is still run, the source listitem is no longer exists. In this case,
jQuery's $('#id') result gives a blank array, not null object. But the
old code, virtuallist tries to replace listitem contents even no object
is chosen. The patch fixes this bug, and includes some more guard codes.

Change-Id: I0bc4e6310c39c42ce35456b54d3d1d926816a485

src/widgets/virtuallist/js/jquery.mobile.tizen.virtuallistview.js

index 03c1c81..30e699e 100755 (executable)
 
                                        // Find current item
                                        item = $( '#' + vl.options.itemIDPrefix + fromIdx );    // TODO: refactor ID generation!
-                                       if ( ! item ) {
+                                       if ( ! item || ! item.length ) {
                                                return false;
                                        }
 
                                        // Get new item
                                        tmpl = $( "#" + vl.options.template );
-                                       newItem = tmpl.tmpl( vl._itemData( toIdx ) );
+                                       if ( tmpl ) {
+                                               newItem = tmpl.tmpl( vl._itemData( toIdx ) );
 
-                                       // TODO: Consider touch block while moving?
+                                               // TODO: Consider touch block while moving?
 
-                                       // Move item contents
-                                       moveItemContents( vl, item, newItem );
+                                               // Move item contents
+                                               moveItemContents( vl, item, newItem );
 
-                                       // clean up temporary item
-                                       newItem.remove();
+                                               // clean up temporary item
+                                               newItem.remove();
+                                       }
 
                                        // Move position, and set id
                                        item.css( 'top', toIdx * vl._line_h )
                                }
                        } else {        // No option is given
                                // Legacy support: dbtable
-                               console.log("WARNING: The data interface of virtuallist is changed. \nOld data interface(data-dbtable) is still supported, but will be removed in next version. \nPlease fix your code soon!");
+                               console.warn( "WARNING: The data interface of virtuallist is changed. \nOld data interface(data-dbtable) is still supported, but will be removed in next version. \nPlease fix your code soon!" );
 
                                /* After DB Load complete, Init Vritual list */
                                if ( $( o.id ).hasClass( "vlLoadSuccess" ) ) {
                        $( window ).unbind( "resize.virtuallist" );
 
                        $( o.id ).empty();
+
+                       if ( this.timerMoveID ) {
+                               clearTimeout( this.timerMoveID );
+                               this.timerMoveID = null;
+                       }
                },
 
                _itemApply: function ( $list, item ) {