root / htmltest / sites / all / modules / sweaver / plugins / sweaver_plugin_palettes / sweaver_plugin_palettes.js @ dc45a079
1 |
|
---|---|
2 |
/**
|
3 |
* Add an extra color css
|
4 |
*/
|
5 |
|
6 |
(function ($) { |
7 |
|
8 |
/**
|
9 |
* Hook onload behavior
|
10 |
*/
|
11 |
$(document).ready(function() { |
12 |
|
13 |
// Check if we need to load the stylesheet when the editor is active.
|
14 |
var palette = $('#sweaver_plugin_palettes [name=sweaver_plugin_palette]').val(); |
15 |
|
16 |
if (palette != '') { |
17 |
// Add a external stylesheet container in the head section.
|
18 |
var link = '<link id="sweaver-palette" href="' + $('#palette-' + palette + ' .file').text() + '" media="all" rel="stylesheet" />'; |
19 |
$('head').append(link); |
20 |
} |
21 |
|
22 |
$('#sweaver_plugin_palettes .colors').click(function(event) { |
23 |
Drupal.Sweaver.changed = true;
|
24 |
|
25 |
var $this = $(this); |
26 |
|
27 |
// Remove the stylesheet that was added through jQuery.
|
28 |
if ($('head link#sweaver-palette').length > 0) { |
29 |
$('head link#sweaver-palette').remove(); |
30 |
} |
31 |
|
32 |
if ($this.hasClass('active')) { |
33 |
// Remove the active class.
|
34 |
$this.removeClass('active'); |
35 |
|
36 |
// Reset the active palette.
|
37 |
$('#sweaver_plugin_palettes [name=sweaver_plugin_palette]').val(''); |
38 |
} |
39 |
else {
|
40 |
// Add a external stylesheet container in the head section.
|
41 |
var link = '<link id="sweaver-palette" href="' + $('.file', this).text() + '" media="all" rel="stylesheet" />'; |
42 |
$('head').append(link); |
43 |
|
44 |
// Remove the active classes.
|
45 |
$('#sweaver_plugin_palettes .active').removeClass('active'); |
46 |
|
47 |
// Add an active class.
|
48 |
$this.addClass('active'); |
49 |
|
50 |
// Set the active palette.
|
51 |
$('#sweaver_plugin_palettes [name=sweaver_plugin_palette]').val($this.children('.key').text()); |
52 |
} |
53 |
}); |
54 |
}); |
55 |
|
56 |
})(jQuery); |