var city_is_visible = (document.currentScript.getAttribute('is-visible') == "true");
if (city_is_visible)
{
var lang = document.currentScript.getAttribute('lang');
if (lang == "zh-cn")
lang = "zh";
const city_id = document.currentScript.getAttribute('city-id');
var city_version = document.currentScript.getAttribute('version');
if ((!city_version) ||
(city_version == ""))
{
city_version = 1;
}
const callback = document.currentScript.getAttribute('callback');
const parent_element_class = document.currentScript.getAttribute('parent-element-class');
const callback_exists = (callback) && (typeof window[callback] === "function");
const parent_element_class_exists = (parent_element_class);
function ResizeElement(element)
{
$(element).show();
}
if ((callback_exists) ||
(parent_element_class_exists))
{
const page_from = document.currentScript.getAttribute('page-from');
$.ajax({
type: "POST",
url: "/city_widget.php",
data: {"city_id": city_id, "page_from": page_from, "lang": lang, "version": city_version},
success: function (response)
{
if ((response) &&
(response != ""))
{
var server_answer = JSON.parse(response);
if (server_answer.status == "ok")
{
if (parent_element_class_exists)
{
$("." + parent_element_class).each(function ()
{
$(this).html(server_answer.html);
ResizeElement(this);
});
}
if (callback_exists) {
window[callback](server_answer);
}
}
}
},
error: function (thrownError)
{
// do nothing
}
});
}
}