如何集成TinyMCE按钮和传递变量

How to integrate TinyMCE button and pass through variables

本文关键字:按钮 变量 TinyMCE 何集成 集成      更新时间:2023-09-26

我需要将TinyMCE和图像上传按钮对话框与我自己的webapp集成-但我需要将图像上传到我的PHP代码中,并使用一些自定义变量。我的PHP调用tinyMCE。使用以下激活码进行初始化:

原始PHP代码(触发编辑器)…

<?php
$js='
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    plugins : "spellchecker,advhr,table,addimg", 
    theme_advanced_buttons1 :     "cut,copy,paste,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,formatselect,zoom, blockquote,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,addimg,|,code,preview,|,forecolor,backcolor",
    theme_advanced_buttons2 : "tablecontrols,|,spellchecker,advhr,removeformat,|,sub,sup,|,charmap,visualaid",
    theme_advanced_buttons3 : "",      
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    content_css : "'.config::siteurl.'/css/myStyle.css"
});

…这将通过一个自定义按钮"添加"激活编辑器;当我点击添加自定义按钮,它触发自定义dialog.htm预期;但我需要的是这个对话框。htm包含我的变量,这样当表单发布时,接收PHP可以使用它们

dialog.htm形式……

.
.
.
<form id='file_upload_form' name='file_upload_form' enctype='multipart/form-data'     action='myUploader.php' method='POST'>
    <input type='text' name='MySpecialId’ value='xxxx'>
     <table width=100%>
     <tr valign=top>
     <td width=100>Please choose a file: </td>
     <td align=left>
         <input style='width: 100%;'  id='myFile' name='myFile' type='file'>
     </td>
     </tr>
 </table>
</form>
.
.

问题是我如何从原始的PHP调用者到dialog.htm中获得一个值,以便在上面的表单中设置MySpecialId值?我想我可以使用Javascript从dialog.js addmgdialog .init() js方法来设置表单,但我怎么能让TinyMCE工具栏通过一个值从调用PHP到自定义按钮dialog.js?

var AddImgDialog = {
    init : function() {
    alert( 'My passed through value is xxxxx' );
},
.
.

提示吗?谢谢TD

您可以在tinyMCE.init()中设置您的变量,例如:

tinyMCE.init({
    mode : "textareas",
    /*more settings*/
    myVariable:12345
});

这个变量可以在dialog.htm中通过tinyMCE.settings.myVariable
访问为了使输入更容易访问,给它一个ID,例如myInputID。现在您可以设置值(将以下指令放在输入后的某个位置)

document.getElementById('myInputID').value=tinyMCE.settings.myVariable;