2017-07-29 127 views
0

我想一个新的自定义按钮添加到summernote部件与YII2使用包装:yii2 summernote小工具添加新的按钮,工具栏

use marqu3s\summernote\Summernote; 

这是我在summernote样品以下视图代码:

http://summernote.org/deep-dive/

  $form->field($model, 'text_body')->widget(Summernote::className(), [ 
      'clientOptions' => [ 
       'id' => 'ysk-summernote', 
       'toolbar' => [ 
        ['mybutton', ['hello']], 
        ['undo', ['undo']], 
        ['redo', ['redo']], 
        ['insert', ['link', 'hr']], 
        ['style', ['bold', 'italic', 'underline', 'clear']], 
        ['font', ['strikethrough', 'superscript', 'subscript']], 
        ['fontsize', ['fontsize']], 
        ['color', ['color']], 
        ['para', ['ul', 'ol', 'paragraph']], 
        ['height', ['height']], 
        ['view', ['codeview']], 
        ['help', ['help']], 
       ], 
       'height' => 400, 
       'buttons' => ['hello' => 'HelloButton'], 
       ] 
      ] 
     ); 
     ?>  

我也加入以下JS:

<?php 
$script = <<< JS 
var HelloButton = function (context) { 
    var ui = $.summernote.ui; 

    // create button 
    var button = ui.button({ 
    contents: '<i class="fa fa-child"/> Hello', 
    tooltip: 'hello', 
    click: function() { 
     // invoke insertText method with 'hello' on editor module. 
     context.invoke('editor.insertText', 'hello'); 
    } 
    }); 

    return button.render(); // return button as jquery object 
}   
JS; 
$this->registerJs($script); 
?> 

视图渲染与编辑器,但没有显示该按钮:

如果我检查的工具栏,我可以看到,虽然在div:

<div class="note-btn-group btn-group note-mybutton"></div> 

我尝试了几个小时,但没有运气,

任何想法表示欢迎

回答

相关问题