Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Knowledge Space WP Plugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alg
Knowledge Space WP Plugin
Commits
70cd9806
Commit
70cd9806
authored
3 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Added pop up on tab close with unsaved changes
parent
ee911b88
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
editor/js/interactions.js
+1
-0
1 addition, 0 deletions
editor/js/interactions.js
editor/js/manageddata.js
+39
-4
39 additions, 4 deletions
editor/js/manageddata.js
with
40 additions
and
4 deletions
editor/js/interactions.js
+
1
−
0
View file @
70cd9806
...
...
@@ -12,6 +12,7 @@ export function initInteractions() {
});
jQuery
(
"
button#save
"
).
on
(
"
click
"
,
()
=>
{
saveGraphJson
(
SPACE
,
graph
.
getCleanData
());
// space_id defined globaly through knowledge-space.php
graph
.
saveChanges
();
});
// Fill space dropdown
...
...
This diff is collapsed.
Click to expand it.
editor/js/manageddata.js
+
39
−
4
View file @
70cd9806
export
default
class
ManagedData
{
constructor
(
data
)
{
this
.
data
=
data
;
this
.
history
=
[];
// Newest state is always at 0
this
.
history
=
[];
// Newest state is always at 0
this
.
historyPosition
=
0
;
this
.
unsavedChanges
=
false
;
this
.
storeCurrentData
(
"
Initial state
"
);
this
.
storeCurrentData
(
"
Initial state
"
,
false
);
}
updateUnsavedChangesHandler
()
{
if
(
this
.
hasUnsavedChanges
())
{
console
.
log
(
"
Unsaved changes...
"
);
window
.
addEventListener
(
"
beforeunload
"
,
this
.
handleBeforeUnload
);
}
else
{
console
.
log
(
"
Everything saved...
"
);
window
.
removeEventListener
(
"
beforeunload
"
,
this
.
handleBeforeUnload
);
}
}
handleBeforeUnload
(
e
)
{
var
confirmationMessage
=
'
If you leave before saving, unsaved changes will be lost.
'
;
(
e
||
window
.
event
).
returnValue
=
confirmationMessage
;
//Gecko + IE
return
confirmationMessage
;
//Gecko + Webkit, Safari, Chrome etc.
}
hasUnsavedChanges
()
{
return
this
.
unsavedChanges
;
}
saveChanges
()
{
this
.
unsavedChanges
=
false
;
this
.
updateUnsavedChangesHandler
();
}
onUndo
()
{}
...
...
@@ -31,7 +58,10 @@ export default class ManagedData {
step
(
direction
=
1
)
{
var
newHistoryPosition
=
this
.
historyPosition
+
Math
.
sign
(
direction
);
if
(
newHistoryPosition
>=
this
.
history
.
length
||
newHistoryPosition
<
0
)
{
if
(
newHistoryPosition
>=
this
.
history
.
length
||
newHistoryPosition
<
0
)
{
return
false
;
}
...
...
@@ -45,7 +75,7 @@ export default class ManagedData {
return
data
;
}
storeCurrentData
(
description
)
{
storeCurrentData
(
description
,
relevantChanges
=
true
)
{
var
formattedData
=
this
.
storableData
(
this
.
data
);
this
.
history
.
unshift
({
...
...
@@ -56,5 +86,10 @@ export default class ManagedData {
// Forget about the currently stored potential future
this
.
history
.
splice
(
0
,
this
.
historyPosition
);
this
.
historyPosition
=
0
;
if
(
!
this
.
hasUnsavedChanges
()
&&
relevantChanges
)
{
this
.
unsavedChanges
=
true
;
this
.
updateUnsavedChangesHandler
();
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment