2018-08-16 01:26:55 +02:00
|
|
|
/* eslint indent: "off" */
|
|
|
|
var realm_logo = (function () {
|
|
|
|
var exports = {};
|
2019-02-27 15:45:26 +01:00
|
|
|
|
|
|
|
function build_realm_logo_widget(args) {
|
2018-08-16 01:26:55 +02:00
|
|
|
var get_file_input = function () {
|
2019-02-27 15:45:26 +01:00
|
|
|
return args.file_input_elem.expectOne();
|
2018-08-16 01:26:55 +02:00
|
|
|
};
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
if (page_params.realm_logo_source === 'D') {
|
2019-02-27 15:45:26 +01:00
|
|
|
args.delete_button_elem.hide();
|
2018-08-16 01:26:55 +02:00
|
|
|
} else {
|
2019-02-27 15:45:26 +01:00
|
|
|
args.delete_button_elem.show();
|
2018-08-16 01:26:55 +02:00
|
|
|
}
|
2019-02-27 15:45:26 +01:00
|
|
|
|
|
|
|
var data = {night: JSON.stringify(args.is_night_mode)};
|
|
|
|
args.delete_button_elem.on('click', function (e) {
|
2018-08-16 01:26:55 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
channel.del({
|
|
|
|
url: '/json/realm/logo',
|
2019-01-27 08:25:10 +01:00
|
|
|
data: data,
|
2018-08-16 01:26:55 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return upload_widget.build_direct_upload_widget(
|
|
|
|
get_file_input,
|
2019-02-27 15:45:26 +01:00
|
|
|
args.file_input_error_elem.expectOne(),
|
|
|
|
args.upload_button_elem.expectOne(),
|
|
|
|
args.upload_function,
|
2018-08-16 01:26:55 +02:00
|
|
|
page_params.max_logo_file_size
|
|
|
|
);
|
2019-02-27 15:45:26 +01:00
|
|
|
}
|
2018-08-16 01:26:55 +02:00
|
|
|
|
2019-02-27 15:45:26 +01:00
|
|
|
exports.build_realm_day_mode_logo_widget = function (upload_function) {
|
|
|
|
var args = {
|
|
|
|
delete_button_elem: $("#realm_logo_delete_button"),
|
|
|
|
file_input_elem: $('#realm_logo_file_input'),
|
|
|
|
file_input_error_elem: $("#realm_logo_file_input_error"),
|
|
|
|
is_night_mode: false,
|
|
|
|
upload_button_elem: $("#realm_logo_upload_button"),
|
|
|
|
upload_function: upload_function,
|
2019-01-27 08:25:10 +01:00
|
|
|
};
|
2019-02-27 15:45:26 +01:00
|
|
|
return build_realm_logo_widget(args);
|
|
|
|
};
|
2019-01-27 08:25:10 +01:00
|
|
|
|
2019-02-27 15:45:26 +01:00
|
|
|
exports.build_realm_night_mode_logo_widget = function (upload_function) {
|
|
|
|
var args = {
|
|
|
|
delete_button_elem: $("#realm_night_logo_delete_button"),
|
|
|
|
file_input_elem: $('#realm_night_logo_file_input'),
|
|
|
|
file_input_error_elem: $("#realm_night_logo_file_input_error"),
|
|
|
|
is_night_mode: true,
|
|
|
|
upload_button_elem: $("#realm_night_logo_upload_button"),
|
|
|
|
upload_function: upload_function,
|
|
|
|
};
|
|
|
|
return build_realm_logo_widget(args);
|
2019-01-27 08:25:10 +01:00
|
|
|
};
|
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
exports.rerender = function () {
|
2019-01-27 08:25:10 +01:00
|
|
|
var file_input = $("#realm_logo_file_input");
|
|
|
|
var night_file_input = $("#realm_night_logo_file_input");
|
2018-08-16 01:26:55 +02:00
|
|
|
$("#realm-settings-logo").attr("src", page_params.realm_logo_url);
|
2019-02-21 02:55:48 +01:00
|
|
|
|
|
|
|
if (page_params.realm_night_logo_source === 'D' &&
|
|
|
|
page_params.realm_logo_source !== 'D') {
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
$("#realm-settings-night-logo").attr("src", page_params.realm_logo_url);
|
|
|
|
} else {
|
|
|
|
$("#realm-settings-night-logo").attr("src", page_params.realm_night_logo_url);
|
|
|
|
}
|
|
|
|
|
2019-03-02 18:23:57 +01:00
|
|
|
if (page_params.night_mode && page_params.realm_night_logo_source !== 'D') {
|
2019-01-27 08:25:10 +01:00
|
|
|
$("#realm-logo").attr("src", page_params.realm_night_logo_url);
|
|
|
|
} else {
|
|
|
|
$("#realm-logo").attr("src", page_params.realm_logo_url);
|
|
|
|
}
|
2018-08-16 01:26:55 +02:00
|
|
|
if (page_params.realm_logo_source === 'U') {
|
|
|
|
$("#realm_logo_delete_button").show();
|
|
|
|
} else {
|
|
|
|
$("#realm_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-01-27 08:25:10 +01:00
|
|
|
if (page_params.realm_night_logo_source === 'U') {
|
|
|
|
$("#realm_night_logo_delete_button").show();
|
|
|
|
} else {
|
|
|
|
$("#realm_night_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.
|
|
|
|
night_file_input.val('');
|
|
|
|
}
|
|
|
|
|
2018-08-16 01:26:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = realm_logo;
|
|
|
|
}
|
|
|
|
window.realm_logo = realm_logo;
|