Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
105 lines (88 loc) · 3.7 KB
/
Copy pathscript.js
File metadata and controls
105 lines (88 loc) · 3.7 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
class PDFEditor {
constructor() {
this.content = '';
this.fontSize = '16px';
this.selectedColor = '#FFFFFF';
this.currentFormat = {
fontSize: '16px',
color: '#FFFFFF',
start: 0,
end: 0
};
this.initializeElements();
this.setupEventListeners();
this.renderPage();
}
initializeElements() {
this.fontSizeSelect = document.getElementById('fontSize');
this.colorButtons = document.querySelectorAll('.color-btn');
this.pagesContainer = document.getElementById('pages');
}
setupEventListeners() {
this.fontSizeSelect.addEventListener('change', (e) => this.changeFontSize(e.target.value));
this.colorButtons.forEach(button => {
button.addEventListener('click', () => {
const color = button.dataset.color;
this.changeColor(color);
});
});
}
createPageElement() {
const pageDiv = document.createElement('div');
pageDiv.className = 'page';
const textarea = document.createElement('textarea');
textarea.value = this.content;
textarea.style.fontSize = this.fontSize;
textarea.style.color = this.selectedColor;
textarea.addEventListener('input', (e) => {
this.content = e.target.value;
});
textarea.addEventListener('select', (e) => {
this.currentFormat.start = e.target.selectionStart;
this.currentFormat.end = e.target.selectionEnd;
});
pageDiv.appendChild(textarea);
return pageDiv;
}
renderPage() {
this.pagesContainer.innerHTML = '';
const pageElement = this.createPageElement();
this.pagesContainer.appendChild(pageElement);
}
changeFontSize(size) {
this.fontSize = size + 'px';
const textarea = this.pagesContainer.querySelector('.page textarea');
if (textarea && textarea.selectionStart !== textarea.selectionEnd) {
// Seçili metin varsa, sadece seçili metni güncelle
const selectedText = this.content.substring(textarea.selectionStart, textarea.selectionEnd);
const newContent = this.content.substring(0, textarea.selectionStart) +
`<span style="font-size: ${this.fontSize}">${selectedText}</span>` +
this.content.substring(textarea.selectionEnd);
this.content = newContent;
} else {
// Seçili metin yoksa, yeni yazılacak metinler için font boyutunu güncelle
textarea.style.fontSize = this.fontSize;
}
this.renderPage();
}
changeColor(color) {
this.selectedColor = color;
const textarea = this.pagesContainer.querySelector('.page textarea');
if (textarea && textarea.selectionStart !== textarea.selectionEnd) {
// Seçili metin varsa, sadece seçili metni güncelle
const selectedText = this.content.substring(textarea.selectionStart, textarea.selectionEnd);
const newContent = this.content.substring(0, textarea.selectionStart) +
`<span style="color: ${this.selectedColor}">${selectedText}</span>` +
this.content.substring(textarea.selectionEnd);
this.content = newContent;
} else {
// Seçili metin yoksa, yeni yazılacak metinler için rengi güncelle
textarea.style.color = this.selectedColor;
}
this.renderPage();
}
}
// Initialize the editor when the page loads
document.addEventListener('DOMContentLoaded', () => {
new PDFEditor();
});