Просмотр файла siwap.ru/design/js/functions.js

Размер файла: 3.26Kb
function isEmpty(str) {
    return (!str || 0 === str.length);
}

function deletePhoto()
{
       
    $('.image-prev').on('click', function(e) {
        e.preventDefault();
        var data = $(this).attr('data-id');
        var element = $('#photo' + data);
        
        $.ajax({
            url: '/AJAX/deletePhoto.php',
            type: 'post',
            data: {id:data},
            dataType: 'json',
            success: function(json) {
                $('#alerts').show();
   
                if(json['error'] == 1) {
                    $('#alerts').html('<div class="alert alert-danger">'+json['comment']+'</div>');
                } else if(json['success'] == 1) {
                    $('#alerts').html('<div class="alert alert-success">'+json['comment']+'</div>');
                    $(element).remove();
                }
                setTimeout(function () {
                    $('#alerts').html('');
                }, 2000);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n " + xhr.responseText);
            }
        });
    });
}

function WaitForMsg()
{
    var elem = document.getElementById('response');
    $.ajax({
        
        type: 'GET',
        url: 'long.php?timestamp='+ timestap,
        async: true,
        cache: false,
        success: function(data){ 
            
            var json = eval('('+ data + ')');
            
                if (json["msg"]!="")
                {
                    elem.innerHTML = json["msg"];
                    //alert(json["msg"]);
                }
                
                timestap = json["timestamp"];
                
                setTimeout('WaitForMsg()',1000);
            
        },
        
        error: function(XMLHttpRequest, textStatus, errorThrown){
            
            // alert("Error: " + textStatus + "(" + errorThrown +")");
            
            setTimeout('WaitForMsg()',15000);
        }
        
    });
}

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#imgPreview').append('<img class="card-img mb-3" src="' + e.target.result + '" style="max-width: 48%;"/>');
        }
        reader.readAsDataURL(input.files[0]);
    }
}

function getTime(time)
{
	var result = false;
	
	if (time != 0 || time != '' || time != null || time != 'undenfined')
	{
		var date = new Date(time*1000);
		var todayDate = new Date();
		
		var day = date.getDate();
		var today = todayDate.getDate();
		var hours = date.getHours();
		var nowHours = todayDate.getHours();
		var minutes = date.getMinutes();
		var nowMinutes = todayDate.getMinutes();
		var seconds = date.getSeconds();
		var nowSeconds = todayDate.getSeconds();

		result = hours + ':' + minutes;
		
		if (day == today)
		{
			result = 'В ' + hours + ':' + minutes;
		}
		if (hours == nowHours)
		{
			result = minutes + ' минут назад';
		}
		if (minutes == nowMinutes)
		{
			result = seconds + ' секунд назад';
		}
		if (seconds == nowSeconds)
		{
			result = 'Только что';
		}
	}
	return result;
}