【问题标题】:Creating or converting a TinyMCE dropdown toolbar menu创建或转换 TinyMCE 下拉工具栏菜单
【发布时间】:2012-07-17 07:53:30
【问题描述】:

我一直在尝试在我的 TinyMCE jQuery 版本中实现这个插件:

http://www.tinymce.com/tryit/menu_button.php

这个例子中的插件是用 TinyMCE 加载的,但它不适用于 jQuery。

我想做的是将它创建为一个单独的 TinyMCE 插件,但我不确定如何实现。使用 TinyMCE 创建插件的教程都是关于对话框窗口的,但这不是我需要的,因为我只想有一个小 sn-ps 的下拉菜单,它将添加到光标所在的位置。

谁能给我举个例子,它展示了如何创建这样一个工具栏下拉菜单?我疯狂地浏览了谷歌,找不到任何类似的东西,而且我上面发布的示例在技术上不是插件,因为我需要使用 PHP 生成内容。

【问题讨论】:

    标签: php javascript plugins tinymce


    【解决方案1】:

    这项任务并不容易(也必须努力完成)。 您需要在自己的自定义插件之一中设置函数 createControl。 我将向您展示我自己的插件之一的一些代码,它应该为您指明正确的方向

        /**
         * Creates control instances based in the incomming name. This method is normally not
         * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
         * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
         * method can be used to create those.
         *
         * @param {String} n Name of the control to create.
         * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
         * @return {tinymce.ui.Control} New control instance or null if no control was created.
         */
        // Creates a custom listbox
        createControl: function(n, cm) {
    
            switch (n) {
                // you may define more than one listbox here!
                // make sure this string is in your buttonconfig
                case 'my_new_listbox':
    
                    var listboxIdPart = 'my_new_listbox';
    
                    // Listbox erzeugen
                    var ctrl = cm.createListBox(listboxIdPart, {
                    title : 'Title',
    
                        // v could be 'value1_here' or "value2_here", it isbest to use simple numers as values
                        //need to specify what shall happen depending on the value
                      onselect : function(v) {
    
                        if (v == 0){
                            return;
                        }
                        else {
                                                  // alert('value choosen:' + v)
                                                  // your actions here
                          return;
                          }                     
                      }
                    }); // closing bracket
    
                                        // Add entries to the dropdown
                    ctrl.add('entry1', 'value1_here');
                    ctrl.add('entry2', 'value2_here');
                    ctrl.add('entry3', 'value3_here');
    
                    // Return new listbox
                    return ctrl;
            }
            return null;
        },
    

    【讨论】:

    • @Thariama:+1。非常有帮助。谢谢。一个简短的编辑: cm.createListBox() 函数后缺少右括号。我已经编辑了答案。希望您得到更正。
    猜你喜欢
    • 2013-07-03
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多