Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
a-doc-editor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ramdayal Munda
a-doc-editor
Commits
686178f5
Commit
686178f5
authored
Dec 19, 2023
by
ramdayalmunda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bold and italic added on the toolbar
parent
6398a96e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
22 deletions
+84
-22
a-doc-editor.css
dist/assets/a-doc-editor.css
+14
-0
a-doc-editor.js
dist/assets/a-doc-editor.js
+69
-21
index.html
dist/index.html
+1
-1
No files found.
dist/assets/a-doc-editor.css
View file @
686178f5
...
@@ -50,6 +50,13 @@
...
@@ -50,6 +50,13 @@
.a-doc-editor
.header
button
{
.a-doc-editor
.header
button
{
width
:
25px
;
width
:
25px
;
}
}
.a-doc-editor
.header
.option-button
{
width
:
25px
;
display
:
flex
;
flex-direction
:
column
;
text-align
:
center
;
justify-content
:
center
;
}
.a-doc-editor
.header
.option
input
{
.a-doc-editor
.header
.option
input
{
width
:
25px
;
width
:
25px
;
}
}
...
@@ -75,6 +82,13 @@
...
@@ -75,6 +82,13 @@
background-color
:
white
;
background-color
:
white
;
cursor
:
pointer
;
cursor
:
pointer
;
}
}
.a-doc-editor
.header
.option.selected
{
padding
:
1px
;
background-color
:
#91d8bd
;
cursor
:
pointer
;
}
.a-doc-editor
.footer
{
.a-doc-editor
.footer
{
overflow
:
auto
;
overflow
:
auto
;
...
...
dist/assets/a-doc-editor.js
View file @
686178f5
...
@@ -24,6 +24,9 @@ var ADocEditor = function (customConfig) {
...
@@ -24,6 +24,9 @@ var ADocEditor = function (customConfig) {
var
fontSize
;
var
fontSize
;
var
fontColor
;
var
fontColor
;
var
fontColorLabel
;
var
fontColorLabel
;
var
fontBold
;
var
fontItalic
;
var
fontUnderline
;
var
fullScreenLoadingOverlay
;
var
fullScreenLoadingOverlay
;
var
defaultConfig
=
{
var
defaultConfig
=
{
...
@@ -114,23 +117,33 @@ var ADocEditor = function (customConfig) {
...
@@ -114,23 +117,33 @@ var ADocEditor = function (customConfig) {
</div>
</div>
<div class="option-bar">
<div class="option-bar">
<div class="option">
<div class="option">
<div class="dropdown-label" ad
c
-target="#
${
fontFamilyDropdownId
}
" style="min-width:180px"></div>
<div class="dropdown-label" ad
e
-target="#
${
fontFamilyDropdownId
}
" style="min-width:180px"></div>
<div class="dropdown-list" id="
${
fontFamilyDropdownId
}
" ad
c
-type="dropdown"></div>
<div class="dropdown-list" id="
${
fontFamilyDropdownId
}
" ad
e
-type="dropdown"></div>
</div>
</div>
<div class="option">
<div class="option">
<button ad
c
-action="font-size-minus">-</button>
<button ad
e
-action="font-size-minus">-</button>
<input ad
c
-action="font-size-set"/>
<input ad
e
-action="font-size-set"/>
<button ad
c
-action="font-size-plus">+</button>
<button ad
e
-action="font-size-plus">+</button>
</div>
</div>
<div class="option">
<div class="option">
<div class="font-color">
<div class="font-color">
<span>A</span>
<span>A</span>
<span class="color-bar" ad
c
-label="font-color"></span>
<span class="color-bar" ad
e
-label="font-color"></span>
<input type="color" ad
c
-action="font-color">
<input type="color" ad
e
-action="font-color">
</div>
</div>
</div>
</div>
<div class="option" ade-action="font-bold">
<div class="option-button"><strong>B</strong></div>
</div>
<div class="option" ade-action="font-italic">
<div class="option-button"><em>I</em></div>
</div>
<div class="option" ade-action="font-underline">
<div class="option-button"><u>U</u></div>
</div>
</div>
</div>
</div>
</div>
<div class="body">
<div class="body">
...
@@ -214,15 +227,23 @@ var ADocEditor = function (customConfig) {
...
@@ -214,15 +227,23 @@ var ADocEditor = function (customConfig) {
mainComponent
.
getElementsByClassName
(
'toggle-sidebar'
)[
1
].
addEventListener
(
'click'
,
(
e
)
=>
{
mainComponent
.
getElementsByClassName
(
'toggle-sidebar'
)[
1
].
addEventListener
(
'click'
,
(
e
)
=>
{
rightSidebar
.
classList
.
toggle
(
'hide'
)
rightSidebar
.
classList
.
toggle
(
'hide'
)
})
})
fontFamily
=
container
.
querySelector
(
`[ad
c
-target="#
${
fontFamilyDropdownId
}
"]`
)
fontFamily
=
container
.
querySelector
(
`[ad
e
-target="#
${
fontFamilyDropdownId
}
"]`
)
fontFamilyDropdown
=
document
.
getElementById
(
fontFamilyDropdownId
)
fontFamilyDropdown
=
document
.
getElementById
(
fontFamilyDropdownId
)
fontFamilyDropdown
.
addEventListener
(
'click'
,
changeFontFamily
)
fontFamilyDropdown
.
addEventListener
(
'click'
,
changeFontFamily
)
reRenderFontDropdown
()
reRenderFontDropdown
()
fontSize
=
container
.
querySelector
(
'[adc-action="font-size-set"]'
)
fontSize
=
container
.
querySelector
(
'[ade-action="font-size-set"]'
)
fontColor
=
container
.
querySelector
(
'[adc-action="font-color"]'
)
fontColor
=
container
.
querySelector
(
'[ade-action="font-color"]'
)
fontColor
.
addEventListener
(
'input'
,
changeFontColor
)
fontColor
.
addEventListener
(
'input'
,
changeFontColor
)
fontColorLabel
=
container
.
querySelector
(
'[adc-label="font-color"]'
)
fontColorLabel
=
container
.
querySelector
(
'[ade-label="font-color"]'
)
fontBold
=
container
.
querySelector
(
'[ade-action="font-bold"]'
)
fontBold
.
addEventListener
(
'click'
,
toggleBold
)
fontItalic
=
container
.
querySelector
(
'[ade-action="font-italic"]'
)
fontItalic
.
addEventListener
(
'click'
,
toggleItalic
)
fontUnderline
=
container
.
querySelector
(
'[ade-action="font-underline"]'
)
fontUnderline
.
addEventListener
(
'click'
,
toggleUnderline
)
fullScreenLoadingOverlay
=
document
.
createElement
(
'div'
)
fullScreenLoadingOverlay
=
document
.
createElement
(
'div'
)
fullScreenLoadingOverlay
.
innerText
=
'Loading...'
fullScreenLoadingOverlay
.
innerText
=
'Loading...'
...
@@ -602,6 +623,8 @@ var ADocEditor = function (customConfig) {
...
@@ -602,6 +623,8 @@ var ADocEditor = function (customConfig) {
caretData.style.fontFamily = fontFamily.innerText
caretData.style.fontFamily = fontFamily.innerText
caretData.style.fontSize = Number(fontSize.value)
caretData.style.fontSize = Number(fontSize.value)
caretData.style.fontColor = fontColor.value
caretData.style.fontColor = fontColor.value
caretData.style.bold = fontBold.classList.contains('selected')
caretData.style.italic = fontItalic.classList.contains('selected')
caretData.activeData.formatedText[caretData.index] = { ...caretData.style }
caretData.activeData.formatedText[caretData.index] = { ...caretData.style }
caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index)
caretData.activeData.plainContent = caretData.activeData.plainContent.slice(0, caretData.index) + e.key + caretData.activeData.plainContent.slice(caretData.index)
...
@@ -872,7 +895,7 @@ var ADocEditor = function (customConfig) {
...
@@ -872,7 +895,7 @@ var ADocEditor = function (customConfig) {
caretData.activeData.style.fontFamily = e.target.innerText
caretData.activeData.style.fontFamily = e.target.innerText
}
}
} else {
} else {
let labels = container.querySelectorAll(`
[
ad
c
-
target
=
"#${fontFamilyDropdown.id}"
]
`)
let labels = container.querySelectorAll(`
[
ad
e
-
target
=
"#${fontFamilyDropdown.id}"
]
`)
labels.forEach(item => item.innerText = caretData.style.fontFamily)
labels.forEach(item => item.innerText = caretData.style.fontFamily)
}
}
}
}
...
@@ -896,6 +919,31 @@ var ADocEditor = function (customConfig) {
...
@@ -896,6 +919,31 @@ var ADocEditor = function (customConfig) {
}
}
}
}
function toggleBold(e){
let isBold = fontBold.classList.contains('selected')
caretData.style.bold = !isBold
if (!isBold) fontBold.classList.add('selected')
else fontBold.classList.remove('selected')
focusLastCanvas()
if (!caretData.activeData.plainContent.length) {
caretData.activeData.style.bold = !isBold
}
}
function toggleItalic(e){
let isItalic = fontItalic.classList.contains('selected')
caretData.style.italic = !isItalic
if (!isItalic) fontItalic.classList.add('selected')
else fontItalic.classList.remove('selected')
focusLastCanvas()
if (!caretData.activeData.plainContent.length) {
caretData.activeData.style.italic = !isItalic
}
}
function toggleUnderline(e){
console.log('underline', fontUnderline)
}
function focusLastCanvas(){
function focusLastCanvas(){
if (!lastFocusCanvas) lastFocusCanvas = canvasList[0].el
if (!lastFocusCanvas) lastFocusCanvas = canvasList[0].el
if (lastFocusCanvas) {
if (lastFocusCanvas) {
...
@@ -909,7 +957,7 @@ var ADocEditor = function (customConfig) {
...
@@ -909,7 +957,7 @@ var ADocEditor = function (customConfig) {
fontFamilyDropdown.innerHTML = ""
fontFamilyDropdown.innerHTML = ""
fontList.forEach((font, i) => {
fontList.forEach((font, i) => {
let optionTag = document.createElement('div')
let optionTag = document.createElement('div')
optionTag.setAttribute('ad
c
-type', 'option')
optionTag.setAttribute('ad
e
-type', 'option')
optionTag.setAttribute('class', 'dropdown-option')
optionTag.setAttribute('class', 'dropdown-option')
optionTag.setAttribute('value', font.name)
optionTag.setAttribute('value', font.name)
optionTag.style.fontFamily = font.name
optionTag.style.fontFamily = font.name
...
@@ -924,9 +972,9 @@ var ADocEditor = function (customConfig) {
...
@@ -924,9 +972,9 @@ var ADocEditor = function (customConfig) {
function bindGlobalEvents() {
function bindGlobalEvents() {
let options = container.querySelectorAll('[ad
c
-target]')
let options = container.querySelectorAll('[ad
e
-target]')
options.forEach(option => {
options.forEach(option => {
let target = container.querySelector(option.getAttribute('ad
c
-target'))
let target = container.querySelector(option.getAttribute('ad
e
-target'))
option.innerText = target?.children?.[0]?.innerText ? target?.children?.[0]?.innerText : ''
option.innerText = target?.children?.[0]?.innerText ? target?.children?.[0]?.innerText : ''
})
})
fontSize.value = caretData.style.fontSize
fontSize.value = caretData.style.fontSize
...
@@ -934,27 +982,27 @@ var ADocEditor = function (customConfig) {
...
@@ -934,27 +982,27 @@ var ADocEditor = function (customConfig) {
fontColorLabel.style.backgroundColor = caretData.style.fontColor
fontColorLabel.style.backgroundColor = caretData.style.fontColor
container.addEventListener('click', (e) => {
container.addEventListener('click', (e) => {
if (e.target.getAttribute('ad
c
-type') == 'option') {
if (e.target.getAttribute('ad
e
-type') == 'option') {
let parent = e.target.parentElement
let parent = e.target.parentElement
let labelList = container.querySelectorAll(`
[
ad
c
-
target
=
"#${parent.id}"
]
`)
let labelList = container.querySelectorAll(`
[
ad
e
-
target
=
"#${parent.id}"
]
`)
labelList.forEach(item => {
labelList.forEach(item => {
item.innerText = e.target.innerText
item.innerText = e.target.innerText
})
})
closeAllExcept()
closeAllExcept()
} else {
} else {
let target = container.querySelector(e.target.getAttribute('ad
c
-target'))
let target = container.querySelector(e.target.getAttribute('ad
e
-target'))
closeAllExcept(target)
closeAllExcept(target)
}
}
if (e.target.getAttribute('ad
c
-action')=='font-size-minus'){
if (e.target.getAttribute('ad
e
-action')=='font-size-minus'){
changeFontSize(Number(fontSize.value)-1)
changeFontSize(Number(fontSize.value)-1)
}
}
if (e.target.getAttribute('ad
c
-action')=='font-size-plus'){
if (e.target.getAttribute('ad
e
-action')=='font-size-plus'){
changeFontSize(Number(fontSize.value)+1)
changeFontSize(Number(fontSize.value)+1)
}
}
function closeAllExcept(except) {
function closeAllExcept(except) {
let dropdownLists = container.querySelectorAll('[ad
c
-type="dropdown"]')
let dropdownLists = container.querySelectorAll('[ad
e
-type="dropdown"]')
dropdownLists.forEach(item => {
dropdownLists.forEach(item => {
if (item == except) {
if (item == except) {
item.classList.toggle('show')
item.classList.toggle('show')
...
...
dist/index.html
View file @
686178f5
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Document
</title>
<title>
Custom Document Editor
</title>
<link
rel=
"stylesheet"
href=
"./assets/a-doc-editor.css"
>
<link
rel=
"stylesheet"
href=
"./assets/a-doc-editor.css"
>
<script
src=
"./assets/fontkit.umd.min.js"
></script>
<script
src=
"./assets/fontkit.umd.min.js"
></script>
<script
src=
"./assets/pdf-lib.min.js"
></script>
<script
src=
"./assets/pdf-lib.min.js"
></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment