Created
June 25, 2013 21:18
-
-
Save Kolesias123/5862495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UploadPhoto: function(photo) | |
{ | |
// No hay nada definido. | |
if ( photo == undefined ) | |
return; | |
// Leemos la foto y ponemos en la vista previa. | |
Photos.Read(photo, '#status-photo img'); | |
photo = Photos.Data(photo); | |
// Actualizamos la información acerca de la foto. | |
$('#status-photo .fileName').html(photo.name); | |
$('#status-photo').fadeIn('slow'); | |
$('#status-box .actions [data-status-action="photo"]').addClass('used'); | |
// Estamos esperando la subida de una foto... | |
PhotoID = true; | |
$('#submit-status').html('Esperando la subida de la foto...'); | |
// Creamos un formulario. | |
var FD = new FormData(); | |
FD.append('photo', photo); | |
// Cargamos la foto y obtenemos su ID. | |
$.ajax({ | |
url: Path + '/actions/ajax/post.photo.php', | |
type: 'POST', | |
data: FD, | |
cache: false, | |
processData: false, | |
contentType: false, | |
xhr: function() | |
{ | |
var XHR = jQuery.ajaxSettings.xhr(); | |
if ( XHR.upload ) | |
{ | |
// Evento: Progreso de subida. | |
XHR.upload.addEventListener('progress', function(e) | |
{ | |
// No es posible calcular el progreso de subida, ocultar la barra de progreso y mostrar un mensaje. | |
if ( !e.lengthComputable ) | |
{ | |
$('#status-photo .fileProgress').html('Subiendo...'); | |
XHR.upload.onprogress = null; | |
} | |
var Loaded = e.position || e.loaded; // Lo que se ha subido. | |
var Total = e.totalSize || e.total; // El total. | |
// Este navegador o el hosting no son compatibles... | |
if ( Total == 0 || Total == undefined ) | |
return console.error('[UPLOAD] Ha ocurrido un error con el progreso.'); | |
// Calculamos el porcentaje de subida. | |
var Progress = 100 / intval(Total) * intval(Loaded); | |
Progress = round(Progress); | |
if ( Progress == 100 ) | |
$('#status-photo .fileProgress').html('Un momento...'); | |
else | |
$('#status-photo .fileProgress').html(Progress + '%'); | |
}, false); | |
} | |
return XHR; | |
}, | |
success: function(result) | |
{ | |
result = Json.Parse(result); | |
// La subida ha sido éxitosa. | |
if ( result.code == 'OK' ) | |
{ | |
$('#status-photo .fileProgress').html('Subida completada.'); | |
$('#submit-status').html('Publicar'); | |
// Establecemos la ID de la foto. | |
PhotoID = result.photo; | |
} | |
// Un error, mostrarlo. | |
else | |
Info.ShowMsg(result.error, 8000); | |
} | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment