ImageLoader: Performance fix: apply lazy loading for canvas element
authorPrzemyslaw Ciezkowski <p.ciezkowski@samsung.com>
Wed, 10 Apr 2013 10:10:40 +0000 (12:10 +0200)
committerYoumin Ha <youmin.ha@samsung.com>
Tue, 16 Apr 2013 04:38:21 +0000 (13:38 +0900)
Change-Id: Ib4629db6ded91cff22e23d241420acfb5f5fc6a0

src/js/widgets/components/imageloader.js

index 44f0514..e45c99b 100644 (file)
@@ -33,8 +33,15 @@ define( [ ], function ( ) {
 */\r
 \r
 ( function ( $, window, document, undefined ) {\r
-       var _canvas = document.createElement( 'canvas' ),\r
+       var _canvas, _context;\r
+\r
+       function initCanvas() {\r
+               if (_context) {\r
+                       return;\r
+               }\r
+               _canvas = document.createElement( 'canvas' );\r
                _context = _canvas.getContext( '2d' );\r
+       }\r
 \r
        function fileSystemErrorMessage( e ) {\r
                var FileError = window.FileError,\r
@@ -93,6 +100,7 @@ define( [ ], function ( ) {
 \r
        function getThumbnail( img, thumbwidth, thumbheight, fit ) {\r
                var dimensions, url;\r
+               initCanvas();\r
                _canvas.width = thumbwidth;\r
                _canvas.height = thumbheight;\r
                dimensions = resize( img.width, img.height, thumbwidth, thumbheight, fit );\r