国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

轉:ueditor使用小結

2024-04-27 15:14:21
字體:
來源:轉載
供稿:網友
轉自:http://www.cnblogs.com/janes/p/5072496.htmlueditor使用小結

一、簡介

ueditor是百度編輯器,官網地址:http://ueditor.baidu.com/website/

完整的功能演示,可以參考:http://ueditor.baidu.com/website/onlinedemo.html

為了方便開發學習,我們下載它的完整版和.net版。

ueditor_release_ueditor1_4_3_1-src.zip

ueditor_release_ueditor1_4_3_1-gbk-net.zip

 

二、如何引入ueditor編輯器

下載包的index.html是編輯器示例,主要幾處代碼如下:

<head>

   ……

<!--編輯器基本配置-->

<script type="text/javascript" charset="gbk" src="ueditor.config.js"></ script>

<!--編輯器完整代碼-->

<script type="text/Javascript" charset="gbk" src="ueditor.all.js"> </script >

  ……

</head>

<body>

<div>

<script id="editor" type="text/plain"></ script>

</div>

<script type="text/javascript">

//實例化編輯器

var ue = UE.getEditor( 'editor', {

        autoHeightEnabled: true,

        autoFloatEnabled: true,

        initialFrameWidth: 690,

        initialFrameHeight:483

    });

</script>

 

三、如何調整ueditor工具欄

ueditor功能強大,但是有些功能我們是用不到的,可以在ueditor.config.js中配置。搜索"toolbars"找到工具欄配置項,刪掉不必要的功能就可以了。

,toolbars: [[

'undo', 'redo' , '|',

'bold', 'forecolor' , 'removeformat', 'autotypeset', 'pasteplain' , '|', '|',

'justifyleft', 'justifycenter' , '|',

'link', 'unlink' ,  '|',

'insertimage', 'insertvideo' , '|',

'Wordimage', '|' ,

'inserttable', 'insertrow' , 'deleterow', 'insertcol', 'deletecol' , 'mergecells', 'splittocells', '|' , 'mybtn1','mydialog1'

        ]]

 

四、如何修改ueditor默認樣式

如果想修改編輯器默認的字體等,可以找打開ueditor.all.js,搜索editor.js中的"render:"方法,修改以下部分:

var html = ( ie && browser.version < 9  ? '' : '<!DOCTYPE html>') +

                    '<html xmlns=/'http://www.w3.org/1999/xhtml/' class=/'view/' ><head>' +

                    '<style type=/'text/CSS/'>' +

                    //設置四周的留邊

                    '.view{padding:0;word-wrap:break-word;cursor:text;height:90%;}/n' +

                    //設置默認字體和字號

                    //font-family不能呢隨便改,在safari下fillchar會有解析問題

                    'body{margin:8px;font-family:sans-serif;font-size:16px;}' +

                    //設置段落間距

                    'p{margin:5px 0;}</style>' +

                    ( options.iframeCssUrl ? '<link rel=/'stylesheet/' type=/'text/css/' href=/'' + utils.unhtml(options.iframeCssUrl) + '/'/>' : '' ) +

                    (options.initialStyle ? '<style>' + options.initialStyle + '</style>' : '') +

                    '</head><body class=/'view/' ></body>' +

                    '<script type=/'text/javascript/' ' + (ie ? 'defer=/'defer/'' : '' ) +' id=/'_initialScript/'>' +

                    'setTimeout(function(){editor = window.parent.UE.instants[/'ueditorInstant' + me.uid + '/'];editor._setup(document);},0);' +

                    'var _tmpScript = document.getElementById(/'_initialScript/');_tmpScript.parentNode.removeChild(_tmpScript);</script></html>';

 

五、ueditor上傳圖片插入正文后如何默認居中

修改/dialogs/image/image.js文件的initAlign()和setAlign方法。

Image(9)

六、ueditor如何自定義工具欄按鈕

如果現有的功能不能滿足需求,我們想在工具欄上新增一個自定義按鈕,該如何實現呢?

1.首先修改ueditor.config.js,為toolbars添加'mybtn1';

,toolbars: [[

'undo', 'redo' , '|',

'bold', 'forecolor' , 'removeformat', 'autotypeset', 'pasteplain' , '|', '|',

'justifyleft', 'justifycenter' , '|',

'link', 'unlink' ,  '|',

'insertimage', 'insertvideo' , '|',

'wordimage', '|' ,

'inserttable', 'insertrow' , 'deleterow', 'insertcol', 'deletecol' , 'mergecells', 'splittocells', '|' ,'mybtn1'

        ]]

2.然后修改ueditor.all.js,找到變量btnCmds,添加'mybtn1';

var btnCmds = ['undo' , 'redo', 'formatmatch',

'bold', 'italic' , 'underline', 'fontborder', 'touppercase' , 'tolowercase',

'strikethrough', 'subscript' , 'superscript', 'source', 'indent' , 'outdent',

'blockquote', 'pasteplain' , 'pagebreak',

'selectall', '

'insertparagraphbeforetable', 'insertrow' , 'insertcol', 'mergeright', 'mergedown' , 'deleterow',

'deletecol', 'splittorows' , 'splittocols', 'splittocells', 'mergecells' , 'deletetable', 'drafts','mybtn1' ];

3.最后在ueditor.all.js,新增mybtn1命令執行的代碼:

UE.commands['mybtn1'] = {

    execCommand: function (cmdName, align) {

var range = this .selection.getRange();

this.execCommand('inserthtml' , '<p>click mybtn1</p>');

return true ;

    }

};

這樣就完成了對工具欄功能的擴展。 

image

七 ueditor如何自動抓取遠程圖片

如果想實現粘貼網頁時,直接將其中的圖片上傳到自己的圖片服務器,該怎么做呢?這其中主要用到的js是plugins/catchremoteimage.js。

首先設置編輯器選項:catchRemoteImageEnable:true。這樣便開啟了自動抓取圖片的功能。

如果想自定義圖片上傳方式,而不用ueditor默認的圖片上傳地址,那么需要修改catchremoteimage.js這里:

image

 

  把這里的url改成自定義的ashx文件地址即可。 

八  ueditor上傳圖片窗口,如何實現選擇圖片后自動上傳

上傳圖片窗口操作需要先選擇圖片,點擊“開始上傳”,然后插入圖片。操作過程略顯繁瑣,其實可以去掉“開始上傳”,在選中圖片后自動上傳。

首先找到dialogs/image/image.html,隱藏image.html的“開始上傳”按鈕。

image

然后修改dialogs/image/image.js文件,找到addFile方法,然后在方法結尾添加以下代碼:

 

function addFile(file) {

……                //自動上傳                clickUpload = function () {                    $upload.click();                }                setTimeout("clickUpload()", 200);            }

 

image

作者:小靜(Cathy) 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 京山县| 宜阳县| 潞城市| 历史| 安丘市| 岫岩| 临夏县| 德庆县| 扶绥县| 中方县| 岳阳市| 拜泉县| 铜梁县| 西和县| 任丘市| 故城县| 农安县| 阿合奇县| 嵊泗县| 惠来县| 连云港市| 习水县| 肃南| 铜鼓县| 南溪县| 新巴尔虎左旗| 胶南市| 泾川县| 灵宝市| 大理市| 垣曲县| 横山县| 图们市| 仁寿县| 临桂县| 虹口区| 册亨县| 汪清县| 昆山市| 沭阳县| 侯马市|