From: Minkyu Kang Date: Thu, 17 Jan 2013 07:58:17 +0000 (+0900) Subject: gallery: use timeout function instead of interval X-Git-Tag: accepted/tizen_2.1/20130425.023924~7^2~202 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d472753d222b6c05addd73edd7625aeb9f184afb;p=platform%2Fframework%2Fweb%2Fweb-ui-fw.git gallery: use timeout function instead of interval Because of interval function can possible calling infinitely, use timeout function instead. And add error checking codes. Change-Id: I265565a219fe2d1c3a5478411c63ae29a7e4648e --- diff --git a/src/widgets/gallery/js/jquery.mobile.tizen.gallery.js b/src/widgets/gallery/js/jquery.mobile.tizen.gallery.js index 1add076..1a930d6 100755 --- a/src/widgets/gallery/js/jquery.mobile.tizen.gallery.js +++ b/src/widgets/gallery/js/jquery.mobile.tizen.gallery.js @@ -155,7 +155,6 @@ align_type: null, direction: 1, container: null, - loader: [], _resize: function ( index ) { var img = this.images[index], @@ -208,6 +207,18 @@ 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 ) { @@ -219,6 +230,9 @@ if ( index < 0 ) { return; } + if ( !this.images.length ) { + return; + } if ( index >= this.images.length ) { return; } @@ -226,18 +240,7 @@ 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 ) { @@ -257,8 +260,6 @@ obj.css( "display", "none" ); this.images[index].removeAttr("style"); this.images[index].detach(); - - clearInterval( this.loader[index] ); }, _detach_all: function () { @@ -472,6 +473,10 @@ }, show: function () { + if ( !this.images.length ) { + return; + } + this._show(); this._add_event(); },