fix(view) image was loaded twice

This commit is contained in:
coderaiser 2014-04-01 11:49:59 -04:00
parent 91a3c07e16
commit 9fbf14da4d
2 changed files with 25 additions and 4 deletions

View file

@ -1 +1 @@
<img src="{{ src }}" title="{{ name }}" alt="{{ name }}"></img>
<img src="{{ src }}" alt="{{ name }}"></img>

View file

@ -13,13 +13,14 @@ var CloudCmd, Util, DOM, CloudFunc, $;
Key = CloudCmd.Key,
Images = DOM.Images,
View = Util.exec.bind(Util),
Element, TemplateAudio,
Element, TemplateAudio, TemplateImage,
Config = {
beforeShow : function() {
Images.hideLoad();
Key.unsetBind();
},
beforeClose : Key.setBind,
fitToView : true,
loop : false,
openEffect : 'none',
closeEffect : 'none',
@ -28,7 +29,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
width : '100%',
minWidth : 0,
minHeight : 0,
padding : 0
padding : 0
};
View.show = show;
@ -84,7 +85,9 @@ var CloudCmd, Util, DOM, CloudFunc, $;
path = CloudFunc.FS + Info.path;
if (isImage(path))
$.fancybox({ href : path }, Config);
getImageElement(path, function(element) {
$.fancybox.open(element, Config);
});
else if (isMusic(path))
getMusicElement(path, function(element) {
$.fancybox.open(element, {
@ -125,6 +128,24 @@ var CloudCmd, Util, DOM, CloudFunc, $;
return isMatch;
}
function getImageElement(src, callback) {
CloudCmd.getTemplate(TemplateImage, 'view/image', function(template) {
var rendered, element;
if (!TemplateImage)
TemplateImage = template;
rendered = Util.render(TemplateImage, {
src: src,
name: Info.name
});
element = $(rendered);
Util.exec(callback, element);
});
}
function getMusicElement(src, callback) {
CloudCmd.getTemplate(TemplateAudio, 'view/audio', function(template) {
var rendered, element;