2013-08-28 14:25:14 +00:00
|
|
|
/**
|
|
|
|
* ownCloud
|
|
|
|
*
|
|
|
|
* @author Morris Jobke
|
|
|
|
* @copyright 2013 Morris Jobke <morris.jobke@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-08-28 21:04:55 +00:00
|
|
|
* Adds a background color to the element called on and adds the first character
|
2013-08-28 14:25:14 +00:00
|
|
|
* of the passed in string. This string is also the seed for the generation of
|
|
|
|
* the background color.
|
|
|
|
*
|
|
|
|
* You have following HTML:
|
|
|
|
*
|
|
|
|
* <div id="albumart"></div>
|
|
|
|
*
|
|
|
|
* And call this from Javascript:
|
|
|
|
*
|
2013-10-23 14:47:25 +00:00
|
|
|
* $('#albumart').imageplaceholder('The Album Title');
|
2013-08-28 14:25:14 +00:00
|
|
|
*
|
|
|
|
* Which will result in:
|
|
|
|
*
|
2013-09-02 16:29:16 +00:00
|
|
|
* <div id="albumart" style="background-color: hsl(123, 90%, 65%); ... ">T</div>
|
2013-08-28 14:25:14 +00:00
|
|
|
*
|
2013-09-25 10:57:41 +00:00
|
|
|
* You may also call it like this, to have a different background, than the seed:
|
|
|
|
*
|
2013-10-23 14:47:25 +00:00
|
|
|
* $('#albumart').imageplaceholder('The Album Title', 'Album Title');
|
2013-09-25 10:57:41 +00:00
|
|
|
*
|
|
|
|
* Resulting in:
|
|
|
|
*
|
|
|
|
* <div id="albumart" style="background-color: hsl(123, 90%, 65%); ... ">A</div>
|
|
|
|
*
|
2013-08-28 14:25:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function ($) {
|
2015-12-17 06:56:02 +00:00
|
|
|
$.fn.imageplaceholder = function(seed, text, size) {
|
2013-09-25 15:19:38 +00:00
|
|
|
// set optional argument "text" to value of "seed" if undefined
|
|
|
|
text = text || seed;
|
2013-09-25 10:57:41 +00:00
|
|
|
|
2015-12-22 10:07:33 +00:00
|
|
|
var hash = md5(seed).substring(0, 4),
|
|
|
|
maxRange = parseInt('ffff', 16),
|
2013-09-02 14:41:18 +00:00
|
|
|
hue = parseInt(hash, 16) / maxRange * 256,
|
2015-12-17 06:56:02 +00:00
|
|
|
height = this.height() || size || 32;
|
2013-09-02 16:20:18 +00:00
|
|
|
this.css('background-color', 'hsl(' + hue + ', 90%, 65%)');
|
2013-08-28 14:52:12 +00:00
|
|
|
|
2015-12-17 06:56:02 +00:00
|
|
|
// Placeholders are square
|
|
|
|
this.height(height);
|
|
|
|
this.width(height);
|
|
|
|
|
2013-08-28 14:52:12 +00:00
|
|
|
// CSS rules
|
2013-09-02 14:41:18 +00:00
|
|
|
this.css('color', '#fff');
|
2015-05-22 01:26:30 +00:00
|
|
|
this.css('font-weight', 'normal');
|
2013-08-28 14:52:12 +00:00
|
|
|
this.css('text-align', 'center');
|
|
|
|
|
2013-08-28 19:54:20 +00:00
|
|
|
// calculate the height
|
|
|
|
this.css('line-height', height + 'px');
|
|
|
|
this.css('font-size', (height * 0.55) + 'px');
|
|
|
|
|
2013-08-28 14:52:12 +00:00
|
|
|
if(seed !== null && seed.length) {
|
2013-09-25 10:57:41 +00:00
|
|
|
this.html(text[0].toUpperCase());
|
2013-08-28 14:52:12 +00:00
|
|
|
}
|
2013-08-28 14:25:14 +00:00
|
|
|
};
|
2013-08-28 14:52:12 +00:00
|
|
|
}(jQuery));
|