render max_imagesize in header.tpl

so it is reachable general from the whole website, and the dropzone-factory can use
it also to create dropzones from modal.js
This commit is contained in:
Jakobus Schürz 2023-03-15 21:48:17 +01:00
parent 16f065e260
commit 920dcca263
13 changed files with 19 additions and 56 deletions

View file

@ -1139,8 +1139,6 @@ function photos_content(App $a)
'$loading' => DI::l10n()->t('Loading...'), '$loading' => DI::l10n()->t('Loading...'),
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1),
]); ]);
} }
} }
@ -1196,8 +1194,6 @@ function photos_content(App $a)
'$preview' => DI::l10n()->t('Preview'), '$preview' => DI::l10n()->t('Preview'),
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone
'$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1),
]); ]);
} }
@ -1272,8 +1268,6 @@ function photos_content(App $a)
'$preview' => DI::l10n()->t('Preview'), '$preview' => DI::l10n()->t('Preview'),
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone
'$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000, 1),
]); ]);
} }
} }

View file

@ -253,11 +253,15 @@ class Page implements ArrayAccess
'$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' => $this->stylesheets, '$stylesheets' => $this->stylesheets,
'$likeError' => $l10n->t('Like not successfull'), '$likeError' => $l10n->t('Like not successfull'),
'$dislikeError' => $l10n->t('Dislike not successfull'), '$dislikeError' => $l10n->t('Dislike not successfull'),
'$announceError' => $l10n->t('Sharing not successfull'), '$announceError' => $l10n->t('Sharing not successfull'),
'$srvError' => $l10n->t('Backend error'), '$srvError' => $l10n->t('Backend error'),
'$netError' => $l10n->t('Network error'), '$netError' => $l10n->t('Network error'),
// Dropzone
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($config->get('system', 'maximagesize')) / 1000000, 1),
]) . $this->page['htmlhead']; ]) . $this->page['htmlhead'];
} }

View file

@ -409,9 +409,6 @@ class Conversation
'$compose_link_title' => $this->l10n->t('Open Compose page'), '$compose_link_title' => $this->l10n->t('Open Compose page'),
'$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false), '$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
// Dropzone
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')) / 1000000, 1),
]); ]);

View file

@ -240,9 +240,6 @@ class Compose extends BaseModule
'deny_cid' => $contact_deny_list, 'deny_cid' => $contact_deny_list,
'deny_gid' => $group_deny_list, 'deny_gid' => $group_deny_list,
]), ]),
// Dropzone
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand($this->config->get('system', 'maximagesize')) / 1000000, 1),
]); ]);
} }
} }

View file

@ -185,8 +185,6 @@ class Edit extends BaseModule
'$compose_link_title' => $this->t('Open Compose page'), '$compose_link_title' => $this->t('Open Compose page'),
// Dropzone
'$max_imagesize' => round(Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000,1),
]); ]);
return $output; return $output;
} }

View file

@ -1069,8 +1069,6 @@ class Post
'$preview' => DI::l10n()->t('Preview'), '$preview' => DI::l10n()->t('Preview'),
'$indent' => $indent, '$indent' => $indent,
'$rand_num' => Crypto::randomDigits(12), '$rand_num' => Crypto::randomDigits(12),
// Dropzone
'$max_imagesize' => round(\Friendica\Util\Strings::getBytesFromShorthand(DI::config()->get('system', 'maximagesize')) / 1000000,1),
]); ]);
} }

View file

