2019-10-25 09:15:16 +02:00
|
|
|
exports.build_realm_logo_widget = function (upload_function, is_night) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let logo_section_id = '#day-logo-section';
|
2019-10-25 09:15:16 +02:00
|
|
|
if (is_night) {
|
|
|
|
logo_section_id = '#night-logo-section';
|
|
|
|
}
|
2019-03-11 16:48:59 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const delete_button_elem = $(logo_section_id + " .realm-logo-delete-button");
|
|
|
|
const file_input_elem = $(logo_section_id + " .realm-logo-file-input");
|
|
|
|
const file_input_error_elem = $(logo_section_id + " .realm-logo-file-input-error");
|
|
|
|
const upload_button_elem = $(logo_section_id + " .realm-logo-upload-button");
|
2019-03-11 16:48:59 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const get_file_input = function () {
|
2019-10-25 09:15:16 +02:00
|
|
|
return file_input_elem.expectOne();
|
|
|
|
};
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
if (page_params.realm_logo_source === 'D') {
|
|
|
|
delete_button_elem.hide();
|
|
|
|
} else {
|
|
|
|
delete_button_elem.show();
|
|
|
|
}
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {night: JSON.stringify(is_night)};
|
2019-10-25 09:15:16 +02:00
|
|
|
delete_button_elem.on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
channel.del({
|
|
|
|
url: '/json/realm/logo',
|
|
|
|
data: data,
|
2018-08-16 01:26:55 +02:00
|
|
|
});
|
2019-10-25 09:15:16 +02:00
|
|
|
});
|
2018-08-16 01:26:55 +02:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
return upload_widget.build_direct_upload_widget(
|
|
|
|
get_file_input,
|
|
|
|
file_input_error_elem.expectOne(),
|
|
|
|
upload_button_elem.expectOne(),
|
|
|
|
upload_function,
|
|
|
|
page_params.max_logo_file_size
|
|
|
|
);
|
|
|
|
};
|
2019-01-27 08:25:10 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
function change_logo_delete_button(logo_source, logo_delete_button, file_input) {
|
|
|
|
if (logo_source === 'U') {
|
|
|
|
logo_delete_button.show();
|
|
|
|
} else {
|
|
|
|
logo_delete_button.hide();
|
|
|
|
// Need to clear input because of a small edge case
|
|
|
|
// where you try to upload the same image you just deleted.
|
|
|
|
file_input.val('');
|
2019-08-20 18:52:33 +02:00
|
|
|
}
|
2019-10-25 09:15:16 +02:00
|
|
|
}
|
2019-08-20 18:52:33 +02:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
exports.rerender = function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const file_input = $("#day-logo-section .realm-logo-file-input");
|
|
|
|
const night_file_input = $("#night-logo-section .realm-logo-file-input");
|
2019-10-25 09:15:16 +02:00
|
|
|
$("#day-logo-section .realm-logo-img").attr("src", page_params.realm_logo_url);
|
2019-02-21 02:55:48 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
if (page_params.realm_night_logo_source === 'D' &&
|
2019-02-21 02:55:48 +01:00
|
|
|
page_params.realm_logo_source !== 'D') {
|
2019-10-25 09:15:16 +02:00
|
|
|
// If no night mode logo is uploaded but a day mode one
|
|
|
|
// is, use the day mode one; this handles the common case
|
|
|
|
// of transparent background logos that look good on both
|
|
|
|
// night and day themes. See also similar code in admin.js.
|
2019-02-21 02:55:48 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
$("#night-logo-section .realm-logo-img").attr("src", page_params.realm_logo_url);
|
|
|
|
} else {
|
|
|
|
$("#night-logo-section .realm-logo-img").attr("src", page_params.realm_night_logo_url);
|
|
|
|
}
|
2019-02-21 02:55:48 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
if (page_params.night_mode && page_params.realm_night_logo_source !== 'D') {
|
|
|
|
$("#realm-logo").attr("src", page_params.realm_night_logo_url);
|
|
|
|
} else {
|
|
|
|
$("#realm-logo").attr("src", page_params.realm_logo_url);
|
|
|
|
}
|
2019-01-27 08:25:10 +01:00
|
|
|
|
2019-10-25 09:15:16 +02:00
|
|
|
change_logo_delete_button(page_params.realm_logo_source,
|
|
|
|
$("#day-logo-section .realm-logo-delete-button"),
|
|
|
|
file_input);
|
|
|
|
change_logo_delete_button(page_params.realm_night_logo_source,
|
|
|
|
$("#night-logo-section .realm-logo-delete-button"),
|
|
|
|
night_file_input);
|
|
|
|
};
|
2018-08-16 01:26:55 +02:00
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.realm_logo = exports;
|