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
f54a9249
Commit
f54a9249
authored
3 years ago
by
Maximilian Giller
Browse files
Options
Downloads
Patches
Plain Diff
Improved error handling when not being able to load image
parent
d31345be
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#50572
passed
3 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
editor/editor.php
+2
-2
2 additions, 2 deletions
editor/editor.php
editor/images/onerror.png
+0
-0
0 additions, 0 deletions
editor/images/onerror.png
editor/js/tools/menus/selectmenu.js
+65
-23
65 additions, 23 deletions
editor/js/tools/menus/selectmenu.js
with
67 additions
and
25 deletions
editor/editor.php
+
2
−
2
View file @
f54a9249
...
@@ -25,14 +25,14 @@
...
@@ -25,14 +25,14 @@
</br>
</br>
<label
for=
"node-image"
>
Node Image
</label>
<label
for=
"node-image"
>
Node Image
</label>
</br>
</br>
<img
id=
"node-image-preview"
class=
"preview-image"
src=
""
/>
<img
id=
"node-image-preview"
style=
"color:red"
class=
"preview-image"
src=
""
/>
</br>
</br>
<input
type=
"text"
id=
"node-image"
name=
"node-image"
placeholder=
"Enter file name or URL"
class=
"bottom-space"
/>
<input
type=
"text"
id=
"node-image"
name=
"node-image"
placeholder=
"Enter file name or URL"
class=
"bottom-space"
/>
</br>
</br>
<label
for=
"node-detail-image"
>
Info Image
</label>
<label
for=
"node-detail-image"
>
Info Image
</label>
</br>
</br>
<img
id=
"node-detail-image-preview"
class=
"preview-image"
src=
""
/>
<img
id=
"node-detail-image-preview"
style=
"color:red"
class=
"preview-image"
src=
""
/>
</br>
</br>
<input
type=
"text"
id=
"node-detail-image"
name=
"node-detail-image"
placeholder=
"Enter file name or URL"
class=
"bottom-space"
/>
<input
type=
"text"
id=
"node-detail-image"
name=
"node-detail-image"
placeholder=
"Enter file name or URL"
class=
"bottom-space"
/>
...
...
This diff is collapsed.
Click to expand it.
editor/images/onerror.png
0 → 100644
+
0
−
0
View file @
f54a9249
31.1 KiB
This diff is collapsed.
Click to expand it.
editor/js/tools/menus/selectmenu.js
+
65
−
23
View file @
f54a9249
import
{
PLUGIN_PATH
}
from
"
../../../../config
"
;
import
*
as
Graph
from
"
../../graph
"
;
import
*
as
Graph
from
"
../../graph
"
;
import
{
CONTEXT
}
from
"
../../state
"
;
import
{
CONTEXT
}
from
"
../../state
"
;
import
ToolMenu
from
"
./toolmenu
"
;
import
ToolMenu
from
"
./toolmenu
"
;
...
@@ -29,6 +30,7 @@ const NODE_MENU = [
...
@@ -29,6 +30,7 @@ const NODE_MENU = [
NODE_DETAIL_IMG_ID
,
NODE_DETAIL_IMG_ID
,
];
];
const
IMAGE_MENU
=
[
NODE_IMG_ID
,
NODE_DETAIL_IMG_ID
];
const
IMAGE_FIELDS
=
[
const
IMAGE_FIELDS
=
[
{
{
uri
:
NODE_IMG_ID
,
uri
:
NODE_IMG_ID
,
...
@@ -45,6 +47,8 @@ const LINK_MENU = [];
...
@@ -45,6 +47,8 @@ const LINK_MENU = [];
const
MENU
=
[...
NODE_MENU
,
...
LINK_MENU
];
const
MENU
=
[...
NODE_MENU
,
...
LINK_MENU
];
const
ERROR_IMG_PATH
=
PLUGIN_PATH
+
"
editor/images/onerror.png
"
;
export
class
SelectMenu
extends
ToolMenu
{
export
class
SelectMenu
extends
ToolMenu
{
constructor
()
{
constructor
()
{
super
();
super
();
...
@@ -63,33 +67,69 @@ export class SelectMenu extends ToolMenu {
...
@@ -63,33 +67,69 @@ export class SelectMenu extends ToolMenu {
hookMenu
()
{
hookMenu
()
{
MENU
.
forEach
((
menu
)
=>
{
MENU
.
forEach
((
menu
)
=>
{
if
(
IMAGE_MENU
.
includes
(
menu
))
{
return
;
}
// Subscribes to change event for each menu element
// Subscribes to change event for each menu element
this
.
find
(
menu
).
on
(
"
change
"
,
(
e
)
=>
{
this
.
find
(
menu
).
on
(
"
change
"
,
(
e
)
=>
{
var
newValue
=
e
.
target
.
value
;
this
.
updateValue
(
menu
,
e
.
target
.
value
);
var
propertyKey
=
this
.
toProperty
(
menu
);
var
formatedValue
=
this
.
formatValue
(
propertyKey
,
newValue
);
// Modify stored selection
this
.
values
[
SELECTION_KEY
][
propertyKey
]
=
formatedValue
;
// Notify tool
this
.
tool
.
onMenuChange
(
SELECTION_KEY
,
this
.
values
[
SELECTION_KEY
]
);
});
});
});
});
// Special hook for image, to update the shown image with every change
// Special hook
s
for image, to update the shown image with every change
IMAGE_FIELDS
.
forEach
((
imageField
)
=>
{
IMAGE_FIELDS
.
forEach
((
imageField
)
=>
{
// In case image can't be loaded, show message
this
.
find
(
imageField
.
preview
).
on
(
"
error
"
,
(
e
)
=>
{
var
img
=
this
.
find
(
e
.
target
);
// Is source even set?
if
(
img
.
attr
(
"
src
"
)
===
undefined
||
img
.
attr
(
"
src
"
)
===
""
)
{
return
;
}
// Show error message
this
.
setImagePreview
(
ERROR_IMG_PATH
,
imageField
.
preview
);
// Maybe graph image should also be updated, but we might not want to overwrite previously saved images.
});
// Test images before updating them
this
.
find
(
imageField
.
uri
).
on
(
"
change
"
,
(
e
)
=>
{
this
.
find
(
imageField
.
uri
).
on
(
"
change
"
,
(
e
)
=>
{
var
uri
=
e
.
target
.
value
;
var
imageSource
=
e
.
target
.
value
;
this
.
setImagePreview
(
uri
,
imageField
.
preview
);
// If source is empty, always apply it
if
(
imageSource
===
undefined
||
imageSource
===
""
)
{
this
.
updateValue
(
imageField
.
uri
,
imageSource
);
this
.
setImagePreview
(
imageSource
,
imageField
.
preview
);
return
;
}
// Try loading the image and only apply it on success
var
img
=
new
Image
();
img
.
addEventListener
(
"
load
"
,
()
=>
{
this
.
updateValue
(
imageField
.
uri
,
imageSource
);
this
.
setImagePreview
(
imageSource
,
imageField
.
preview
);
});
img
.
addEventListener
(
"
error
"
,
()
=>
{
this
.
setImagePreview
(
ERROR_IMG_PATH
,
imageField
.
preview
);
});
img
.
src
=
this
.
getFullImageSource
(
imageSource
);
});
});
});
});
}
}
updateValue
(
menu
,
newValue
)
{
var
propertyKey
=
this
.
toProperty
(
menu
);
var
formatedValue
=
this
.
formatValue
(
propertyKey
,
newValue
);
// Modify stored selection
this
.
values
[
SELECTION_KEY
][
propertyKey
]
=
formatedValue
;
// Notify tool
this
.
tool
.
onMenuChange
(
SELECTION_KEY
,
this
.
values
[
SELECTION_KEY
]);
}
updateImagePreviews
()
{
updateImagePreviews
()
{
IMAGE_FIELDS
.
forEach
((
imageField
)
=>
{
IMAGE_FIELDS
.
forEach
((
imageField
)
=>
{
var
uri
=
this
.
find
(
imageField
.
uri
).
val
();
var
uri
=
this
.
find
(
imageField
.
uri
).
val
();
...
@@ -97,22 +137,24 @@ export class SelectMenu extends ToolMenu {
...
@@ -97,22 +137,24 @@ export class SelectMenu extends ToolMenu {
});
});
}
}
setImagePreview
(
uri
,
previewId
)
{
getFullImageSource
(
uri
)
{
var
previewImage
=
this
.
find
(
previewId
);
if
(
uri
===
""
)
{
if
(
uri
===
""
)
{
// Show default empty image
// Show default empty image
p
re
viewImage
.
attr
(
"
src
"
,
""
)
;
re
turn
""
;
}
else
if
(
uri
.
includes
(
"
/
"
))
{
}
else
if
(
uri
.
includes
(
"
/
"
))
{
// Is absolute URL
// Is absolute URL
p
re
viewImage
.
attr
(
"
src
"
,
uri
)
;
re
turn
uri
;
}
else
{
}
else
{
// Is file name
// Is file name
var
url
=
Graph
.
IMAGE_SRC
+
uri
;
return
Graph
.
IMAGE_SRC
+
uri
;
previewImage
.
attr
(
"
src
"
,
url
);
}
}
}
}
setImagePreview
(
uri
,
previewId
)
{
var
previewImage
=
this
.
find
(
previewId
);
previewImage
.
attr
(
"
src
"
,
this
.
getFullImageSource
(
uri
));
}
formatValue
(
propertyKey
,
rawValue
)
{
formatValue
(
propertyKey
,
rawValue
)
{
var
formattedValue
=
rawValue
;
var
formattedValue
=
rawValue
;
...
...
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