Jxstar集成百度富媒體編輯器UEditor

因?yàn)轫?xiàng)目需要,需要在Jxstar中集成百度富媒體編輯器,主要是需要使用百度地圖,嘗試了很多種方案,終于能夠優(yōu)雅的集成UEditor了,但是在集成過(guò)程中,在JxExt.js添加了代碼,不是很好,在開發(fā)過(guò)程中盡量不要修改平臺(tái)源碼,直接放圖片

百度富媒體編輯器.png

集成百度富媒體編輯器說(shuō)明

  1. 導(dǎo)入百度富媒體編輯器文件,放到lib目錄下面ueditor1.4.3.3,并且把jsp頁(yè)面下的jar包添加到WEB-INFO/lib下面,其中有兩個(gè)jar版本比JxStar版本高,我使用了新版本的jar
  2. 在index_top.jsp 文件底部引入
    <script type="text/javascript" src="lib/ueditor1.4.3.3/ueditor.config.js"></script>
    <script type="text/javascript" src="lib/ueditor1.4.3.3/ueditor.all.js"></script>
  1. 在JxExt.js添加如下代碼
Ueditor = Ext.extend(Ext.form.Field ,{
    id : 'editor',
    defaultAutoCreate : {tag: 'div'},
    constructor : function(cfg){
        Ext.apply(this,cfg);
        this.listeners = {
            render : function(cmp) {
                //注意此處zIndex的值為8999 目的是防止百度富媒體編輯器覆蓋Extjs的彈出框
                var ueditor = new UE.ui.Editor({zIndex:8999,initialFrameWidth:"100%",initialFrameHeight : 500,});
                this.ueditor = ueditor;
                ueditor.render(cmp.id);
                if(this.originalValue){
                    var v = this.originalValue;
                    ueditor.ready(function(){
                        ueditor.setHeight(500);
                        ueditor.setContent(v);
                    });
                }
                //監(jiān)聽(tīng)百度富媒體編輯器內(nèi)容改變事件
                ueditor.addListener("contentChange",function(){
                    ueditor.setHeight(500);
                });
            },
            scope : this,
        };

        Ueditor.superclass.constructor.call(this);
    },
    /**
     * 重寫setValue方法 主要為修改設(shè)置值
     * */
    setValue : function(value){
        var self = this;
        if(!self.ueditor){
            self.originalValue = value;
        }else{
            self.ueditor.ready(function(){
                self.ueditor.setHeight(500);
                self.ueditor.setContent(value);
            });
        }
    },
    getValue : function(){
        var self = this;
        var ueditorValue = "";
        if(!self.ueditor){
            ueditorValue =  self.originalValue ;
        }else{
            self.ueditor.ready(function(){
                self.ueditor.setHeight(500);
                ueditorValue = self.ueditor.getContent();
            });
        }
        return ueditorValue;
    }



});
Ext.reg('ueditor', Ueditor);
  1. 使用方法:在Inc文件中直接修改控件的類型即可
var isret = false;
var findcfg = function(datas) {
    if (isret) return;
    for (var i = datas.length-1; i >= 0; i--) {
        if (datas[i].name == 'uoa_news__news_content') {
            var heitem = datas[i];
            if (heitem) {
                delete heitem.width;
                heitem.xtype = 'ueditor';
                heitem.anchor = '100%';
                heitem.maxLength = 20000;
            }
            isret = true; return;
        } else {
            if (datas[i].items && datas[i].items.length > 0) {
                findcfg(datas[i].items);
            }
        }
    }
};
findcfg(items);

優(yōu)化百度富媒體編輯器皮膚說(shuō)明

  1. 在themes下導(dǎo)入wx皮膚包(大神定制好的,直接導(dǎo)入使用即可)
  2. 在ueditor.config.js 中設(shè)置 微信主題:theme: 'wx',themePath : URL + "themes/"

升級(jí)百度富媒體編輯器百度地圖,以及自動(dòng)獲取百度地圖IP地址并綁定到指定控件說(shuō)明

  1. 默認(rèn)富媒體編輯器百度地圖的版本為V1.1升級(jí)方式為:
