js创建ue编辑器编辑后台

来源:互联网 发布:linux shell 创建文件 编辑:程序博客网 时间:2024/04/30 01:40
<head>
<meta charset="utf-8">
<title>关于我们</title>
<link rel="stylesheet" type="text/css"
    href="<%=path%>/static/commons/plugins/bootstrap-validator/css/bootstrapValidator.min.css">
<script type="text/javascript" charset="utf-8"
src="<%=path%>/static/commons/plugins/ueditor1_4_3_3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8"
src="<%=path%>/static/commons/plugins/ueditor1_4_3_3/ueditor.all.js"></script>

<script type="text/javascript" charset="utf-8"
src="<%=path%>/static/commons/plugins/ueditor1_4_3_3/lang/zh-cn/zh-cn.js"></script>

<script type="text/javascript"
    src="<%=path%>/static/commons/plugins/bootstrap-validator/js/bootstrapValidator.min.js"></script>
<script type="text/javascript"
    src="<%=path%>/static/commons/plugins/bootstrap-validator/js/zh_CN.js"></script>
    
<style type="text/css">


</style>


</head>


    <!-- 页面展示部分  -->
    <div style="margin: 0px 10px 5px 10px;">
     <form id="defaultForm" class="form-horizontal" >
<div class="form-group">
    <label class="col-sm-2 control-label" for="newsTitle">标题</label>
<div class="col-sm-9">
<input id="newsTitle" name="newsTitle" type="text"
class="form-control" />
    </div>
</div>
<div class="form-group">
    <div class="col-sm-12">
           <script id="newsContent" name="newsContent" type="text/plain" style="width:100%;height:500px;"></script>
        </div>
        </div>
    </form>
    <br>
    <button id="updateButton" type="button" class="btn btn-primary btn-lg" >修改</button>
    </div>
</div>


<!-- js代码  -->

<script type="text/javascript">    
$(function () {
//表单验证
    var initBootstrapValidator =  function () {
        $("#defaultForm").bootstrapValidator({
             message: 'This value is not valid',
             feedbackIcons: {/*输入框不同状态,显示图片的样式*/
               valid: 'glyphicon glyphicon-ok',
               invalid: 'glyphicon glyphicon-remove',
               validating: 'icon-loading'
             },
             fields: {
            newsTitle: {
                      validators: {
                          notEmpty: {
                              message: '请填写新闻标题'
                          },
                          stringLength: {
                              min: 1,
                              max: 15,
                              message: '长度在1~15字符'
                          }
                      }
                  }
             }
        });
   }
    initBootstrapValidator();


   //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例

    var ue = UE.getEditor('newsContent',{
    toolbars: [[
    'fullscreen', 'source', 
    '|', 'undo', 'redo', 
    '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', /* 'autotypeset',  */'blockquote', 'pasteplain',
             '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', 
             '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight', 
             '|', 'customstyle', 'paragraph', 'fontfamily', 'fontsize', 
             '|', 'directionalityltr', 'directionalityrtl', 'indent', 
             '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 
             '|', 'touppercase', 'tolowercase', 
             '|', 'link', 'unlink', 'anchor', 
             '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', 
             '|', 'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', /*'map', 'gmap', */'insertframe', 'insertcode', /*'webapp',*/ 'pagebreak', 'template', 'background', 
             '|', 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', 
             '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', 
             '|', 'print', 'preview', 'searchreplace', 'drafts', 'help'
    ]]
    });

var newsId = "";
   
    function showAboutUs() {
    $.ajax({
            type: 'POST',  
            url : "<%=path%>/queryDetails.do",  //跳转查询数据的方法
            data:{
                type : 3
            },
            dataType:'json',
            success:function(data){ 
                $("#newsTitle").val(data.title);
                newsId = data.id;
                ue.ready(function(){
                    ue.setContent(data.newsContent);//设置标题
                });
            },
            error:function(data){ 
                alert("error1");
            }
       });
    }

    showAboutUs();

//发布新的信息(修改)
function update(buttonName, path) {

var bootstrapValidator = $("#defaultForm").data('bootstrapValidator');
         bootstrapValidator.validate();


         
if(!bootstrapValidator.isValid()){

             var speed=200;//滑动的速度
             $('body,html').animate({ scrollTop: 0 }, speed);
             return;
         } 
var newsTitle = $("#newsTitle");
        var newsContent = UE.getEditor('newsContent').getContent();

        if(!newsContent) {
        $.messager.alert('提示','请填写发布内容!','error');
            return;  
        }
      
        $.ajax({
            type: 'POST',  
            url: '<%=path%>/updateone.do',
            data:[
            {"name" : "id", "value" : newsId},
            {"name" : "type", "value" : 3},
                {"name" : "title", "value" : newsTitle.val()},   
                {"name" : "newsContent", "value":newsContent}
            ],
            /* {
                id : newsId,
                title : newsTitle,
                newsContent : newsContent
            }, */
            dataType:'json',
            success:function(data){ 
            $.messager.alert('提示',data.message);
            },
            error:function(data){ 
                alert("error");
            }
       });
}

//更新
$("#updateButton").click(function (){
update();
}); 


});
    
</script>




原创粉丝点击