-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfavicon_generator.js
41 lines (37 loc) · 1.24 KB
/
favicon_generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* @file
*
* Favicon generator color picker function.
*/
(function($) {
Drupal.behaviors.favicon_generator = {
attach: function(context, settings) {
// Attach color wheel behaviour.
$('.favicon_generator_colorpicker').farbtastic('#edit-favicon-generator-color');
// Attach onClick event for swatches.
$('.form-item-favicon-generator-color .color-preset:not(.favicon-generator-color-preset-processed)')
.addClass('favicon-generator-color-preset-processed')
.click(function() {
var color = $(this).css('background-color');
color = Drupal.favicon_generator.rgb2hex(color);
$.farbtastic('.favicon_generator_colorpicker').setColor(color);
});
}
};
Drupal.favicon_generator = Drupal.favicon_generator || {};
Drupal.favicon_generator.rgb2hex = function(rgb) {
if (rgb.search("rgb") == -1) {
return rgb;
}
else {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
return ("#" +
Drupal.favicon_generator.hex(rgb[1]) +
Drupal.favicon_generator.hex(rgb[2]) +
Drupal.favicon_generator.hex(rgb[3]));
}
};
Drupal.favicon_generator.hex = function(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
};
})(jQuery);