Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ckeditor_html_embed
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ckeditor_html_embed
Merge requests
!6
Issue
#3489170
: Added a popup warning when the content inside html embed is not saved.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3489170
: Added a popup warning when the content inside html embed is not saved.
issue/ckeditor_html_embed-3489170:3489170-submit-edit-button
into
1.0.x
Overview
1
Commits
1
Pipelines
0
Changes
3
1 unresolved thread
Hide all comments
Open
SOURABH SISODIA
requested to merge
issue/ckeditor_html_embed-3489170:3489170-submit-edit-button
into
1.0.x
4 months ago
Overview
1
Commits
1
Pipelines
0
Changes
3
1 unresolved thread
Hide all comments
Expand
Closes
#3489170
0
0
Merge request reports
Compare
1.0.x
1.0.x (HEAD)
and
latest version
latest version
f982cb6a
1 commit,
4 months ago
3 files
+
140
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
js/html-embed-warning.js
0 → 100644
+
121
−
0
Options
(
function
(
Drupal
)
{
'
use strict
'
;
let
hasUnsavedChanges
=
false
;
let
originalContent
=
''
;
let
warningPopup
=
null
;
function
createWarningPopup
()
{
const
popup
=
document
.
createElement
(
'
div
'
);
popup
.
className
=
'
form-item--error-message
'
;
popup
.
style
.
cssText
=
`
position: absolute;
background: #fff;
color: #d72222;
padding: 0.3em 0.45em;
border: 1px solid #d72222;
border-radius: 2px;
font-size: 0.75rem;
margin-top: 0.15em;
animation: fade-in 0.2s ease-out;
`
;
// Add keyframes for animation.
const
style
=
document
.
createElement
(
'
style
'
);
style
.
textContent
=
`
@keyframes fade-in {
from { opacity: 0; transform: translateY(-5px); }
to { opacity: 1; transform: translateY(0); }
}
`
;
document
.
head
.
appendChild
(
style
);
popup
.
textContent
=
Drupal
.
t
(
'
Please save your changes.
'
);
return
popup
;
}
function
showWarning
(
targetElement
)
{
if
(
!
warningPopup
)
{
warningPopup
=
createWarningPopup
();
document
.
body
.
appendChild
(
warningPopup
);
}
// Position below the HTML embed area.
const
rect
=
targetElement
.
getBoundingClientRect
();
const
scrollTop
=
window
.
pageYOffset
||
document
.
documentElement
.
scrollTop
;
const
scrollLeft
=
window
.
pageXOffset
||
document
.
documentElement
.
scrollLeft
;
warningPopup
.
style
.
top
=
`
${
rect
.
bottom
+
scrollTop
+
5
}
px`
;
warningPopup
.
style
.
left
=
`
${
rect
.
left
+
scrollLeft
}
px`
;
warningPopup
.
style
.
display
=
'
block
'
;
// Auto-hide after 5 seconds
setTimeout
(()
=>
{
if
(
warningPopup
)
{
warningPopup
.
style
.
display
=
'
none
'
;
}
},
5000
);
// Focus on textarea.
targetElement
.
focus
();
}
Drupal
.
behaviors
.
htmlEmbedWarning
=
{
attach
:
function
(
context
,
settings
)
{
// Track when HTML embed dialog opens (both from edit button and toolbar).
document
.
addEventListener
(
'
click
'
,
function
(
e
)
{
// Handle edit source button.
const
editButton
=
e
.
target
.
closest
(
'
button[data-cke-tooltip-text="Edit source"]
'
);
// Handle toolbar HTML embed button.
const
toolbarButton
=
e
.
target
.
closest
(
'
.ck-button[data-cke-tooltip-text="Insert HTML"]
'
);
if
(
editButton
||
toolbarButton
)
{
setTimeout
(()
=>
{
const
textarea
=
document
.
querySelector
(
'
.ck-reset .ck-input-text.raw-html-embed__source
'
);
if
(
textarea
)
{
originalContent
=
textarea
.
value
;
hasUnsavedChanges
=
false
;
textarea
.
addEventListener
(
'
input
'
,
function
()
{
hasUnsavedChanges
=
this
.
value
!==
originalContent
;
});
}
},
100
);
}
});
// Handle dialog buttons.
document
.
addEventListener
(
'
click
'
,
function
(
e
)
{
const
textarea
=
document
.
querySelector
(
'
.ck-reset .ck-input-text.raw-html-embed__source
'
);
// Save button.
if
(
e
.
target
.
closest
(
'
.raw-html-embed__save-button
'
))
{
hasUnsavedChanges
=
false
;
originalContent
=
textarea
?.
value
||
''
;
}
// Cancel/Close button.
if
(
e
.
target
.
closest
(
'
.raw-html-embed__cancel-button
'
)
||
e
.
target
.
closest
(
'
.ck-button[aria-label="Close"]
'
))
{
if
(
textarea
)
{
textarea
.
value
=
originalContent
;
// Restore original content
}
hasUnsavedChanges
=
false
;
}
});
// Form submit handler.
once
(
'
html-embed-form
'
,
'
form.node-form
'
,
context
).
forEach
(
function
(
form
)
{
form
.
addEventListener
(
'
submit
'
,
function
(
e
)
{
if
(
hasUnsavedChanges
)
{
const
textarea
=
document
.
querySelector
(
'
.ck-reset .ck-input-text.raw-html-embed__source
'
);
if
(
textarea
)
{
e
.
preventDefault
();
e
.
stopPropagation
();
showWarning
(
textarea
);
return
false
;
}
}
});
});
}
};
})(
Drupal
);
Loading