Merge pull request #6722 from JeroenED/task/share-color-schemes

Sharing color schemes
This commit is contained in:
Hypolite Petovan 2019-02-22 12:50:40 -05:00 committed by GitHub
commit 21ecb7688b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 123 additions and 1 deletions

View file

@ -57,6 +57,7 @@ function theme_content(App $a)
$arr = [];
$arr['scheme'] = PConfig::get(local_user(), 'frio', 'scheme', PConfig::get(local_user(), 'frio', 'schema'));
$arr['share_string'] = '';
$arr['nav_bg'] = PConfig::get(local_user(), 'frio', 'nav_bg');
$arr['nav_icon_color'] = PConfig::get(local_user(), 'frio', 'nav_icon_color');
$arr['link_color'] = PConfig::get(local_user(), 'frio', 'link_color');
@ -76,6 +77,7 @@ function theme_admin(App $a)
$arr = [];
$arr['scheme'] = Config::get('frio', 'scheme', Config::get('frio', 'scheme'));
$arr['share_string'] = '';
$arr['nav_bg'] = Config::get('frio', 'nav_bg');
$arr['nav_icon_color'] = Config::get('frio', 'nav_icon_color');
$arr['link_color'] = Config::get('frio', 'link_color');
@ -120,6 +122,7 @@ function frio_form($arr)
'$baseurl' => System::baseUrl(),
'$title' => L10n::t('Theme settings'),
'$scheme' => ['frio_scheme', L10n::t('Select color scheme'), $arr['scheme'], '', $scheme_choices],
'$share_string' => ['frio_share_string', L10n::t('Copy or paste schemestring'), $arr['share_string'], L10n::t('You can copy this string to share your theme with others. Pasting here applies the schemestring'), false, false],
'$nav_bg' => array_key_exists('nav_bg', $disable) ? '' : ['frio_nav_bg', L10n::t('Navigation bar background color'), $arr['nav_bg'], '', false],
'$nav_icon_color' => array_key_exists('nav_icon_color', $disable) ? '' : ['frio_nav_icon_color', L10n::t('Navigation bar icon color '), $arr['nav_icon_color'], '', false],
'$link_color' => array_key_exists('link_color', $disable) ? '' : ['frio_link_color', L10n::t('Link color'), $arr['link_color'], '', false],

View file

@ -6,6 +6,7 @@
{{include file="field_select.tpl" field=$scheme}}
{{if $nav_bg}}{{include file="field_input.tpl" field=$share_string}}{{/if}}
{{if $nav_bg}}{{include file="field_colorinput.tpl" field=$nav_bg}}{{/if}}
{{if $nav_icon_color}}{{include file="field_colorinput.tpl" field=$nav_icon_color}}{{/if}}
{{if $link_color}}{{include file="field_colorinput.tpl" field=$link_color}}{{/if}}
@ -36,6 +37,124 @@
<script type="text/javascript">
$(document).ready(function() {
function GenerateShareString() {
var theme = {};
// Parse initial share_string
if ($("#id_frio_nav_bg").length) {
theme.nav_bg = $("#id_frio_nav_bg").val();
}
if ($("#id_frio_nav_icon_color").length) {
theme.nav_icon_color = $("#id_frio_nav_icon_color").val();
}
if ($("#id_frio_link_color").length) {
theme.link_color = $("#id_frio_link_color").val();
}
if ($("#id_frio_background_color").length) {
theme.background_color = $("#id_frio_background_color").val();
}
if ($("#id_frio_background_image").length) {
theme.background_image = $("#id_frio_background_image").val();
if (theme.background_image.length > 0) {
if ($("#id_frio_bg_image_option_stretch").is(":checked") == true) {
theme.background_image_option = "stretch";
}
if ($("#id_frio_bg_image_option_cover").is(":checked") == true) {
theme.background_image_option = "cover";
}
if ($("#id_frio_bg_image_option_contain").is(":checked") == true) {
theme.background_image_option = "contain";
}
if ($("#id_frio_bg_image_option_repeat").is(":checked") == true) {
theme.background_image_option = "repeat";
}
}
}
if ($("#frio_contentbg_transp").length) {
theme.contentbg_transp = $("#frio_contentbg_transp").val();
}
if ($("#id_frio_login_bg_image").length) {
theme.login_bg_image = $("#id_frio_login_bg_image").val();
}
if ($("#id_frio_login_bg_color").length) {
theme.login_bg_color = $("#id_frio_login_bg_color").val();
}
if (!($("#id_frio_share_string").is(":focus"))){
var share_string = JSON.stringify(theme);
$("#id_frio_share_string").val(share_string);
}
}
// interval because jquery.val does not trigger events
window.setInterval(GenerateShareString, 500);
GenerateShareString();
// Take advantage of the effects of previous comment
$(document).on("keyup", "#id_frio_share_string", function() {
theme = JSON.parse($("#id_frio_share_string").val());
if ($("#id_frio_nav_bg").length) {
$("#id_frio_nav_bg").val(theme.nav_bg);
}
if ($("#id_frio_nav_icon_color").length) {
$("#id_frio_nav_icon_color").val(theme.nav_icon_color);
}
if ($("#id_frio_link_color").length) {
$("#id_frio_link_color").val(theme.link_color);
}
if ($("#id_frio_background_color").length) {
$("#id_frio_background_color").val(theme.background_color);
}
if ($("#id_frio_background_image").length) {
$("#id_frio_background_image").val(theme.background_image);
var elText = theme.background_image;
if(elText.length !== 0) {
$("#frio_bg_image_options").show();
} else {
$("#frio_bg_image_options").hide();
}
switch (theme.background_image_option) {
case 'stretch':
$("#id_frio_bg_image_option_stretch").prop("checked", true);
break;
case 'cover':
$("#id_frio_bg_image_option_cover").prop("checked", true);
break;
case 'contain':
$("#id_frio_bg_image_option_contain").prop("checked", true);
break;
case 'repeat':
$("#id_frio_bg_image_option_repeat").prop("checked", true);
break;
}
}
if ($("#frio_contentbg_transp").length) {
$("#frio_contentbg_transp").val(theme.contentbg_transp);
}
if ($("#id_frio_login_bg_image").length) {
$("#id_frio_login_bg_image").val(theme.login_bg_image);
}
if ($("#id_frio_login_bg_color").length) {
$("#id_frio_login_bg_color").val(theme.login_bg_color);
}
});
// Create colorpickers
$("#frio_nav_bg, #frio_nav_icon_color, #frio_background_color, #frio_link_color, #frio_login_bg_color").colorpicker({format: 'hex', align: 'left'});
// show image options when user user starts to type the address of the image
@ -80,5 +199,5 @@
<div class="clearfix"></div>
<script type="text/javascript">
$(".inputRange").rangeinput();
$(".inputRange").rangeinput();
</script>