【问题标题】:Aloha Editor: Add new style (aloha-button) in aloha-multisplit-expanded boxAloha Editor:在 aloha-multisplit-expanded 框中添加新样式(aloha-button)
【发布时间】:2012-06-14 12:21:41
【问题描述】:

如何在 aloha-multisplit-expanded 框中添加新的 aloha-button。 (我希望能够添加无限数量的样式。当然,不是通过管理员,而是硬编码)

【问题讨论】:

    标签: css drupal aloha-editor


    【解决方案1】:

    为 aloha 编辑器添加样式: 我将在这里展示如何添加名为“meg”的简单样式

    1. 为 sites\all\libraries\aloha\aloha\plugins\common\format\nls 文件中的按钮添加定义到“root”。 "button.meg.tooltip":"Meg 格式说明"
    2. 在sites\all\libraries\aloha\aloha\plugins\common\format\lib\format-plugin.js 添加到“config”数组中的“default button configuration”,类名,这样:

      配置:['strong'、'meg'、'em'......]

    3. 在“initButtons”函数中添加初始化样式按钮的实现: 在 switch(button) 下,为新样式添加“case”:

      注意:'span'标签用于实现带有中性标签的普通css类。

    4. 将“span.meg”类定义为特殊样式: 在您的 css 主文件(drupal 站点主题的 css)中添加“span.meg”类:

      span.meg {
      color: green; }
      
    5. 刷新您的网站以进行重建,并在浮动 aloha 中使用新样式

    示例代码

    // Additional special styles
    case 'charm-meg':
        that.multiSplitItems.push({
            'name' : button,
            'tooltip' : i18n.t('button.' + button + '.tooltip'),
            'iconClass' : 'aloha-button ' + i18n.t('aloha-button-' + button),
            'markup' : jQuery('<span class=' + button + '></span>'),
            'click' : function () {
                var
                    markup = jQuery('<span class=' + button + '></span>'),
                    rangeObject = Aloha.Selection.rangeObject,
                    foundMarkup,
                    selectedCells = jQuery('.aloha-cell-selected');
    
                // formating workaround for table plugin
                if ( selectedCells.length > 0 ) {
                    var cellMarkupCounter = 0;
                    selectedCells.each( function () {
                        var cellContent = jQuery(this).find('div'),
                            cellMarkup = cellContent.find(button);
    
                        if ( cellMarkup.length > 0 ) {
                            // unwrap all found markup text
                            // <td><b>text</b> foo <b>bar</b></td>
                            // and wrap the whole contents of the <td> into <b> tags
                            // <td><b>text foo bar</b></td>
                            cellMarkup.contents().unwrap();
                            cellMarkupCounter++;
                        }
                        cellContent.contents().wrap('<span class=' + button + '></span>');
                    });
    
                    // remove all markup if all cells have markup
                    if ( cellMarkupCounter == selectedCells.length ) {
                        selectedCells.find(button).contents().unwrap();
                    }
                    return false;
                }
                // formating workaround for table plugin
    
                // check whether the markup is found in the range (at the start of the range)
                foundMarkup = rangeObject.findMarkup(function() {
                    return this.nodeName.toLowerCase() == markup.get(0).nodeName.toLowerCase();
                }, Aloha.activeEditable.obj);
    
                if ( foundMarkup ) {
                    // remove the markup
                    if (rangeObject.isCollapsed()) {
                        // when the range is collapsed, we remove exactly the one DOM element
                        GENTICS.Utils.Dom.removeFromDOM(foundMarkup, rangeObject, true);
                    } else {
                        // the range is not collapsed, so we remove the markup from the range
                        GENTICS.Utils.Dom.removeMarkup(rangeObject, markup, Aloha.activeEditable.obj);
                    }
                } else {
                    // when the range is collapsed, extend it to a word
                    if (rangeObject.isCollapsed()) {
                        GENTICS.Utils.Dom.extendToWord(rangeObject);
                    }
    
                    // add the markup
                    GENTICS.Utils.Dom.addMarkup(rangeObject, markup);
                }
                // select the modified range
                rangeObject.select();
                return false;
            },
            'tooltip' : i18n.t('<span class=' + button + '></span>'),
            'toggle' : true
        });
        break;
    

    【讨论】:

    • 合并成一个答案并要求模组清理:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    相关资源
    最近更新 更多