2012-05-10 98 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個更少的圖像我只是刪除刪除按鈕的處理程序。