1 """
2 * Copyright 2008 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http:#www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 """
16
17 from pyjamas import DOM
18 from pyjamas.ui.Image import Image
19 from pyjamas.ui import Event
20
21 """*
22 * Static internal collection of ImageLoader instances.
23 * ImageLoader is not instantiable externally.
24 """
25 imageLoaders = []
26
27
28 """*
29 * Provides a mechanism for deferred execution of a callback
30 * method once all specified Images are loaded.
31 """
33
34
36
37 self.images = []
38 self.callBack = None
39 self.loadedImages = 0
40 self.totalImages = 0
41
42
43 """*
44 * Stores the ImageElement reference so that when all the images report
45 * an onload, we can return the array of all the ImageElements.
46 * @param img
47 """
49 self.totalImages += 1
50 self.images.append(img)
51
52
53 """*
54 * Invokes the onImagesLoaded method in the CallBack if all the
55 * images are loaded AND we have a CallBack specified.
56 *
57 * Called from the JSNI onload event handler.
58 """
64
65
66
67 """*
68 * Sets the callback object for the ImageLoader.
69 * Once this is set, we may invoke the callback once all images that
70 * need to be loaded report in from their onload event handlers.
71 *
72 * @param cb
73 """
76
77
79 self.loadedImages += 1
80
81
83 return (self.loadedImages == self.totalImages)
84
85
86 """*
87 * Returns a handle to an img object. Ties back to the ImageLoader instance
88 """
100
117
118
119
120 """*
121 * Takes in an array of url Strings corresponding to the images needed to
122 * be loaded. The onImagesLoaded() method in the specified CallBack
123 * object is invoked with an array of ImageElements corresponding to
124 * the original input array of url Strings once all the images report
125 * an onload event.
126 *
127 * @param urls Array of urls for the images that need to be loaded
128 * @param cb CallBack object
129 """
140