成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Angular5 整合富文本編輯器TinyMCE(漢化+上傳)

zeyu / 1166人閱讀

摘要:簡(jiǎn)介是一個(gè)輕量級(jí)的富文本編輯器,相對(duì)于更加精簡(jiǎn),但足以滿足絕大部分場(chǎng)景的需要。

1. TinyMCE簡(jiǎn)介
TinyMCE是一個(gè)輕量級(jí)的富文本編輯器,相對(duì)于CKEditor更加精簡(jiǎn),但足以滿足絕大部分場(chǎng)景的需要。
2. 安裝和配置TinyMCE

2.1 安裝TinyMCE

npm install --save tinymce

2.2 設(shè)置tinymce全局訪問(wèn)(.angular-cli.json)

 "scripts": [
     "../node_modules/[email protected]/tinymce.js",
     "../node_modules/[email protected]/themes/modern/theme.js",
     "../node_modules/[email protected]/plugins/link/plugin.js",
     "../node_modules/[email protected]/plugins/paste/plugin.js",
     "../node_modules/[email protected]/plugins/table/plugin.js"
 ],

2.3 定義全局變量

在項(xiàng)目中的typing.d.ts中聲明tinymce全局變量,不然會(huì)提示找不到tinymce
declare var tinymce: any;

2.4 拷貝皮膚文件到assets目錄下

Linux and MacOS
cp -r node_modules/tinymce/skins src/assets/skins

2.5 安裝中文支持

中文語(yǔ)言包可以從這個(gè)地址下載:https://www.tinymce.com/downl...

下載下來(lái)的壓縮文件中會(huì)有一個(gè)langs目錄,里面有zh_CN.js,把這個(gè)目錄拷貝到src/assets目錄下,然后在全局中添加引用(.angular-cli.json):
"scripts": [

   "../node_modules/[email protected]/tinymce.js",
   "../node_modules/[email protected]/themes/modern/theme.js",
   "../node_modules/[email protected]/plugins/link/plugin.js",
   "../node_modules/[email protected]/plugins/paste/plugin.js",
   "../node_modules/[email protected]/plugins/table/plugin.js",
   "../src/assets/langs/zh_CN.js"

],

3. 創(chuàng)建TinyMCE組件
ng g c myeditor
import {
    Component,
    AfterViewInit,
    EventEmitter,
    OnDestroy,
    Input,
    Output
} from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";

@Component({
    selector: "tiny-editor",
    templateUrl: "./tiny-editor.component.html",
    styleUrls: ["./tiny-editor.component.css"]
})
export class TinyEditorComponent implements AfterViewInit, OnDestroy {
    @Input() elementId: String;
    @Output() onEditorContentChange = new EventEmitter();

    editor;

    constructor() { }

    ngAfterViewInit() {
        let self = this;
        tinymce.init({
            selector: "#" + this.elementId,
            height: 600,
            plugins: ["link", "table", "image"],
            skin_url: "assets/skins/lightgray",
            setup: editor => {
                this.editor = editor;
                editor.on("keyup change", () => {
                    const content = editor.getContent();
                    this.onEditorContentChange.emit(content);
                });
            }
        });
    }

    ngOnDestroy() {
        tinymce.remove(this.editor);
    }

}
// tiny-editor.component.html
4. 使用自定義TinyMCE組件
5. 增加圖片上傳功能
import {
    Component,
    AfterViewInit,
    EventEmitter,
    OnDestroy,
    Input,
    Output
} from "@angular/core";
import { HttpClient, HttpHeaders } from "@angular/common/http";

@Component({
    selector: "tiny-editor",
    templateUrl: "./tiny-editor.component.html",
    styleUrls: ["./tiny-editor.component.css"]
})
export class TinyEditorComponent implements AfterViewInit, OnDestroy {
    @Input() elementId: String;
    @Output() onEditorContentChange = new EventEmitter();

    editor;

    constructor(private http: HttpClient) { }

    ngAfterViewInit() {
        let self = this;
        tinymce.init({
            selector: "#" + this.elementId,
            height: 600,
            plugins: ["link", "table", "image"],
            skin_url: "assets/skins/lightgray",
            setup: editor => {
                this.editor = editor;
                editor.on("keyup change", () => {
                    const content = editor.getContent();
                    this.onEditorContentChange.emit(content);
                });
            },
            // 圖片上傳功能
            images_upload_handler: function(blobInfo, success, failure) {
                var formData;
                formData = new FormData();
                console.log(blobInfo);
                formData.append("file", blobInfo.blob(), blobInfo.filename());
                console.log(formData);
                self.uploadFile("http://www.seenode.com/index/player/upload", formData).subscribe( response => {
                    let url = response["data"]["imagePath"];
                    success(url);
                });
            }
        });
    }

    // 上傳圖片
    private uploadFile(url: string, formData: any) {
        var self = this;
        var headers = new HttpHeaders();
        headers.set("Accept", "application/json");
        return self.http.post(url, formData, { headers: headers });
    }

