fastadmin后台集成ace在线代码编辑器

ace包在这:https://download.csdn.net/download/weixin_39347356/74370374
官方Git:https://github.com/ajaxorg/ace/
放到对应页面对应js中的api bindevent中

 <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Content')}:</label>
        <div class="col-xs-12 col-sm-8" id="editor">
            <textarea id="content" class="form-control hidden" rows="5" name="row[content]" cols="50">{$row.content|htmlentities}</textarea>
        </div>
        <textarea id="c-content" class="form-control hidden" rows="5" name="row[content]" cols="50">{$row.content|htmlentities}</textarea>
    </div>
require(['ace/ace','ace/theme/monokai','ace/ext/language_tools','ace/mode/javascript',
                    'ace/mode/css','ace/mode/html','ace/mode/php','ace/mode/text'
], function (ace) {
     var type=$('#type').val();
     var editor = ace.edit("editor");
     editor.setTheme("ace/theme/monokai");
     if(type=='css'){
         editor.getSession().setMode("ace/mode/css");
     }else
     if(type=='js'){
         editor.getSession().setMode("ace/mode/javascript");
     }else {
     //if(type=='html'){
         editor.getSession().setMode("ace/mode/html");
         editor.getSession().setMode("ace/mode/php");
     }
     editor.setFontSize(14); //字体大小
     document.getElementById("editor").style.lineHeight="18px";//设置行高;
     editor.setOption("wrap", "free");//自动换行
     editor.setOptions({
         enableBasicAutocompletion: true,
         enableSnippets: true,
         enableLiveAutocompletion: true
     });
     editor.setShowPrintMargin(false);
     editor.getSession().setUseWorker(false);
     editor.getSession().setUseWrapMode(true); //支持代码折叠

     editor.getSession().on('change', function(){
         // 设置textarea的值
         $('#c-content').val(editor.getSession().getValue());
     });

     $('#bark').click(function(){
         //设置编辑器内容
         //editor.setValue($('#previous').val())
         editor.getSession().setValue($('#previous').val())
     })
 });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值