Created
December 4, 2015 09:09
-
-
Save level420/e1d70de25889609c1f56 to your computer and use it in GitHub Desktop.
Preload image resources of type png and gif into qx.ui.basic.Image instances and add them to the application root offscreen at position -5000, -5000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************************************************************ | |
qooxdoo - the new era of web development | |
http://qooxdoo.org | |
Copyright: | |
2015 Visionet GmbH, http://www.visionet.de | |
License: | |
LGPL: http://www.gnu.org/licenses/lgpl.html | |
EPL: http://www.eclipse.org/org/documents/epl-v10.php | |
See the LICENSE file in the project's top-level directory for details. | |
Authors: | |
* Dietrich Streifert (level420) | |
************************************************************************ */ | |
/** | |
* Add a method to preload images | |
* | |
*/ | |
qx.Mixin.define("visionet.application.MPreloadImageResources", | |
{ | |
/* | |
***************************************************************************** | |
MEMBERS | |
***************************************************************************** | |
*/ | |
members : | |
{ | |
/** | |
* Preload image resources of type png and gif into qx.ui.basic.Image instances | |
* and add them to the application root offscreen at position -5000, -5000 | |
* | |
* @param pathfragment {String|null} only preload if pathfragment is contained (via indexOf) in the resource name | |
*/ | |
preloadImageResources : function(pathfragment) { | |
var resources = qx.$$resources; | |
if(!resources || typeof resources !== "object") { | |
this.warn("unable to preload images: resource hash qx.$$resources not initialized or not an object"); | |
return; | |
} | |
var root = qx.core.Init.getApplication().getRoot(); | |
if(!root) { | |
this.error("unable to preload images: qx.core.Init.getApplication().getRoot() not yet available!"); | |
return; | |
} | |
var loadedCombined = {}; | |
for (var resname in resources) { | |
if (resources.hasOwnProperty(resname)) { | |
if(pathfragment && resname.indexOf(pathfragment) == -1) { | |
continue; | |
} | |
var res = resources[resname]; | |
if(qx.lang.Type.isArray(res) && (res[2] == "png" || res[2] == "gif")) { | |
// simple images | |
if(res.length == 4) { | |
if (qx.core.Environment.get("qx.debug")) { | |
this.debug("preloading image: " + resname); | |
} | |
} | |
// combined images | |
else if(res.length == 7) { | |
var combinedresname = res[4]; | |
if(!combinedresname || loadedCombined[combinedresname]) { | |
// combined base image already loaded | |
continue; | |
} | |
loadedCombined[combinedresname] = true; | |
resname = combinedresname; | |
if (qx.core.Environment.get("qx.debug")) { | |
this.debug("preloading combined image: " + resname); | |
} | |
} | |
var image = new qx.ui.basic.Image(resname); | |
root.add(image, {top:-5000, left:-5000}); | |
} | |
} | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have another version of this mixin which uses the not yes implemented getIds method of qx.util.ResourceManager which hopefully gets soon merged from pull request qooxdoo/qooxdoo#163
Then we don't need the internal qx.$$resources anymore