This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9462fc
commit 2b551bb
Showing
11 changed files
with
646 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,49 @@ | ||
import { Component, ViewChild, ViewEncapsulation } from '@angular/core'; | ||
import { FormGroup, AbstractControl, FormBuilder, Validators } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'quill-example-01', | ||
template: `<quill-editor [(ngModel)]="editorContent" | ||
[config]="editorConfig" | ||
(ready)="onEditorCreated($event)"> | ||
(change)="onContentChanged($event)"> | ||
</quill-editor> | ||
<br> | ||
<div class="ql-editor" [innerHTML]="editorContent"></div>` | ||
styles: [`.form-control .quill-editor{overflow: visible;} .form-group { border: 1px solid #ccc; position: relative; } .has-error { border-color: red; } .has-success { border-color: green; }`], | ||
template: `<form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="form"> | ||
<div class="form-group" [ngClass]="{'has-error': (!content.valid && content.touched), 'has-success': (content.valid && content.touched)}"> | ||
<quill-editor class="form-control" [formControl]="content" [options]="editorConfig"></quill-editor> | ||
</div> | ||
</form>`, | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class QuillEditorComponentExample01 { | ||
|
||
public editorContent = `<p>I am Example 01</p>`; | ||
public form:FormGroup; | ||
public content:AbstractControl; | ||
|
||
public editorConfig = { | ||
placeholder: "输入公告内容,支持html" | ||
theme: 'bubble', | ||
placeholder: "输入任何内容,支持html", | ||
modules: { | ||
toolbar: [ | ||
['bold', 'italic', 'underline', 'strike'], | ||
[{ 'list': 'ordered'}, { 'list': 'bullet' }], | ||
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], | ||
[{ 'color': [] }, { 'background': [] }], | ||
[{ 'font': [] }], | ||
[{ 'align': [] }], | ||
['link', 'image'], | ||
['clean'] | ||
] | ||
} | ||
}; | ||
|
||
constructor() {} | ||
|
||
onEditorCreated(quill) { | ||
console.log('this is quill object', quill); | ||
} | ||
constructor(private _fb:FormBuilder) { | ||
this.form = _fb.group({ | ||
'content': ['<p>I am Example 01</p>', Validators.compose([Validators.required])], | ||
}); | ||
|
||
onContentChanged({ quill, html, text }) { | ||
console.log(quill, html, text); | ||
} | ||
this.content = this.form.controls['content']; | ||
}; | ||
|
||
ngOnInit() { | ||
setTimeout(() => { | ||
this.editorContent = '<h1>i am changed!</h1>' | ||
}, 1800) | ||
public submitAnnouncement(values:Object):void { | ||
if (this.form.valid) { | ||
console.log('Submit!', values); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,65 @@ | ||
import { Component, ViewChild, ViewEncapsulation } from '@angular/core'; | ||
import { FormGroup, AbstractControl, FormBuilder, Validators } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'quill-example-02', | ||
styles: [`.form-group { border: 1px solid #ccc; } .has-error { border-color: red; } .has-success { border-color: green; }`], | ||
template: `<form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="form"> | ||
<div class="form-group" [ngClass]="{'has-error': (!content.valid && content.touched), 'has-success': (content.valid && content.touched)}"> | ||
<quill-editor class="form-control" [formControl]="content" [config]="editorConfig"></quill-editor> | ||
</div> | ||
</form>` | ||
template: `<quill-editor [(ngModel)]="editorContent" | ||
[options]="editorConfig" | ||
(blur)="onEditorBlured($event)" | ||
(focus)="onEditorFocused($event)" | ||
(ready)="onEditorCreated($event)" | ||
(change)="onContentChanged($event)"> | ||
</quill-editor> | ||
<div class="ql-editor preview" [innerHTML]="editorContent"></div>`, | ||
styles: [ | ||
` | ||
.quill-editor { | ||
min-height: 16em; | ||
max-height: 20em; | ||
overflow-y: auto; | ||
} | ||
.preview { | ||
min-height: 10em; | ||
max-height: 16em; | ||
overflow-y: auto; | ||
border: 1px solid #eee; | ||
border-top: none; | ||
} | ||
` | ||
], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class QuillEditorComponentExample02 { | ||
|
||
public form:FormGroup; | ||
public content:AbstractControl; | ||
|
||
public editor; | ||
public editorContent = `<h3>I am Example 02</h3>`; | ||
public editorConfig = { | ||
theme: 'bubble', | ||
placeholder: "输入任何内容,支持html", | ||
modules: { | ||
toolbar: [ | ||
['bold', 'italic', 'underline', 'strike'], | ||
[{ 'list': 'ordered'}, { 'list': 'bullet' }], | ||
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], | ||
[{ 'color': [] }, { 'background': [] }], | ||
[{ 'font': [] }], | ||
[{ 'align': [] }], | ||
['link', 'image'], | ||
['clean'] | ||
] | ||
} | ||
placeholder: "输入公告内容,支持html" | ||
}; | ||
|
||
constructor(private _fb:FormBuilder) { | ||
this.form = _fb.group({ | ||
'content': ['<p>I am Example 02</p>', Validators.compose([Validators.required])], | ||
}); | ||
constructor() {} | ||
|
||
this.content = this.form.controls['content']; | ||
}; | ||
onEditorBlured(quill) { | ||
console.log('editor blur!', quill); | ||
} | ||
|
||
onEditorFocused(quill) { | ||
console.log('editor focus!', quill); | ||
} | ||
|
||
onEditorCreated(quill) { | ||
this.editor = quill; | ||
console.log('quill is ready! this is current quill instance object', quill); | ||
} | ||
|
||
onContentChanged({ quill, html, text }) { | ||
console.log('quill content is changed!', quill, html, text); | ||
} | ||
|
||
public submitAnnouncement(values:Object):void { | ||
if (this.form.valid) { | ||
console.log('Submit!', values); | ||
} | ||
ngOnInit() { | ||
setTimeout(() => { | ||
this.editorContent = '<h1>Example 02 changed!</h1>'; | ||
console.log('you can use the quill instance object to do something', this.editor); | ||
// this.editor.disable(); | ||
}, 2800) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Component, ViewChild, ViewEncapsulation } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'quill-example-03', | ||
template: ` | ||
<div id="toolbar"> | ||
<!-- Add a bold button --> | ||
<button class="ql-bold">Bold</button> | ||
<button class="ql-italic">Italic</button> | ||
<!-- Add font size dropdown --> | ||
<select class="ql-size"> | ||
<option value="small"></option> | ||
<!-- Note a missing, thus falsy value, is used to reset to default --> | ||
<option selected></option> | ||
<option value="large"></option> | ||
<option value="huge"></option> | ||
</select> | ||
<!-- Add subscript and superscript buttons --> | ||
<button class="ql-script" value="sub"></button> | ||
<button class="ql-script" value="super"></button> | ||
<button style="width: 120px" (click)="customButtonClick()">custom button</button> | ||
</div> | ||
<quill-editor [(ngModel)]="editorContent" | ||
[options]="editorConfig" | ||
(blur)="onEditorBlured($event)" | ||
(focus)="onEditorFocused($event)" | ||
(ready)="onEditorCreated($event)" | ||
(change)="onContentChanged($event)"> | ||
</quill-editor>`, | ||
styles: [ | ||
` | ||
.quill-editor { | ||
min-height: 16em; | ||
max-height: 20em; | ||
overflow-y: auto; | ||
} | ||
` | ||
], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class QuillEditorComponentExample03 { | ||
|
||
public editor; | ||
public editorContent = `<h3>I am Example 03</h3>`; | ||
public editorConfig = { | ||
placeholder: "输入公告内容,支持html", | ||
modules: { | ||
toolbar: '#toolbar' | ||
} | ||
}; | ||
|
||
constructor() {} | ||
|
||
onEditorBlured(quill) { | ||
// console.log('editor blur!', quill); | ||
} | ||
|
||
onEditorFocused(quill) { | ||
// console.log('editor focus!', quill); | ||
} | ||
|
||
onEditorCreated(quill) { | ||
this.editor = quill; | ||
// console.log('quill is ready! this is current quill instance object', quill); | ||
} | ||
|
||
onContentChanged({ quill, html, text }) { | ||
// console.log('quill content is changed!', quill, html, text); | ||
} | ||
|
||
customButtonClick() { | ||
alert(`You can custom the button and listen click event to do something...\n你可以定义一些自定义按钮做你想做的事,如上传图片至第三方存储...等等`) | ||
} | ||
|
||
ngOnInit() { | ||
} | ||
} |
Oops, something went wrong.