wikipoints/public/js/app.js

107 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Приложение
*/
// ------------ Система статусов приложения ------------------------------------
var statusReady = 0; // Обычный режим. Просмотр точек, навигация по карте и прочее.
var statusHunting = 1; // Курсор-прицел. Поиск места для добавления точки.
var statusReHunting = 2; // КУрсор прицел. Переопределение координат точки.
var statusAdd = 3; // Открыто окно добавления точки - форма.
var statusEdit = 4; // Открыто окно редактирования точки. В нём информация о существующей точке, включая ID.
var statusSendingToServer = 5; // Отправлен запрос на сервер - ждём, не даём жать кнопку повторно, отвлекаем пользователя.
var status = statusReady;
var statusPrev = statusReady;
/**
* Устанавливает новое значение статуса.
* @returns {undefined}
*/
function setStatus(value)
{
statusPrev = status;
status = value;
}
/**
* Меняет значение статуса на предыдущее.
* @returns {undefined}
*/
function resetStatus()
{
tmp = status;
status = statusPrev;
statusPrev = tmp;
}
// -------------------------------- Libs ---------------------------------------
/**
* Возвращает GET параметр
* @param string name
* @returns string
*/
function getURLParameter(name) {
return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1]);
}
// ----------------- Работа с правым блоком (BOX) ------------------------------
function openBox(type, keepOpen)
{
newTab = $('#box'+type).css('display') == 'none';
keepOpen = keepOpen == true;
if (!newTab && !keepOpen)
{
return closeBox();
}
$('div','#control').removeClass('active');
$('#box').children('div').css('display', 'none');
$('.boxButton'+type).addClass('active');
$('#box'+type).css('display', 'block');
$('body').addClass('openBox');
}
function closeBox()
{
$('body').removeClass('openBox');
$('div','#control').removeClass('active');
$('#box').children('div').css('display', 'none');
return true;
}
function showImage(id)
{
point = pointsSources[id];
$('#imageModalLabel').text(point.name);
if (typeof(point.images) == 'object')
{
if( typeof($('.fotorama').data('fotorama')) != 'undefined' )
{
$('.fotorama').data('fotorama').destroy();
}
$('#imageModalImg').hide();
$('.fotorama').show();
photos = [];
point.images.forEach(function(entry) {
photos.push({img: '/photos/middle/'+entry, thumb: '/photos/small/'+entry});
});
$('.fotorama').fotorama({data: photos});
} else
{
$('#imageModalImg').show();
$('.fotorama').hide();
$('#imageModalImg').attr('src', point.img);
}
$('#imageModal').modal('show');
}