이벤트
이벤트 타입
| 이벤트 이름 | 버전 | 설명 |
|---|---|---|
initialized | 2.1.0 버전부터 지원 | 에디터가 초기화될 때 발생합니다. |
beforeUploadImage | 2.2.0 버전부터 지원 | 이미지가 업로드되기 전에 발생합니다. |
afterUploadImage | 2.2.0 버전부터 지원 | 이미지 업로드가 완료된 후에 발생합니다. |
beforeUploadVideo | 2.2.0 버전부터 지원 | 동영상이 업로드되기 전에 발생합니다. |
afterUploadVideo | 2.2.0 버전부터 지원 | 동영상 업로드가 완료된 후에 발생합니다. |
beforeUploadFile | 2.2.0 버전부터 지원 | 파일이 업로드되기 전에 발생합니다. |
afterUploadFile | 2.2.0 버전부터 지원 | 파일 업로드가 완료된 후에 발생합니다. |
beforeOpenDocument | 2.3.0 버전부터 지원 | 문서를 열기 전에(임포트 전에) 발생합니다. |
afterOpenDocument | 2.3.0 버전부터 지원 | 문서를 연 후(임포트 후)에 발생합니다. |
beforeNewDocument | 2.4.1 버전부터 지원 | 새 문서를 생성하기 전에 발생합니다. |
afterNewDocument | 2.4.1 버전부터 지원 | 새 문서가 생성된 후에 발생합니다. |
onSelection | 2.6.0 버전부터 지원 | 캐럿 이동이나 선택 영역 확장 등 선택 동작이 일어날 때 발생합니다. |
beforeCopy | 2.11.0 버전부터 지원 | 에디터의 편집 영역에서 내용이 복사되기 전에 발생합니다. 이 이벤트를 통해 복사되는 HTML을 확인하거나 실제로 복사될 HTML을 설정할 수 있습니다. |
beforePaste | 2.10.0 버전부터 지원 | 붙여넣기 전에 발생합니다. |
afterPaste | 2.10.0 버전부터 지원 | 붙여넣기 후에 발생합니다. |
afterEdit | 2.10.0 버전부터 지원 | 문서가 편집된 후에 발생합니다. |
autoAction | 2.20.2509 버전부터 지원 / 3.2.2509 버전부터 지원 | 사용자 정의 입력 액션이 실행될 때 발생합니다. |
이벤트 등록
API 사용하기
editor.setEventListener()
이벤트를 등록하는 API입니다.
editor.setEventListener('eventName', function(e) {
});
에디터 초기화 시 등록
var editorId = 'synapEditor';
var editorConfig = {};
var html = '';
var eventListeners = {
'eventName': function (e) {
}
};
new SynapEditor(editorId, editorConfig, html, eventListeners);
함수 방식
var editorId = 'synapEditor';
var editorConfig = {};
var html = '';
function SynapEditorEventName(e) {
// The event name starts with an uppercase letter
// ex: initialized => SynapEditorInitialized
// ex: beforeUploadImage => SynapEditorBeforeUploadImage
}
new SynapEditor(editorId, editorConfig, html);
이벤트 제거
API 사용하기
editor.removeEventListener()
등록된 이벤트를 제거하는 데 사용되는 API입니다.
editor.removeEventListener('eventName');
함수에 전달된 객체의 Shape
{
editor: {editor object}, // editor
eventType: 'initialized', // event name
cancelable: false, // whether the event can be cancelled
returnValue: null, // whether the event is cancelled
....
}
editor: 이벤트가 발생한 에디터.eventType: 이벤트 이름.cancelable: 이벤트를 취소할 수 있는지 여부.returnValue: 취소 가능한 이벤트(cancelable: true)의 경우, 이벤트 진행을 취소하려면false를 전달합니다.
이벤트 진행 취소
cancelable이 true인 경우, returnValue를 false로 설정하여 이벤트 진행을 취소할 수 있습니다.
var editorId = 'synapEditor';
var editorConfig = {};
var html = '';
var eventListeners = {
'beforeUploadImage': function (e) {
e.returnValue = false; // The upload will not proceed any further
}
};
new SynapEditor(editorId, editorConfig, html, eventListeners);