@ -1,8 +1,8 @@
var DzFactory = function () { var DzFactory = function () {
this.createDropzone = function(dropSelector, textareaSelector, maxImagesize) { this.createDropzone = function(dropSelector, textareaSelector) {
return new Dropzone( dropSelector, { return new Dropzone( dropSelector, {
paramName: 'userfile', // The name that will be used to transfer the file paramName: 'userfile', // The name that will be used to transfer the file
maxFilesize: maxImagesize, // MB maxFilesize: max_imagesize, // MB
url: '/media/photo/upload?response=url&album=', url: '/media/photo/upload?response=url&album=',
accept: function(file, done) { accept: function(file, done) {
done(); done();
@ -52,8 +52,8 @@ var DzFactory = function () {
}) })
}; };
this.setupDropzone = function(dropSelector, textareaSelector, maxImagesize) { this.setupDropzone = function(dropSelector, textareaSelector) {
var dropzone = this.createDropzone(dropSelector, textareaSelector, maxImagesize); var dropzone = this.createDropzone(dropSelector, textareaSelector);
$(dropSelector).on('paste', function(event) { $(dropSelector).on('paste', function(event) {
dzFactory.copyPaste(event, dropzone); dzFactory.copyPaste(event, dropzone);
}) })

View file

@ -96,5 +96,5 @@
</div> </div>
</div> </div>
<script> <script>
dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}');
</script> </script>

View file

@ -1,24 +0,0 @@
function isInteger(value) {
return /^\d+$/.test(value);
}
function getMBytes(value) {
var res;
if (isInteger(value)) {
res = value;
} else {
eh = value.slice(-1);
am = Number(value.slice(0, -1));
switch (eh) {
case 'k':
res = am * 1024;
break;
case 'm':
res = am * 1024 * 1024;
break;
case 'g':
res = am * 1024 * 1024 * 1024;
}
}
return res / 1000000;
}

View file

@ -293,8 +293,7 @@ function editpost(url) {
// To make dropzone fileupload work on editing a comment, we need to // To make dropzone fileupload work on editing a comment, we need to
// attach a new dropzone to modal // attach a new dropzone to modal
console.log("modal.js max_imagesize",'{{$max_imagesize}}'); dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text');
dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', '{{$max_imagesize}}');
modal.show(); modal.show();
$("#jot-popup").show(); $("#jot-popup").show();

View file

@ -67,12 +67,12 @@
<script> <script>
$('[id=comment-fake-text-{{$id}}]').on('focus', function() { $('[id=comment-fake-text-{{$id}}]').on('focus', function() {
dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}');
$('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus') $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
$('[id=comment-{{$id}}]').prop('click', null).off('click') $('[id=comment-{{$id}}]').prop('click', null).off('click')
}); });
$('[id=comment-{{$id}}]').on('click', function() { $('[id=comment-{{$id}}]').on('click', function() {
dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}', {{$max_imagesize}}); dzFactory.setupDropzone('#dropzone-{{$id}}', 'comment-edit-text-{{$id}}');
$('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus') $('[id=comment-fake-text-{{$id}}]').prop('focus', null).off('focus')
$('[id=comment-{{$id}}]').prop('click', null).off('click') $('[id=comment-{{$id}}]').prop('click', null).off('click')
}); });

View file

@ -141,7 +141,7 @@
<script type="text/javascript" src="view/theme/frio/js/textedit.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <script type="text/javascript" src="view/theme/frio/js/textedit.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript" src="vendor/enyo/dropzone/dist/min/dropzone.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <script type="text/javascript" src="vendor/enyo/dropzone/dist/min/dropzone.min.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript" src="view/js/dropzone-factory.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script> <script type="text/javascript" src="view/js/dropzone-factory.js?v={{$smarty.const.FRIENDICA_VERSION}}"></script>
<script type="text/javascript"> var dzFactory = new DzFactory(); Dropzone.autoDiscover = false;</script> <script type="text/javascript"> max_imagesize = {{$max_imagesize}}; var dzFactory = new DzFactory(); Dropzone.autoDiscover = false; </script>
{{* Include the strings which are needed for some js functions (e.g. translation) {{* Include the strings which are needed for some js functions (e.g. translation)
They are loaded into the html <head> so that js functions can use them *}} They are loaded into the html <head> so that js functions can use them *}}

View file

@ -180,5 +180,5 @@ can load different content into the jot modal (e.g. the item edit jot)
</script> </script>
<script> <script>
dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text', {{$max_imagesize}}); dzFactory.setupDropzone('#jot-text-wrap', 'profile-jot-text');
</script> </script>