Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*=============================================
- SUBIR LOGOTIPO
- =============================================*/
- $("#subirPopup").change(function(){
- var imagenPopup = this.files[0];
- /*=============================================
- VALIDAMOS EL FORMATO DE LA IMAGEN SEA JPG O PNG
- =============================================*/
- if(imagenPopup["type"] != "image/jpeg" && imagenPopup["type"] != "image/png"){
- $("#subirLogo").val("");
- swal({
- title: "Error al subir la imagen",
- text: "¡La imagen debe estar en formato JPG o PNG!",
- type: "error",
- confirmButtonText: "¡Cerrar!"
- });
- /*=============================================
- VALIDAMOS EL TAMAÑO DE LA IMAGEN
- =============================================*/
- }else if(imagenPopup["size"] > 2000000){
- $("#subirLogo").val("");
- swal({
- title: "Error al subir la imagen",
- text: "¡La imagen no debe pesar más de 2MB!",
- type: "error",
- confirmButtonText: "¡Cerrar!"
- });
- /*=============================================
- PREVISUALIZAMOS LA IMAGEN
- =============================================*/
- }else{
- var datosImagen = new FileReader;
- datosImagen.readAsDataURL(imagenPopup);
- $(datosImagen).on("load", function(event){
- var rutaImagen = event.target.result;
- $(".previsualizarPopup").attr("src", rutaImagen);
- })
- }
- /*=============================================
- GUARDAR EL LOGOTIPO
- =============================================*/
- $("#guardarPopup").click(function(){
- var tituloPopup = $("#tituloPopup").val();
- var textoBotonPopup = $("#textoBotonPopup").val();
- var rutaBotonPopup = $("#rutaBotonPopup").val();
- var datos = new FormData();
- datos.append("tituloPopup", tituloPopup);
- datos.append("textoBotonPopup", textoBotonPopup);
- datos.append("rutaBotonPopup", rutaBotonPopup);
- datos.append("imagenPopup", imagenPopup);
- $.ajax({
- url:"ajax/popup.ajax.php",
- method: "POST",
- data: datos,
- cache: false,
- contentType: false,
- processData: false,
- success: function(respuesta){
- if(respuesta == "ok"){
- console.log(respuesta);
- swal({
- title: "Cambios guardados",
- text: "¡La plantilla ha sido actualizada correctamente!",
- type: "success",
- confirmButtonText: "¡Cerrar!"
- });
- }
- }
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement