기능 요구사항
1. 글상자 영역의 배경과 윤곽선 색상을 변경할 수 있다.
2. 글상자 영역의 윤곽선 두께를 변경할 수 있다.
플러그인 파일
먼저 CKEditor4 설치 후 plugins 디렉토리안에 bgstyle폴더를 생성한다.
- ckeditor root/
- plugins/
- bgstyle/
- icons/
- bgstyle.png
- dialogs/
- bgstyle.js
- plugin.js
- icons/
- bgstyle/
- plugins/
플러그인 소스 코드
CKEDITOR.plugins.add('bgstyle', {
icons: 'bgstyle',
init: function( editor ) {
CKEDITOR.dialog.add('bgstyleDialog', this.path + 'dialogs/bgstyle.js')
editor.addCommand('bgstyle', new CKEDITOR.dialogCommand('bgstyleDialog'))
editor.ui.addButton('bgstyle', {
label: '배경 꾸미기',
command: 'bgstyle',
toolbar: 'insert,100'
})
}
})
대화상자 소스 코드
let bgLabelId, bdLabelId
CKEDITOR.dialog.add('bgstyleDialog', function( editor ) {
return {
title: '배경 속성',
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'vbox',
children: [
{
type: 'hbox',
children: [
{
type: 'text',
id: 'backgroundFillColor',
label: '배경 채움색상',
commandName: 'bgColortest',
'default': '#ffffff',
onLoad: function() {
let dialog = this
bgLabelId = dialog.domId
}
},
{
type: 'button',
id: 'bgColor',
label: '선택',
onClick: function() {
editor.execCommand('colordialog')
editor.getColorFromDialog(function( color ) {
if ( color ) {
document.querySelector(`#${bgLabelId} input`).value = color
}
})
},
onLoad: function() {
this.getElement().getParent().setStyle("vertical-align", "bottom")
}
},
]
},
{
type: 'hbox',
children: [
{
type: 'text',
id: 'backgroundBorderColor',
label: '윤곽선 색상',
'default': '#000000',
onLoad: function() {
let dialog = this
bdLabelId = dialog.domId
}
},
{
type: 'button',
id: 'bdColor',
label: '선택',
onClick: function() {
editor.execCommand('colordialog')
editor.getColorFromDialog(function( color ) {
if ( color ) {
document.querySelector(`#${bdLabelId} input`).value = color
}
})
},
onLoad: function() {
this.getElement().getParent().setStyle("vertical-align", "bottom")
}
}
]
},
{
type: 'text',
id: 'backgroundBorderWidth',
label: '두께',
'default': '1'
}
]
},
]
},undefined
],
onOk: function() {
let dialog = this
document.querySelector(`#${Object.getOwnPropertyNames(CKEDITOR.instances)[0]}`).style.background = dialog.getValueOf('tab-basic', 'backgroundFillColor')
document.querySelector(`#${Object.getOwnPropertyNames(CKEDITOR.instances)[0]}`).style.border = `${dialog.getValueOf('tab-basic','backgroundBorderWidth')}px solid ${dialog.getValueOf('tab-basic', 'backgroundBorderColor')}`
},
}
})
참고: https://ckeditor.com/docs/ckeditor4/latest/guide/plugin_sdk_sample_1.html
'웹개발 관련' 카테고리의 다른 글
CKEditor4를 이용한 html 메타데이터 캔버스 구현 (0) | 2022.05.11 |
---|---|
한글 웹 폰트 경량화해보기 (0) | 2022.04.27 |
Visual Studio Cod Extension - Better Comments (0) | 2021.07.27 |
Web Server와 WAS(Web Application Server) 및 Apache Http Server 설치 (0) | 2021.07.15 |
CSR(Client Side Rendering)과 SSR(Server Side Rendering)의 차이 (0) | 2021.05.30 |