summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2016-04-07 05:03:38 +0200
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>2016-04-07 05:03:38 +0200
commitfade4796e74f3f26ebfb0be086a4f85e2ccfaf58 (patch)
treec899ae73507c2fe730f5dc808a7e689c35a324f4
parent9b930cd01d2a536cfa21ba08a3be737cdfe4e54b (diff)
parent28571e6361eeb60ff241f8d8cc6a9a7e7fcdd318 (diff)
downloadnextcloud-server-fade4796e74f3f26ebfb0be086a4f85e2ccfaf58.tar.gz
nextcloud-server-fade4796e74f3f26ebfb0be086a4f85e2ccfaf58.zip
Merge pull request #23768 from owncloud/skjnldsv-color-generator-edit
Updated color generator
-rw-r--r--core/js/placeholder.js28
1 files changed, 23 insertions, 5 deletions
diff --git a/core/js/placeholder.js b/core/js/placeholder.js
index 8eb17b43fa4..da721ac5bcb 100644
--- a/core/js/placeholder.js
+++ b/core/js/placeholder.js
@@ -47,12 +47,23 @@
* <div id="albumart" style="background-color: hsl(123, 90%, 65%); ... ">A</div>
*
*/
+
+ /*
+ * Alternatively, you can use the prototype function to convert your string to hsl colors:
+ *
+ * "a6741a86aded5611a8e46ce16f2ad646".toHsl()
+ *
+ * Will return the hsl parameters within an array:
+ *
+ * [290, 60, 68]
+ *
+ */
(function ($) {
- $.fn.imageplaceholder = function(seed, text, size) {
- text = text || seed;
- var hash = seed.toLowerCase().replace(/[^0-9a-f]+/g, '');
+ String.prototype.toHsl = function() {
+
+ var hash = this.toLowerCase().replace(/[^0-9a-f]+/g, '');
// Already a md5 hash?
if( !hash.match(/^[0-9a-f]{32}$/g) ) {
@@ -103,8 +114,15 @@
if (bright >= 200) {
sat = 60;
}
- var hue = parseInt(hsl[0] * 360);
- this.css('background-color', 'hsl('+hue+', '+sat+'%, '+lum+'%)');
+ return [parseInt(hsl[0] * 360), sat, lum];
+ };
+
+ $.fn.imageplaceholder = function(seed, text, size) {
+ text = text || seed;
+
+ // Compute the hash
+ var hsl = seed.toHsl();
+ this.css('background-color', 'hsl('+hsl[0]+', '+hsl[1]+'%, '+hsl[2]+'%)');
// Placeholders are square
var height = this.height() || size || 32;