<script type="text/javascript" src="http://api.map.baidu.com/api?ak=19pbPPDtgoBhWrOFmGmp7hq9BUCsOMvC&v=2.0&services=true"></script>
  1. 升級(jí)完成后有過(guò)期的API需要修改
    marker.setPoint(point)需要升級(jí)為marker.setPosition(point);
    marker.getPoint()需要升級(jí)為marker.getPosition();
    map.zoomLevel;需要升級(jí)為map.getZoom();
  2. 綁定百度地圖的坐標(biāo)到指定的控件需要在map.html上修改代碼:
      var mapCoordinate = point.lng + ',' + point.lat;
              if($G('is_dynamic').checked) {
                  var URL = editor.options.UEDITOR_HOME_URL,
                      url = [URL + (/\/$/.test(URL) ? '':'/') + "dialogs/map/show.html" +
                          '#center=' + center.lng + ',' + center.lat,
                          '&zoom=' + zoom,
                          '&width=' + mapWidth,
                          '&height=' + mapHeight,
                          '&markers=' + point.lng + ',' + point.lat,
                          '&markerStyles=' + 'l,A'].join('');
                  editor.execCommand('inserthtml', '<iframe mapcoordinate="'+mapCoordinate+'" class="ueditor_baidumap" src="' + url + '"' + (styleStr ? ' style="' + styleStr + '"' :'') + ' frameborder="0" width="' + (mapWidth+4) + '" height="' + (mapHeight+4) + '"></iframe>');
              } else {
                  var url = "http://api.map.baidu.com/staticimage?center=" + center.lng + ',' + center.lat +
                          "&zoom=" + zoom + "&width=" + size.width + '&height=' + size.height + "&markers=" + point.lng + ',' + point.lat;
                  editor.execCommand('inserthtml', '<img mapcoordinate="'+mapCoordinate+'" width="'+ size.width +'"height="'+ size.height +'" src="' + url + '"' + (styleStr ? ' style="' + styleStr + '"' :'') + '/>');
              }

在ueditor.all.js修改代碼即可:

     UE.commands['inserthtml'] = {
         execCommand: function (command,html,notNeedFilter){
             if(document.getElementsByName('uoa_news__map_coordinate').length > 0){
                 var objDiv = document.createElement("div");
                 objDiv.innerHTML =html;
                 if(objDiv.childNodes[0].getAttribute("mapcoordinate")){
                     document.getElementsByName('uoa_news__map_coordinate')[0].value = objDiv.childNodes[0].getAttribute("mapcoordinate");
                 }
             }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1、通過(guò)CocoaPods安裝項(xiàng)目名稱項(xiàng)目信息 AFNetworking網(wǎng)絡(luò)請(qǐng)求組件 FMDB本地?cái)?shù)據(jù)庫(kù)組件 SD...
    陽(yáng)明AI閱讀 16,203評(píng)論 3 119
  • 背景 最近需要為書本添加詳細(xì)描述, 采用在管理后臺(tái)通過(guò)富文本編輯器上傳商品的詳情描述。 在目前看來(lái), 只需要支持格...
    fall4u閱讀 9,020評(píng)論 2 3
  • 背景 最近工作需要重新搭建公司網(wǎng)站,其中需要使用富文本編輯器,貨比三家,最后選擇了百度團(tuán)隊(duì)的UEditor。項(xiàng)目框...
    菜鳥要逆襲閱讀 18,354評(píng)論 4 14
  • 黎明每天翻新著日子的土地, 種什么、收什么由我們自己。 鋤頭生銹高掛 , 日子被冷落荒廢。 走進(jìn)收獲的秋季, 看別...
    蕙蘭漱雪閱讀 279評(píng)論 0 10
  • 回家路上,突然一輛出租車竄到前方停了下來(lái),對(duì)路邊的小伙子喊到,“去哪里?”那小伙子說(shuō)“山大路9號(hào)”,出租車一臉愕然...
    王青山閱讀 158評(píng)論 0 0

友情鏈接更多精彩內(nèi)容