Move calendar/event stylesheets/scripts registration to modules

- Add media parameter to Page->registerStylesheet
- Fixes CSS precedence with custom theme stylesheet
This commit is contained in:
Hypolite Petovan 2020-08-15 18:56:17 -04:00
parent 4b15b9fe56
commit 2e286d6a57
7 changed files with 20 additions and 21 deletions

View file

@ -105,6 +105,11 @@ function cal_content(App $a)
// get the translation strings for the callendar // get the translation strings for the callendar
$i18n = Event::getStrings(); $i18n = Event::getStrings();
DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
DI::page()->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
DI::page()->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
$htpl = Renderer::getMarkupTemplate('event_head.tpl'); $htpl = Renderer::getMarkupTemplate('event_head.tpl');
DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [ DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [
'$module_url' => '/cal/' . $a->data['user']['nickname'], '$module_url' => '/cal/' . $a->data['user']['nickname'],

View file

@ -256,6 +256,11 @@ function events_content(App $a)
// get the translation strings for the callendar // get the translation strings for the callendar
$i18n = Event::getStrings(); $i18n = Event::getStrings();
DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.min.css');
DI::page()->registerStylesheet('view/asset/fullcalendar/dist/fullcalendar.print.min.css', 'print');
DI::page()->registerFooterScript('view/asset/moment/min/moment-with-locales.min.js');
DI::page()->registerFooterScript('view/asset/fullcalendar/dist/fullcalendar.min.js');
$htpl = Renderer::getMarkupTemplate('event_head.tpl'); $htpl = Renderer::getMarkupTemplate('event_head.tpl');
DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [ DI::page()['htmlhead'] .= Renderer::replaceMacros($htpl, [
'$module_url' => '/events', '$module_url' => '/events',

View file

@ -165,11 +165,10 @@ class Page implements ArrayAccess
* The path can be absolute or relative to the Friendica installation base folder. * The path can be absolute or relative to the Friendica installation base folder.
* *
* @param string $path * @param string $path
* * @param string $media
* @see Page::initHead() * @see Page::initHead()
*
*/ */
public function registerStylesheet($path) public function registerStylesheet($path, string $media = 'screen')
{ {
$path = Network::appendQueryParam($path, ['v' => FRIENDICA_VERSION]); $path = Network::appendQueryParam($path, ['v' => FRIENDICA_VERSION]);
@ -177,7 +176,7 @@ class Page implements ArrayAccess
$path = mb_substr($path, mb_strlen($this->basePath . DIRECTORY_SEPARATOR)); $path = mb_substr($path, mb_strlen($this->basePath . DIRECTORY_SEPARATOR));
} }
$this->stylesheets[] = trim($path, '/'); $this->stylesheets[trim($path, '/')] = $media;
} }
/** /**
@ -252,7 +251,7 @@ class Page implements ArrayAccess
'$shortcut_icon' => $shortcut_icon, '$shortcut_icon' => $shortcut_icon,
'$touch_icon' => $touch_icon, '$touch_icon' => $touch_icon,
'$block_public' => intval($config->get('system', 'block_public')), '$block_public' => intval($config->get('system', 'block_public')),
'$stylesheets' => array_unique($this->stylesheets), '$stylesheets' => $this->stylesheets,
]) . $this->page['htmlhead']; ]) . $this->page['htmlhead'];
} }

View file

@ -1,9 +1,3 @@
<link rel="stylesheet" type="text/css" href="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" />
<link rel="stylesheet" type="text/css" href="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.print.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" media="print" />
<script type="text/javascript" src="{{$baseurl}}/view/asset/moment/min/moment-with-locales.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript" src="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script> <script>
function showEvent(eventid) { function showEvent(eventid) {
$.get( $.get(

View file

@ -8,8 +8,8 @@
<link rel="stylesheet" href="view/asset/jquery-datetimepicker/build/jquery.datetimepicker.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen" /> <link rel="stylesheet" href="view/asset/jquery-datetimepicker/build/jquery.datetimepicker.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen" />
<link rel="stylesheet" href="view/asset/perfect-scrollbar/dist/css/perfect-scrollbar.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen" /> <link rel="stylesheet" href="view/asset/perfect-scrollbar/dist/css/perfect-scrollbar.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen" />
{{foreach $stylesheets as $stylesheetUrl}} {{foreach $stylesheets as $stylesheetUrl => $media}}
<link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="screen" /> <link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="{{$media}}" />
{{/foreach}} {{/foreach}}
<link rel="shortcut icon" href="{{$shortcut_icon}}" /> <link rel="shortcut icon" href="{{$shortcut_icon}}" />

View file

@ -1,9 +1,5 @@
<link rel="stylesheet" type="text/css" href="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" />
<link rel="stylesheet" type="text/css" href="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.print.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" media="print" />
<link rel="stylesheet" type="text/css" href="view/theme/frio/css/mod_events.css?v={{$smarty.const.FRIENDICA_VERSION}}" /> <link rel="stylesheet" type="text/css" href="view/theme/frio/css/mod_events.css?v={{$smarty.const.FRIENDICA_VERSION}}" />
<script type="text/javascript" src="{{$baseurl}}/view/asset/moment/min/moment-with-locales.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript" src="{{$baseurl}}/view/asset/fullcalendar/dist/fullcalendar.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript" src="view/theme/frio/js/mod_events.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <script type="text/javascript" src="view/theme/frio/js/mod_events.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript"> <script type="text/javascript">

View file

@ -25,14 +25,14 @@
<link rel="stylesheet" href="view/theme/frio/frameworks/bootstrap-toggle/css/bootstrap-toggle.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/> <link rel="stylesheet" href="view/theme/frio/frameworks/bootstrap-toggle/css/bootstrap-toggle.min.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
<link rel="stylesheet" href="view/theme/frio/font/open_sans/open-sans.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/> <link rel="stylesheet" href="view/theme/frio/font/open_sans/open-sans.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
{{foreach $stylesheets as $stylesheetUrl}}
<link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="screen" />
{{/foreach}}
{{* own css files *}} {{* own css files *}}
<link rel="stylesheet" href="view/theme/frio/css/hovercard.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/> <link rel="stylesheet" href="view/theme/frio/css/hovercard.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
<link rel="stylesheet" href="view/theme/frio/css/font-awesome.custom.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/> <link rel="stylesheet" href="view/theme/frio/css/font-awesome.custom.css?v={{$smarty.const.FRIENDICA_VERSION}}" type="text/css" media="screen"/>
{{foreach $stylesheets as $stylesheetUrl => $media}}
<link rel="stylesheet" href="{{$stylesheetUrl}}" type="text/css" media="{{$media}}" />
{{/foreach}}
<link rel="shortcut icon" href="{{$shortcut_icon}}" /> <link rel="shortcut icon" href="{{$shortcut_icon}}" />
<link rel="apple-touch-icon" href="{{$touch_icon}}"/> <link rel="apple-touch-icon" href="{{$touch_icon}}"/>