    ngOnDestroy() {
        tinymce.remove(this.editor);
    }

}
6. 獲取和設(shè)置編輯器內(nèi)容
// 監(jiān)聽(tīng)onEditorKeyup事件
private keyupHandler(event) {
    console.log("編輯器的內(nèi)容:", event);
}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/92499.html

相關(guān)文章

  • 18.上傳文件限制和使用富文本輯器【完結(jié)篇】

    摘要:本文首先完善一下前文上傳頭像的部分,增加上傳文件的大小和格式限制,其次把發(fā)布問(wèn)答部分中,問(wèn)題的詳細(xì)描述部分從普通的修改為富文本編輯器,這樣可以在問(wèn)題描述中添加各種格式的信息,如代碼表格列表圖片等。 本文是后端開(kāi)發(fā)——Flask初體驗(yàn)專欄的最后一篇文章,整個(gè)Q&A demo的簡(jiǎn)單框架其實(shí)已經(jīng)建立起來(lái)了,現(xiàn)在就是再優(yōu)化、完善一些細(xì)節(jié)。本文首先完善一下前文上傳頭像的部分,增加上傳文件的大小和...

    xialong 評(píng)論0 收藏0
  • tinymce與prism代碼高亮實(shí)現(xiàn)及漢化的配置

    摘要:簡(jiǎn)單介紹是一個(gè)輕量級(jí)的基于瀏覽器的所見(jiàn)即所得編輯器,由寫(xiě)成。它對(duì)和都有著非常良好的支持。功能方強(qiáng)大,并且功能配置靈活簡(jiǎn)單。另一特點(diǎn)是加載速度非??斓?。所以我們使用作為代碼高亮插件。簡(jiǎn)單介紹:TinyMCE是一個(gè)輕量級(jí)的基于瀏覽器的所見(jiàn)即所得編輯器,由JavaScript寫(xiě)成。它對(duì)IE6+和Firefox1.5+都有著非常良好的支持。功能方強(qiáng)大,并且功能配置靈活簡(jiǎn)單。另一特點(diǎn)是加載速度非??斓?..

    番茄西紅柿 評(píng)論0 收藏0
  • django項(xiàng)目admin后臺(tái)tinymce文本編輯并自定義添加圖片本地上傳和富文本中的回顯

    摘要:選擇該頁(yè)面綁定的標(biāo)簽指定圖片上傳處理目錄注其中為了顯示為中文,標(biāo)明了中文,同時(shí)需要下載語(yǔ)言包放到對(duì)應(yīng)的文件夾下。 前言 我們常因?yàn)閐jango的自帶admin后臺(tái)功能而選擇該框架,但也因?yàn)槠渥詣?dòng)生成的特殊性而在做出特別的更改的時(shí)候束手束腳,鑒于項(xiàng)目已經(jīng)采用了django,而后臺(tái)要求能夠直接上傳富文本內(nèi)容直接用于網(wǎng)頁(yè)顯示,定制性高,后來(lái)翻了目前較為知名的幾款富文本編輯框,覺(jué)得還是tiny...

    HackerShell 評(píng)論0 收藏0
  • django項(xiàng)目admin后臺(tái)tinymce文本編輯并自定義添加圖片本地上傳和富文本中的回顯

    摘要:選擇該頁(yè)面綁定的標(biāo)簽指定圖片上傳處理目錄注其中為了顯示為中文,標(biāo)明了中文,同時(shí)需要下載語(yǔ)言包放到對(duì)應(yīng)的文件夾下。 前言 我們常因?yàn)閐jango的自帶admin后臺(tái)功能而選擇該框架,但也因?yàn)槠渥詣?dòng)生成的特殊性而在做出特別的更改的時(shí)候束手束腳,鑒于項(xiàng)目已經(jīng)采用了django,而后臺(tái)要求能夠直接上傳富文本內(nèi)容直接用于網(wǎng)頁(yè)顯示,定制性高,后來(lái)翻了目前較為知名的幾款富文本編輯框,覺(jué)得還是tiny...

    Honwhy 評(píng)論0 收藏0
  • django項(xiàng)目admin后臺(tái)tinymce文本編輯并自定義添加圖片本地上傳和富文本中的回顯

    摘要:選擇該頁(yè)面綁定的標(biāo)簽指定圖片上傳處理目錄注其中為了顯示為中文,標(biāo)明了中文,同時(shí)需要下載語(yǔ)言包放到對(duì)應(yīng)的文件夾下。 前言 我們常因?yàn)閐jango的自帶admin后臺(tái)功能而選擇該框架,但也因?yàn)槠渥詣?dòng)生成的特殊性而在做出特別的更改的時(shí)候束手束腳,鑒于項(xiàng)目已經(jīng)采用了django,而后臺(tái)要求能夠直接上傳富文本內(nèi)容直接用于網(wǎng)頁(yè)顯示,定制性高,后來(lái)翻了目前較為知名的幾款富文本編輯框,覺(jué)得還是tiny...

    k00baa 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<