2012-12-10 112 views
4

好吧,這是殺了我。我已經寫了一個WordPress插件,它爲TinyMCE編輯器添加了一個自定義按鈕,並且它的工作效果非常好,除了由按鈕觸發的選項彈出窗口與WP原生的類似彈出窗口不同之外...如何在WordPress中爲自定義TinyMCE按鈕指定href值?

具體來說,當您在WordPress中點擊TinyMCE工具欄上方的添加媒體按鈕時,添加媒體窗口會以一個不錯的thickbox模式打開。它還加載在iframe,因爲按鈕的HTML獲取輸出被包裹在一個錨定標記與URL href的值:

<a href="http://.../wp-admin/media-upload.php?post_id=916&amp;TB_iframe=1&amp;width=640&amp;height=354" class="thickbox add_media" id="content-add_media" title="Add Media" onclick="return false;"> 

但是,當我的按鈕的HTML獲取輸出,錨標記有「一個href值的javascript :;「:

<a role="button" id="content_companyinfo" href="javascript:;" class="mceButton mceButtonEnabled mce_companyinfo" onmousedown="return false;" onclick="return false;" aria-labelledby="content_companyinfo_voice" title="Insert company info fields" tabindex="-1"> 

這裏是我的TinyMCE的編輯器插件代碼:http://pastebin.com/kuQJRHJR

這裏是添加媒體按鈕的WP核心TinyMCE的編輯器插件:http://core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/plugins/media/editor_plugin_src.js

TinyMCE addButton函數不允許您設置href值,而只是一個鏈接到使用addCommand創建的自定義命令函數的cmd值。

我試着在addButton函數的設置中將類'thickbox'添加到我的按鈕中,但是在我的常規彈出窗口後面創建了thickbox模式的奇怪效果。

任何人都知道如何以正確的方式做到這一點?提前致謝!

回答

5
  1. 在你的插件的editor_plugin.js init功能添加這個功能:

    ed.onInit.add(function(ed, evt) { 
    // make that the interactions window will open in a thickbox by adding the button the right attributes 
         jQuery('#content_myInteractions').addClass('thickbox'); 
    }); 
    

    更改 「content_myInteractions」 你的按鈕的ID。

  2. 在您的按鈕的命令,使用tb_show()打開您在ThickBox想要的內容:我把我的ThickBox的內容從我進入到我的網頁蒙山jQuery的底部的DIV

    tb_show('myInteractions', '#TB_inline?height=300&width=400&inlineId=interactions_wrapper'); 
    

(內聯內容)。 您也可以使用iframe。 這可能有幫助thickbox.net

相關問題