This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtitle-bar.ts
More file actions
128 lines (128 loc) · 6.88 KB
/
title-bar.ts
File metadata and controls
128 lines (128 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { createElement, Event, KeyboardEventArgs } from '@syncfusion/ej2-base';
import { DocumentEditor, FormatType } from '@syncfusion/ej2-documenteditor';
import { Button } from '@syncfusion/ej2-buttons';
import { DropDownButton, ItemModel } from '@syncfusion/ej2-splitbuttons';
import { MenuEventArgs } from '@syncfusion/ej2-navigations';
/**
* Represents document editor title bar.
*/
export class TitleBar {
private tileBarDiv: HTMLElement;
private documentTitle: HTMLElement;
private documentTitleContentEditor: HTMLElement;
private export: DropDownButton;
private print: Button;
private open: Button;
private documentEditor: DocumentEditor;
constructor(element: HTMLElement, docEditor: DocumentEditor, isShareNeeded: Boolean) {
//initializes title bar elements.
this.tileBarDiv = element;
this.documentEditor = docEditor;
this.initializeTitleBar(isShareNeeded);
this.wireEvents();
}
private initializeTitleBar = (isShareNeeded: Boolean): void => {
// tslint:disable-next-line:max-line-length
this.documentTitle = createElement('label', { id: 'documenteditor_title_name', styles: 'font-weight:400;text-overflow:ellipsis;white-space:pre;overflow:hidden;user-select:none;cursor:text' });
// tslint:disable-next-line:max-line-length
this.documentTitleContentEditor = createElement('div', { id: 'documenteditor_title_contentEditor', className: 'single-line', styles: 'border: 1px solid #2B3481;' });
this.documentTitleContentEditor.appendChild(this.documentTitle);
this.tileBarDiv.appendChild(this.documentTitleContentEditor);
this.documentTitleContentEditor.setAttribute('title', 'Document Name. Click or tap to rename this document.');
let btnStyles: string = 'float:right;background: transparent;box-shadow:none; font-family: inherit;border-color: transparent;'
+ 'border-radius: 2px;color:#ffffff;font-size:12px;text-transform:capitalize;margin-top:4px;height:28px;font-weight:400';
// tslint:disable-next-line:max-line-length
this.print = this.addButton('e-de-icon-Print e-de-padding-right', 'Print', btnStyles, 'de-print', 'Print this document (Ctrl+P).', false) as Button;
this.open = this.addButton('e-de-icon-Open e-de-padding-right', 'open', btnStyles, 'de-open', 'Open', false) as Button;
let items: ItemModel[] = [
{ text: 'Microsoft Word (.docx)', id: 'word' },
{ text: 'Syncfusion Document Text (.sfdt)', id: 'sfdt' },
];
// tslint:disable-next-line:max-line-length
this.export = this.addButton('e-de-icon-Download e-de-padding-right', 'Download', btnStyles, 'documenteditor-share', 'Download this document.', true, items) as DropDownButton;
if (!isShareNeeded) {
this.export.element.style.display = 'none';
} else {
this.open.element.style.display = 'none';
}
}
private setTooltipForPopup(): void {
// tslint:disable-next-line:max-line-length
document.getElementById('documenteditor-share-popup').querySelectorAll('li')[0].setAttribute('title', 'Download a copy of this document to your computer as a DOCX file.');
// tslint:disable-next-line:max-line-length
document.getElementById('documenteditor-share-popup').querySelectorAll('li')[1].setAttribute('title', 'Download a copy of this document to your computer as an SFDT file.');
}
private wireEvents = (): void => {
this.print.element.addEventListener('click', this.onPrint);
this.open.element.addEventListener('click', (e: Event) => {
if ((e.target as HTMLInputElement).id === 'de-open') {
let fileUpload: HTMLInputElement = document.getElementById('uploadfileButton') as HTMLInputElement;
fileUpload.value = '';
fileUpload.click();
}
});
this.documentTitleContentEditor.addEventListener('keydown', (e: KeyboardEventArgs) => {
if (e.keyCode === 13) {
e.preventDefault();
this.documentTitleContentEditor.contentEditable = 'false';
if (this.documentTitleContentEditor.textContent === '') {
this.documentTitleContentEditor.textContent = 'Document1';
}
}
});
this.documentTitleContentEditor.addEventListener('blur', (): void => {
if (this.documentTitleContentEditor.textContent === '') {
this.documentTitleContentEditor.textContent = 'Document1';
}
this.documentTitleContentEditor.contentEditable = 'false';
this.documentEditor.documentName = this.documentTitle.textContent;
});
this.documentTitleContentEditor.addEventListener('click', (): void => {
this.updateDocumentEditorTitle();
});
}
private updateDocumentEditorTitle = (): void => {
this.documentTitleContentEditor.contentEditable = 'true';
this.documentTitleContentEditor.focus();
window.getSelection().selectAllChildren(this.documentTitleContentEditor);
}
// Updates document title.
public updateDocumentTitle = (): void => {
if (this.documentEditor.documentName === '') {
this.documentEditor.documentName = 'Untitled';
}
this.documentTitle.textContent = this.documentEditor.documentName;
}
// tslint:disable-next-line:max-line-length
private addButton(iconClass: string, btnText: string, styles: string, id: string, tooltipText: string, isDropDown: boolean, items?: ItemModel[]): Button | DropDownButton {
let button: HTMLButtonElement = createElement('button', { id: id, styles: styles }) as HTMLButtonElement;
this.tileBarDiv.appendChild(button);
button.setAttribute('title', tooltipText);
if (isDropDown) {
// tslint:disable-next-line:max-line-length
let dropButton: DropDownButton = new DropDownButton({ select: this.onExportClick, items: items, iconCss: iconClass, cssClass: 'e-caret-hide', content: btnText, open: (): void => { this.setTooltipForPopup(); } }, button);
return dropButton;
} else {
let ejButton: Button = new Button({ iconCss: iconClass, content: btnText }, button);
return ejButton;
}
}
private onPrint = (): void => {
this.documentEditor.print();
}
private onExportClick = (args: MenuEventArgs): void => {
let value: string = args.item.id;
switch (value) {
case 'word':
this.save('Docx');
break;
case 'sfdt':
this.save('Sfdt');
break;
}
}
private save = (format: string): void => {
// tslint:disable-next-line:max-line-length
this.documentEditor.save(this.documentEditor.documentName === '' ? 'sample' : this.documentEditor.documentName, format as FormatType);
}
}