Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. /*=============================================
  2. SUBIR LOGOTIPO
  3. =============================================*/
  4.  
  5. $("#subirPopup").change(function(){
  6.  
  7. var imagenPopup = this.files[0];
  8.  
  9. /*=============================================
  10. VALIDAMOS EL FORMATO DE LA IMAGEN SEA JPG O PNG
  11. =============================================*/
  12.  
  13. if(imagenPopup["type"] != "image/jpeg" && imagenPopup["type"] != "image/png"){
  14.  
  15. $("#subirLogo").val("");
  16.  
  17. swal({
  18. title: "Error al subir la imagen",
  19. text: "¡La imagen debe estar en formato JPG o PNG!",
  20. type: "error",
  21. confirmButtonText: "¡Cerrar!"
  22. });
  23.  
  24. /*=============================================
  25. VALIDAMOS EL TAMAÑO DE LA IMAGEN
  26. =============================================*/
  27.  
  28. }else if(imagenPopup["size"] > 2000000){
  29.  
  30. $("#subirLogo").val("");
  31.  
  32. swal({
  33. title: "Error al subir la imagen",
  34. text: "¡La imagen no debe pesar más de 2MB!",
  35. type: "error",
  36. confirmButtonText: "¡Cerrar!"
  37. });
  38.  
  39. /*=============================================
  40. PREVISUALIZAMOS LA IMAGEN
  41. =============================================*/
  42.  
  43. }else{
  44.  
  45. var datosImagen = new FileReader;
  46. datosImagen.readAsDataURL(imagenPopup);
  47.  
  48. $(datosImagen).on("load", function(event){
  49.  
  50. var rutaImagen = event.target.result;
  51.  
  52. $(".previsualizarPopup").attr("src", rutaImagen);
  53.  
  54. })
  55.  
  56. }
  57.  
  58. /*=============================================
  59. GUARDAR EL LOGOTIPO
  60. =============================================*/
  61.  
  62. $("#guardarPopup").click(function(){
  63.  
  64. var tituloPopup = $("#tituloPopup").val();
  65.  
  66. var textoBotonPopup = $("#textoBotonPopup").val();
  67.  
  68. var rutaBotonPopup = $("#rutaBotonPopup").val();
  69.  
  70. var datos = new FormData();
  71. datos.append("tituloPopup", tituloPopup);
  72. datos.append("textoBotonPopup", textoBotonPopup);
  73. datos.append("rutaBotonPopup", rutaBotonPopup);
  74. datos.append("imagenPopup", imagenPopup);
  75.  
  76. $.ajax({
  77.  
  78. url:"ajax/popup.ajax.php",
  79. method: "POST",
  80. data: datos,
  81. cache: false,
  82. contentType: false,
  83. processData: false,
  84. success: function(respuesta){
  85.  
  86. if(respuesta == "ok"){
  87.  
  88. console.log(respuesta);
  89.  
  90. swal({
  91. title: "Cambios guardados",
  92. text: "¡La plantilla ha sido actualizada correctamente!",
  93. type: "success",
  94. confirmButtonText: "¡Cerrar!"
  95. });
  96.  
  97. }
  98.  
  99.  
  100. }
  101.  
  102. })
  103.  
  104.  
  105. })
  106.  
  107. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement