Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
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
TeDomum
Nextcloud
Commits
dcc28a3a
Commit
dcc28a3a
authored
8 years ago
by
John Molakvoæ
Committed by
skjnldsv
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
New colour generator
parent
37d32a93
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/js/placeholder.js
+56
-6
56 additions, 6 deletions
core/js/placeholder.js
with
56 additions
and
6 deletions
core/js/placeholder.js
+
56
−
6
View file @
dcc28a3a
/**
* ownCloud
*
* @author John Molakvoæ
* @copyright 2016 John Molakvoæ <fremulon@protonmail.com>
* @author Morris Jobke
* @copyright 2013 Morris Jobke <morris.jobke@gmail.com>
*
...
...
@@ -48,16 +50,64 @@
(
function
(
$
)
{
$
.
fn
.
imageplaceholder
=
function
(
seed
,
text
,
size
)
{
// set optional argument "text" to value of "seed" if undefined
text
=
text
||
seed
;
var
hash
=
md5
(
seed
).
substring
(
0
,
4
),
maxRange
=
parseInt
(
'
ffff
'
,
16
),
hue
=
parseInt
(
hash
,
16
)
/
maxRange
*
256
,
height
=
this
.
height
()
||
size
||
32
;
this
.
css
(
'
background-color
'
,
'
hsl(
'
+
hue
+
'
, 90%, 65%)
'
);
var
hash
=
seed
.
toLowerCase
().
replace
(
/
[^
0-9a-f
]
+/g
,
''
);
// Already a md5 hash?
if
(
!
hash
.
match
(
/^
[
0-9a-f
]{32}
$/g
)
)
{
hash
=
md5
(
hash
);
}
function
rgbToHsl
(
r
,
g
,
b
)
{
r
/=
255
,
g
/=
255
,
b
/=
255
;
var
max
=
Math
.
max
(
r
,
g
,
b
),
min
=
Math
.
min
(
r
,
g
,
b
);
var
h
,
s
,
l
=
(
max
+
min
)
/
2
;
if
(
max
===
min
)
{
h
=
s
=
0
;
// achromatic
}
else
{
var
d
=
max
-
min
;
s
=
l
>
0.5
?
d
/
(
2
-
max
-
min
)
:
d
/
(
max
+
min
);
switch
(
max
)
{
case
r
:
h
=
(
g
-
b
)
/
d
+
(
g
<
b
?
6
:
0
);
break
;
case
g
:
h
=
(
b
-
r
)
/
d
+
2
;
break
;
case
b
:
h
=
(
r
-
g
)
/
d
+
4
;
break
;
}
h
/=
6
;
}
return
[
h
,
s
,
l
];
}
// Init vars
var
result
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
];
var
rgb
=
[
0
,
0
,
0
];
var
sat
=
80
;
var
lum
=
68
;
var
modulo
=
16
;
// Splitting evenly the string
for
(
var
i
in
hash
)
{
result
[
i
%
modulo
]
=
result
[
i
%
modulo
]
+
parseInt
(
hash
.
charAt
(
i
),
16
).
toString
();
}
// Converting our data into a usable rgb format
// Start at 1 because 16%3=1 but 15%3=0 and makes the repartition even
for
(
var
count
=
1
;
count
<
modulo
;
count
++
)
{
rgb
[
count
%
3
]
+=
parseInt
(
result
[
count
]);
}
var
hsl
=
rgbToHsl
(
rgb
[
0
],
rgb
[
1
],
rgb
[
2
]);
// Classic formulla to check the brigtness for our eye
// If too bright, lower the sat
var
bright
=
Math
.
sqrt
(
0.299
*
Math
.
pow
(
rgb
[
0
],
2
)
+
0.587
*
Math
.
pow
(
rgb
[
1
],
2
)
+
0.114
*
Math
.
pow
(
rgb
[
2
],
2
)
);
if
(
bright
>=
200
)
{
sat
=
60
;
}
var
hue
=
parseInt
(
hsl
[
0
]
*
360
);
this
.
css
(
'
background-color
'
,
'
hsl(
'
+
hue
+
'
,
'
+
sat
+
'
%,
'
+
lum
+
'
%)
'
);
// Placeholders are square
var
height
=
this
.
height
()
||
size
||
32
;
this
.
height
(
height
);
this
.
width
(
height
);
...
...
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