-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme.js
More file actions
32 lines (31 loc) · 717 Bytes
/
theme.js
File metadata and controls
32 lines (31 loc) · 717 Bytes
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
/**
* jQuery Themes
*
* Used to create CSS variables starting from the parent element
* to be accessed within your stylesheets.
*
* Example Usage
*
* $(document.body).theme({
* 'font-size': '16px',
* 'primary': '#10c15c',
* 'secondary': '#4b5555'
* });
*
* Properties are now accessible in CSS
*
* P {
* font-size: var(--font-size);
* color: var(--primary);
* }
*
* When switching between multiple themes, include the same named properties
* with different values.
*/
(function($) {
$.fn.theme = function(theme) {
var themeRoot = $(this);
$(themeRoot).addClass('theme-root');
Object.keys(theme).forEach(k => $(themeRoot).css(`--${k}`, `${theme[k]}`));
};
})(jQuery);