Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LQDN Adminsys
generateur-slogans
Commits
45bebda6
Verified
Commit
45bebda6
authored
Sep 27, 2017
by
Thibaut Broggi
Browse files
Cache images in javascript
close
#3
parent
5c55ce0b
Changes
1
Hide whitespace changes
Inline
Side-by-side
canvas.js
View file @
45bebda6
let
cachedImages
=
[];
let
canvas
=
document
.
getElementById
(
'
output
'
);
let
ctx
=
canvas
.
getContext
(
'
2d
'
);
...
...
@@ -15,6 +17,17 @@ let get = function(url, cb) {
xmlHttp
.
send
(
null
);
}
let
getImage
=
function
(
id
,
cb
)
{
if
(
cachedImages
[
id
])
cb
(
cachedImages
[
id
]);
else
{
get
(
'
./imgs/
'
+
id
+
'
.svg
'
,
function
(
res
)
{
cachedImages
[
id
]
=
res
;
cb
(
res
);
});
}
}
let
draw
=
function
()
{
let
bgColor
=
document
.
querySelector
(
'
.colorpicker input[type="radio"][name="bg-color"]:checked
'
).
value
;
let
fgColor
=
document
.
querySelector
(
'
.colorpicker input[type="radio"][name="fg-color"]:checked
'
).
value
;
...
...
@@ -67,7 +80,7 @@ let draw = function() {
ctx
.
fillText
(
'
La Quadrature du Net !
'
,
offset
,
height
*
0.9
);
//Draw picto
get
(
'
./imgs/
'
+
icon
+
'
.svg
'
,
function
(
res
)
{
get
Image
(
icon
,
function
(
res
)
{
let
img
=
new
Image
();
let
imgXml
=
res
.
replace
(
/#FFD201/g
,
fgColor
);
img
.
src
=
'
data:image/svg+xml;base64,
'
+
btoa
(
imgXml
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment