move mtt.js options to php js_options()

This commit is contained in:
Max Pozdeev 2021-04-21 15:03:26 +03:00
parent 85e03c42f1
commit ae22d091bf
5 changed files with 34 additions and 16 deletions

View file

@ -23,20 +23,7 @@
<script type="text/javascript">
$().ready(function(){
mytinytodo.init({
title: "<?php mttinfo('title', false); ?>",
lang: <?php echo Lang::instance()->makeJS() ?>,
mttUrl: "<?php mttinfo('mtt_url'); ?>",
homeUrl: "<?php mttinfo('url'); ?>",
db: mytinytodoStorageAjax,
needAuth: <?php echo need_auth() ? "true" : "false"; ?>,
isLogged: <?php echo is_logged() ? "true" : "false"; ?>,
showdate: <?php echo Config::get('showdate') ? "true" : "false"; ?>,
duedatepickerformat: "<?php echo htmlspecialchars(Config::get('dateformat2')); ?>",
firstdayofweek: <?php echo (int) Config::get('firstdayofweek'); ?>,
calendarIcon: '<?php mttinfo('template_url'); ?>images/calendar.svg',
autotag: <?php echo Config::get('autotag') ? "true" : "false"; ?>
}).run();
mytinytodo.setApi(mytinytodoStorageAjax).init(<?php js_options(); ?>).run();
});
</script>

View file

@ -90,7 +90,8 @@ class Lang
return 0;
}
function makeJS($pretty = 0)
/* minimal number of translated strings to use in js front-end */
function jsStrings()
{
$a = array();
$a['daysMin'] = $this->get('days_min');
@ -121,6 +122,12 @@ class Lang
]);
$a['_rtl'] = $this->rtl() ? 1 : 0;
return $a;
}
function makeJS($pretty = 0)
{
$a = $this->jsStrings();
$opts = JSON_UNESCAPED_UNICODE;
if ($pretty) {
$opts |= JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;

View file

@ -107,6 +107,12 @@ var mytinytodo = window.mytinytodo = _mtt = {
flag: flag,
// procs
setApi: function(storage)
{
this.db = new storage(this);
return this;
},
init: function(options)
{
// required properties

View file

@ -47,3 +47,22 @@ function redirectWithHashRoute(array $q, array $hash)
header("Location: ". $url);
exit;
}
function js_options()
{
$a = array(
"title" => get_mttinfo('title', false),
"lang" => Lang::instance()->jsStrings(),
"mttUrl" => get_mttinfo('mtt_url'),
"homeUrl" => get_mttinfo('url'),
"needAuth" => need_auth() ? true : false,
"isLogged" => is_logged() ? true : false,
"showdate" => Config::get('showdate') ? true : false,
"duedatepickerformat" => htmlspecialchars(Config::get('dateformat2')),
"firstdayofweek" => (int) Config::get('firstdayofweek'),
"calendarIcon" => get_mttinfo('template_url'). 'images/calendar.svg',
"autotag" => Config::get('autotag') ? true : false,
"markdown" => Config::get('markup') == 'v1' ? false : true
);
echo json_encode($a, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

View file

@ -143,7 +143,6 @@ function __($s)
function mttinfo($v, $escape = true)
{
global $_mttinfo;
echo $escape ? get_mttinfo($v) : get_unsafe_mttinfo($v);
}