Initial commit: Proyecto Portal ePromos completo con documentación unificada y seguridad base
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Rasca y Gana (premios separados)
|
||||
// Requiere: window.RASCA_BOOT, jQuery 2.x y rasca_wScratchpad.min.js
|
||||
(function ($) {
|
||||
"use strict";
|
||||
const BOOT = window.RASCA_BOOT || { rascaId: "1", api:{config:"/api/rasca_config.php?rasca_id=1", premio:"/api/rasca_premio.php"} };
|
||||
let CFG = null;
|
||||
let confirmado = false, enviado = false, scratchInit = false;
|
||||
|
||||
function setBanner(id, url){
|
||||
const el = document.getElementById(id);
|
||||
if(!el) return;
|
||||
if(url){ el.style.backgroundImage = "url('"+url+"')"; el.style.display='block'; }
|
||||
else el.style.display='none';
|
||||
}
|
||||
function aplicarVisual(cfg){
|
||||
if(cfg.background_image){ document.body.style.backgroundImage = "url('"+cfg.background_image+"')"; }
|
||||
setBanner("banner-1", cfg.banner_1 || "img/BANNER-1.png");
|
||||
setBanner("banner-2", cfg.banner_2 || "img/BANNER-2.png");
|
||||
setBanner("banner-3", cfg.banner_3 || "img/BANNER-3.png");
|
||||
setBanner("banner-4", cfg.banner_4 || "img/BANNER-4.png");
|
||||
if(cfg.fullscreen_icon && document.getElementById('fullscreen-icon')){
|
||||
document.getElementById('fullscreen-icon').src = cfg.fullscreen_icon;
|
||||
}
|
||||
}
|
||||
function toggleFullScreen(){
|
||||
if(!document.fullscreenElement){ document.documentElement.requestFullscreen().catch(()=>{}); }
|
||||
else { document.exitFullscreen().catch(()=>{}); }
|
||||
}
|
||||
function initScratch(){
|
||||
if(scratchInit) return; scratchInit = true;
|
||||
const bg = (CFG && CFG.bg_image) || "img/ruleta.png"; // fallback
|
||||
const fg = (CFG && CFG.fg_image) || "img/puntero.png"; // fallback (capa raspable)
|
||||
|
||||
$("#card").wScratchPad({
|
||||
size: 80, bg: bg, fg: fg, cursor: "pointer",
|
||||
scratchMove: function(e, percent){
|
||||
if(!confirmado){
|
||||
if(!window.confirm("¿Deseas participar en la promoción?")) return;
|
||||
confirmado = true;
|
||||
}
|
||||
if(percent > 0 && !enviado){
|
||||
enviado = true;
|
||||
$("#card").wScratchPad("clear");
|
||||
$.ajax({
|
||||
url: BOOT.api.premio, method: "POST",
|
||||
contentType: "application/json; charset=utf-8", dataType: "json",
|
||||
data: JSON.stringify({rasca_id: parseInt(BOOT.rascaId,10), percent: Math.round(percent)})
|
||||
})
|
||||
.done(function(res){
|
||||
if(res && res.ok){
|
||||
if(res.sin_premio){ $("#premio").text("Gracias por participar."); return; }
|
||||
//$("#premio").text(res.premio ? ("¡Felicidades! " + res.premio) : "¡Felicidades!");
|
||||
if(res.imagen_url){ $("#card").wScratchPad("bg", res.imagen_url); }
|
||||
else if (CFG && CFG.bg_image){ $("#card").wScratchPad("bg", CFG.bg_image); }
|
||||
}else{
|
||||
$("#premio").text(res && res.error ? res.error : "No se pudo completar la jugada."); enviado = false;
|
||||
}
|
||||
})
|
||||
.fail(function(){ $("#premio").text("Error de red. Intenta nuevamente."); enviado = false; });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function cargarConfig(){
|
||||
$.ajax({ url: BOOT.api.config, method: "GET", dataType: "json" })
|
||||
.done(function(cfg){ CFG = cfg || {}; aplicarVisual(CFG); initScratch(); })
|
||||
.fail(function(){ CFG = {}; initScratch(); });
|
||||
}
|
||||
$(function(){ $("#fullscreen-btn").on("click", toggleFullScreen); cargarConfig(); });
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user