* refresh(index): refresh the widget, should be called after add or remove. (parameter: start index)
* empty: remove all of images from the gallery
* length: get length of images
- * value: get current index of gallery
+ * value(index): get or set current index of gallery (parameter: index of image)
*
* Events
*
*/
/**
@method value
- The value method is used to get current index of gallery.
+ The value method is used to get or set current index of gallery. The image_index attribute defines the index of the image to be set. If not get current index.
<div id="gallery" data-role="gallery" data-vertical-align="middle"></div>
value = $("#gallery").gallery('value');
+ $("#gallery").gallery('value', [image_index]);
*/
(function ( $, window, undefined ) {
$.widget( "tizen.gallery", $.mobile.widget, {
align_type: null,
direction: 1,
container: null,
- loader: [],
_resize: function ( index ) {
var img = this.images[index],
processing = function () {
self._resize( index );
self._align( index, obj );
+ },
+ loading = function () {
+ if ( self.images[index] === undefined ) {
+ return;
+ }
+
+ if ( !self.images[index].height() ) {
+ setTimeout( loading, 10 );
+ return;
+ }
+
+ processing();
};
if ( !obj ) {
if ( index < 0 ) {
return;
}
+ if ( !this.images.length ) {
+ return;
+ }
if ( index >= this.images.length ) {
return;
}
obj.css( "display", "block" );
obj.append( this.images[index] );
- if ( this.images[index].height() ) {
- processing();
- } else {
- this.loader[index] = setInterval( function () {
- if ( !self.images[index].height() ) {
- return;
- }
-
- processing();
- clearInterval( self.loader[index] );
- }, 10);
- }
+ loading();
},
_detach: function ( index, obj ) {
obj.css( "display", "none" );
this.images[index].removeAttr("style");
this.images[index].detach();
-
- clearInterval( this.loader[index] );
},
_detach_all: function () {
},
show: function () {
+ if ( !this.images.length ) {
+ return;
+ }
+
this._show();
this._add_event();
},
return this.images.length;
},
- value: function () {
- return this.index;
+ value: function ( index ) {
+ if ( index === undefined ) {
+ return this.index;
+ }
+
+ this.refresh( index );
}
}); /* End of widget */
// auto self-init widgets
- $( document ).bind( "pagecreate", function ( e ) {
+ $( document ).bind( "pagecreate create", function ( e ) {
$( e.target ).find( ":jqmData(role='gallery')" ).gallery();
});
- $( document ).bind( "pagebeforeshow", function ( e ) {
+ $( document ).bind( "pageshow", function ( e ) {
$( e.target ).find( ":jqmData(role='gallery')" ).gallery( 'show' );
});