2011-10-28 60 views
1

我正在一個具有表單提交ajax調用觸發ceebox的函數的drupal站點。代號爲Drupal PHP函數如下:爲什麼Ceebox觸發器複製iframe和鏈接?

$commands = array(); 
    $html = '<a title="" style="display:none;" href="/subscribe" class="ceebox" id="subscribe" rel="iframe width:500 height:350"></a>'; 
//attempt to remove already existing ceebox generated elements 
    $commands[] = ajax_command_replace('#subscribe',''); 
    $commands[] = ajax_command_replace('#cee_iframeContent', ''); 
    $commands[] = ajax_command_replace('#cee_title', ''); 
    $commands[] = ajax_command_append('body', $html); 
    $commands[] = ajax_command_invoke(NULL, 'subscribeOpen', array('subscribe')); 
    return array('#type' => 'ajax', '#commands'=>$commands); 

的Javascript Drupal的函數調用:

(function($) { 
     $.fn.subscribeOpen = function(data) { 

      $('#subscribe').ceebox().trigger('click'); 


     }; 



})(jQuery); 

這一切都按預期工作;即在iframe中調出包含/訂閱頁面內容的ceebox。當我單擊ceebox上的關閉鏈接或單擊背景關閉時,它會首次關閉。當我點擊訂閱鏈接來觸發drupal ajax和ceebox調用時,它會添加一個額外的關閉鏈接,額外的「Item 1 of 1」標題和一個額外的iFrame窗口。每當我點擊關閉,然後觸發添加infinitum函數,就會重複此操作。我試圖添加解除綁定('#ceebox')到#subscribe元素以及jQuery unique()方法的各種組合都無濟於事。任何人都可以闡明如何解除/刪除這些重複的ceeboxes?

回答

2

我通過瀏覽jquery.ceebox.js文件並發現intialise函數有一個live()方法運行它。

這將導致各種奇妙的問題,因爲它應該只被稱爲一次元素。觸發ceebox時,上面的代碼將調用現場()多次,因此,我建議您更換jquery.ceebox.js線374:

$(elem).live("click", function(e){ 

閱讀:

$(elem).bind("click", function(e){ 
+0

+1大努力。好答案。 – AlphaMale

+0

感謝您的工作,爲我節省了很多時間。 – Celos