2012-05-10 50 views
0

而PhotoSwipe一直都非常好,到目前为止,这些只是小问题,我似乎无法避开的PhoneGap - PhotoSwipe删除图片

我初始化PhotoSwipe如下

formPhoto.gallery = window.Code.PhotoSwipe.attach(images, options); 

和图库中,一用户可以选择是否删除通过

图像或没有一次删除按钮被按下,这是运行

formPhoto.gallery.cache.images.splice(e.target.currentIndex,1); 
delete formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id]; 


if(formPhoto.gallery.cache.images.length == 0) 
    formPhoto.gallery.hide(); 
else 
    formPhoto.gallery.carousel.show(0); 

现在这项工作大多好,除了2例。

  1. 如果您低于3张照片,它会打破幻灯片事件(在幻灯片的右侧) - 图像滑动到黑色屏幕上。如果您删除并且只剩下1张图像,您甚至无法正确查看图像,只会弹回黑屏。
  2. 如果再次添加图像回库,已删除的旧图像再次

显示它使用

images = []; 
for(var x in formPhoto.activeObj.value) 
    images.push({url: formPhoto.activeObj.value[x].file, id:x}); 

formPhoto.gallery = window.Code.PhotoSwipe.attach(images, options); 

如果你愿意,我可以尝试抢的记录重新开始这是怎么回事。我不知道如何解决这个问题,我环视了https://github.com/codecomputerlove/PhotoSwipe/issues和谷歌,但没有什么帮助。

我真正想要做的是刚刚从画廊(其仅在独占模式查看)

回答

0

确定删除图像,我最后写一个临时解决方案..它有点哈克,但我只是手动从旋转式

  jQuery(formPhoto.gallery.carousel.contentEl).find("[src*=\"" + formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id].file + "\"]").parent().remove(); 
      //we look for the image that contains the same filename as the one we're trying to delete. 
      //so we just remove that. 

      formPhoto.gallery.cache.images.splice(e.target.currentIndex,1); 

      delete formPhoto.activeObj.value[e.target.originalImages[e.target.currentIndex].id]; 
      e.target.originalImages.splice(e.target.currentIndex, 1); 


      formPhoto.activeObj.object.find("[type=amountadded]").html(formPhoto.activeObj.valueLength() + " photos"); 

      if(formPhoto.gallery.cache.images.length == 0) 
       formPhoto.gallery.hide(); 
      else { 
       //real hacky job. Atleast it looks like a real cool effect occured. 
       formPhoto.galleryInitiate(formPhoto.activeObj, e.target.originalImages); 
      } 

删除DOM还固定重现图像的问题,是因为新生成的文件有相同的文件名。平均时间在文件名称中添加了一个日期组件。

0

这是一个删除按钮

function ps_delete_image(btn) { 
    var inst = PhotoSwipe.instances[0]; 
    var curImg = $photoSwipe.getCurrentImage(); 
    inst.cache.images.splice(inst.currentIndex, 1); 
    inst.originalImages.splice(inst.currentIndex, 1); 
    if(inst.cache.images.length == 0) inst.hide(); 
    else { 
     if (inst.currentIndex == inst.cache.images.length) inst.carousel.show(inst.currentIndex - 1); 
     else inst.carousel.show(inst.currentIndex); 
    } 
    // remove delete button if 3 or less is left 
    if(inst.cache.images.length <= 3) { 
     $(btn).remove(); 
    } 
} 

为了解决问题,与3个更少的图像我只是删除删除按钮的处理程序。