Issue #1625 body class definition in section init

Initialize body_classes in common.inc.php
Add class for section and section id
also add class with search id
Class is added to $page in section_init now
Also add tis info to the body dataset for javascript use
This commit is contained in:
HWFord 2022-04-07 14:30:47 +02:00
parent 91c965e75e
commit 722c26a1b3
6 changed files with 43 additions and 31 deletions

View file

@ -51,6 +51,7 @@ $page = array(
'errors' => array(), 'errors' => array(),
'warnings' => array(), 'warnings' => array(),
'messages' => array(), 'messages' => array(),
'body_classes' => array(),
); );
$user = array(); $user = array();
$lang = array(); $lang = array();

View file

@ -48,10 +48,11 @@ $template->assign(
'SHOW_MOBILE_APP_BANNER' => $show_mobile_app_banner, 'SHOW_MOBILE_APP_BANNER' => $show_mobile_app_banner,
'BODY_CLASS' => 'BODY_CLASSES' => $page['body_classes'],
isset($page['body_class']) ?
$page['body_class'] : '', 'BODY_DATA' => json_encode($page['body_classes']),
)); )
);
// Header notes // Header notes

View file

@ -647,6 +647,42 @@ if ( 'categories'==$page['section'] and isset($page['category']) and !isset($pag
} }
unset( $need_redirect, $page['hit_by'] ); unset( $need_redirect, $page['hit_by'] );
} }
echo('<pre>');print_r($page);echo('</pre>');
array_push($page['body_classes'], 'section-'.$page['section']);
if ('categories' == $page['section'] && isset($page['category']))
{
$body_class = 'category-'.$page['category']['id'];
if (isset($page['combined_categories']))
{
foreach ($page['combined_categories'] as $combined_categories)
{
$body_class .= '-'.$combined_categories['id'];
}
}
array_push($page['body_classes'], $body_class);
}
elseif (isset($page['tags']))
{
$body_class = 'tag';
foreach ($page['tags'] as $tag)
{
$body_class .= '-'.$tag['id'];
}
array_push($page['body_classes'], $body_class);
}
elseif (isset($page['search']))
{
array_push($page['body_classes'], 'search-'.$page['search']);
}
if (isset($page['image_id']))
{
array_push($page['body_classes'], 'image-'.$page['image_id']);
}
trigger_notify('loc_end_section_init'); trigger_notify('loc_end_section_init');
?> ?>

View file

@ -112,26 +112,6 @@ if ( empty($page['is_external']) )
//----------------------------------------------------- template initialization //----------------------------------------------------- template initialization
$page['body_id'] = 'theCategoryPage'; $page['body_id'] = 'theCategoryPage';
if ('categories' == $page['section'] && isset($page['category']))
{
$page['body_class'] = 'category_'.$page['category']['id'];
if (isset($page['combined_categories']))
{
foreach ($page['combined_categories'] as $combined_categories)
{
$page['body_class'] .= '_'.$combined_categories['id'];
}
}
}
elseif (isset($page['tags']))
{
$page['body_class'] = 'tag';
foreach ($page['tags'] as $tag)
{
$page['body_class'] .= '_'.$tag['id'];
}
}
if (isset($page['flat']) or isset($page['chronology_field'])) if (isset($page['flat']) or isset($page['chronology_field']))
{ {
$template->assign( $template->assign(

View file

@ -627,12 +627,6 @@ if ( $metadata_showable and pwg_get_session_var('show_metadata') )
$page['body_id'] = 'thePicturePage'; $page['body_id'] = 'thePicturePage';
if (isset($page['image_id']))
{
$page['body_class'] = 'image_'.$page['image_id'];
}
// allow plugins to change what we computed before passing data to template // allow plugins to change what we computed before passing data to template
$picture = trigger_change('picture_pictures_data', $picture); $picture = trigger_change('picture_pictures_data', $picture);

View file

@ -68,7 +68,7 @@
{/if} {/if}
</head> </head>
<body id="{$BODY_ID}" class="{$BODY_CLASS}"> <body id="{$BODY_ID}" class="{foreach from=$BODY_CLASSES item=class}{$class} {/foreach}" data-infos={$BODY_DATA}>
<div id="the_page"> <div id="the_page">