From 9fbf14da4df36dc51b92c3f945709a7dc7c32ce5 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 1 Apr 2014 11:49:59 -0400 Subject: [PATCH] fix(view) image was loaded twice --- html/view/image.html | 2 +- lib/client/view.js | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/html/view/image.html b/html/view/image.html index 12bbd746..5bf60ab8 100644 --- a/html/view/image.html +++ b/html/view/image.html @@ -1 +1 @@ -{{ name }} \ No newline at end of file +{{ name }} \ No newline at end of file diff --git a/lib/client/view.js b/lib/client/view.js index abf2cf89..6812086c 100644 --- a/lib/client/view.js +++ b/lib/client/view.js @@ -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;