virtuallist: fix unique listitem ID bug
authorYoumin Ha <youmin.ha@samsung.com>
Tue, 15 Jan 2013 06:06:27 +0000 (15:06 +0900)
committerMinkyu Kang <mk7.kang@samsung.com>
Tue, 15 Jan 2013 07:26:06 +0000 (16:26 +0900)
Each <li> element has its own id, but its format is quite simple, like
'li_<number>'. This id can be duplicated when 2 or more virtuallist
widget are used together.
Added virtuallist element's id as the prefix of IDs of each li element.

Change-Id: I94292be2011327ba626407780ffa287d28367ccb

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

index 8be7b28..8c8d1fe 100755 (executable)
 
                        for ( i = 0; i < lastIndex; i++ ) {
                                htmlData = myTemplate.tmpl( this._itemData( i ) );
-                               $( o.id ).append( $( htmlData ).attr( 'id', 'li_' + i ) );
+                               $( o.id ).append( $( htmlData ).attr( 'id', o.itemIDPrefix + i ) );
                        }
 
                        /* After push data, re-style virtuallist widget */
                                                break;
                                        }
 
-                                       cur_item = $( '#li_' + ( v_firstIndex + i ) );
+                                       cur_item = $( '#' + o.itemIDPrefix + ( v_firstIndex + i ) );
 
                                        if ( cur_item ) {
                                                /* Make New <LI> element from template. */
                                                htmlData.remove();
 
                                                /* Set New Position */
-                                               ( cur_item ).css( 'top', t._title_h + t._line_h * ( v_lastIndex + 1 + i ) ).attr( 'id', 'li_' + ( v_lastIndex + 1 + i ) );
+                                               ( cur_item ).css( 'top', t._title_h + t._line_h * ( v_lastIndex + 1 + i ) ).attr( 'id', o.itemIDPrefix + ( v_lastIndex + 1 + i ) );
 
                                        } else {
                                                break;
                                }
 
                                for ( i = 0; i < num; i++ ) {
-                                       cur_item = $( '#li_' + ( v_lastIndex - i ) );
+                                       cur_item = $( '#' + o.itemIDPrefix + ( v_lastIndex - i ) );
 
                                        if ( cur_item ) {
                                                if ( v_firstIndex - 1 - i < 0 ) {
                                                htmlData.remove();
 
                                                /* Set New Position */
-                                               $( cur_item ).css( 'top', t._title_h + t._line_h * ( v_firstIndex - 1 - i ) ).attr( 'id', 'li_' + ( v_firstIndex - 1 - i ) );
+                                               $( cur_item ).css( 'top', t._title_h + t._line_h * ( v_firstIndex - 1 - i ) ).attr( 'id', o.itemIDPrefix + ( v_firstIndex - 1 - i ) );
 
                                        } else {
                                                break;
                                return orig + " ui-listview ui-virtual-list-container" + ( t.options.inset ? " ui-listview-inset ui-corner-all ui-shadow " : "" );
                        });
 
+                       o.itemIDPrefix = $el.attr( "id" ) + '_';
                        o.id = "#" + $el.attr( "id" );
 
                        $( o.id ).bind( "pagehide", function ( e ) {