Mudanças entre as edições de "Widget:Teste"

De Wiki Gla
Ir para navegação Ir para pesquisar
m
 
(333 revisões intermediárias por 2 usuários não estão sendo mostradas)
Linha 1: Linha 1:
<div class="home-button-container">
<noinclude>
   <!-- Card 1 -->
   <!--
   <div class="home-button-item">
   Widget:ReportModal — formulário embutido no corpo da página (sem overlay, sem botão extra).
    <a href="/index.php/Personagens" title="Personagens">
      <div class="home-button-image">
        <img src="https://wiki.gla.com.br/images/a/a8/Personagens_card.png" alt="Personagens">
      </div>
      <div class="home-button-title">PERSONAGENS</div>
    </a>
  </div>


   <!-- Card 2 -->
   {{#widget:ReportModal|api_base=https://TEU_DEPLOY}}
  <div class="home-button-item">
    <a href="/index.php/Itens" title="Itens">
      <div class="home-button-image">
        <img src="https://wiki.gla.com.br/images/3/39/Itens_card.png" alt="Itens">
      </div>
      <div class="home-button-title">ITENS</div>
    </a>
  </div>


   <!-- Card 3 -->
   Opcionais:
  <div class="home-button-item">
    |wid=2      — vários widgets na mesma página (ids únicos)
     <a href="/wiki/BoostSystem" title="Boost System">
     |heading=   — título da caixa (vazio → "Report ou sugestão")
      <div class="home-button-image">
        <img src="URL_DA_IMAGEM_BOOST" alt="Boost System">
      </div>
      <div class="home-button-title">BOOST SYSTEM</div>
    </a>
  </div>


   <!-- Card 4 -->
   No servidor: REPORTS_CORS_ORIGINS=https://wiki.gla.com.br
  <div class="home-button-item">
-->
    <a href="/wiki/NolandTales" title="Noland Tales">
</noinclude>
      <div class="home-button-image">
<div class="gla-report-widget-root" data-gla-init="0" data-gla-api="{{{api_base|}}}" data-gla-wid="{{{wid|1}}}"
        <img src="URL_DA_IMAGEM_NOLAND" alt="Noland Tales">
  data-gla-heading="{{{heading|}}}"></div>
      </div>
<script>
      <div class="home-button-title">NOLAND TALES</div>
   /*<![CDATA[*/
    </a>
  (function () {
   </div>
    "use strict";


  <div class="home-button-item">
    var roots = document.currentScript.previousElementSibling;
    <a href="/wiki/NolandTales" title="Noland Tales">
    if (!roots || !roots.classList || !roots.classList.contains("gla-report-widget-root")) {
       <div class="home-button-image">
       roots = document.querySelector(".gla-report-widget-root:not([data-gla-init])");
        <img src="URL_DA_IMAGEM_NOLAND" alt="Noland Tales">
    }
      </div>
    if (!roots || roots.getAttribute("data-gla-init")) return;
      <div class="home-button-title">NOLAND TALES</div>
    roots.setAttribute("data-gla-init", "1");
    </a>
  </div>


  <div class="home-button-item">
    var REPORTS_API_BASE = (roots.getAttribute("data-gla-api") || "").replace(/\/$/, "");
    <a href="/wiki/NolandTales" title="Noland Tales">
    var wid = String(roots.getAttribute("data-gla-wid") || "1").replace(/[^a-zA-Z0-9_-]/g, "");
      <div class="home-button-image">
    var HEADING = roots.getAttribute("data-gla-heading") || "";
        <img src="URL_DA_IMAGEM_NOLAND" alt="Noland Tales">
     if (!HEADING) HEADING = "Report ou sugestão";
      </div>
      <div class="home-button-title">NOLAND TALES</div>
     </a>
  </div>


  <div class="home-button-item">
    var MAX_TITLE = 60;
     <a href="/wiki/NolandTales" title="Noland Tales">
     var MAX_BYTES = 5 * 1024 * 1024;
      <div class="home-button-image">
        <img src="URL_DA_IMAGEM_NOLAND" alt="Noland Tales">
      </div>
      <div class="home-button-title">NOLAND TALES</div>
    </a>
  </div>


  <div class="home-button-item">
     function esc(s) {
     <a href="/wiki/NolandTales" title="Noland Tales">
       var d = document.createElement("div");
       <div class="home-button-image">
      d.textContent = s == null ? "" : String(s);
        <img src="URL_DA_IMAGEM_NOLAND" alt="Noland Tales">
      return d.innerHTML;
      </div>
    }
      <div class="home-button-title">NOLAND TALES</div>
    </a>
  </div>
</div>
<style>
.home-button-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 4 colunas - ajuste conforme necessário */
  gap: 10px;
  padding: 10px;
  box-sizing: border-box;
}


.home-button-item {
    function byId(id) {
  position: relative;
      return document.getElementById(id);
  overflow: hidden;
    }
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  box-sizing: border-box;
}


.home-button-item:hover {
    function css() {
  transform: translateY(-5px);
      if (byId("gla-reports-inline-css-global")) return;
  border-color: #007bff;
      var st = document.createElement("style");
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
      st.id = "gla-reports-inline-css-global";
}
      st.textContent =
        ".gla-report-widget-root{width:100%;max-width:520px;margin:1rem 0;display:block;clear:both}" +
        ".gla-reports-inline{max-width:100%;box-sizing:border-box;background:#111827;color:#f9fafb;border-radius:12px;padding:18px 20px;font:14px/1.45 system-ui,sans-serif;border:1px solid #374151;box-shadow:0 8px 24px rgba(0,0,0,.15)}" +
        ".gla-reports-inline-h2{font-size:1.1rem;margin:0 0 14px;color:#fff;font-weight:600}" +
        ".gla-r-field{margin-bottom:12px}" +
        ".gla-r-field label{display:block;font-size:.8rem;color:#d1d5db;margin-bottom:4px}" +
        ".gla-r-field input[type=text],.gla-r-field select,.gla-r-field textarea{width:100%;box-sizing:border-box;border-radius:8px;border:1px solid #4b5563;background:#1f2937;color:#fff;padding:8px 10px;font:inherit}" +
        ".gla-r-field textarea{min-height:120px;resize:vertical}" +
        ".gla-r-actions{display:flex;gap:8px;margin-top:16px;flex-wrap:wrap;align-items:center}" +
        ".gla-r-actions button{border-radius:8px;padding:10px 16px;font:inherit;border:0;cursor:pointer}" +
        ".gla-r-primary{background:#6366f1;color:#fff}" +
        ".gla-r-muted{background:#374151;color:#e5e7eb}" +
        ".gla-r-msg{margin-top:12px;font-size:.85rem;min-height:1.2em}" +
        ".gla-r-msg.gla-r-ok{color:#6ee7b7}" +
        ".gla-r-msg.gla-r-err{color:#fca5a5}";
      document.head.appendChild(st);
    }


.home-button-item a {
    var mid = "gla-form-" + wid;
  display: block;
  text-decoration: none;
  color: inherit;
}


.home-button-image {
    function buildFormBody() {
  width: 100%;
      return (
  /* Alterado para 16:9, reduzindo a altura */
        '<section class="gla-reports-inline" aria-labelledby="' +
  aspect-ratio: 16/9;
        mid +
  overflow: hidden;
        '-tit">' +
}
        '<h2 class="gla-reports-inline-h2" id="' +
        mid +
        '-tit">' +
        esc(HEADING) +
        "</h2>" +
        '<form id="' +
        mid +
        '-f" novalidate>' +
        '<div class="gla-r-field"><label for="' +
        mid +
        '-title">Título <span style="opacity:.65">(opcional, até ' +
        MAX_TITLE +
        " caracteres)</span></label>" +
        '<input type="text" id="' +
        mid +
        '-title" name="name" maxlength="' +
        MAX_TITLE +
        '" autocomplete="off" placeholder="Ex.: erro na página X"/></div>' +
        '<div class="gla-r-field"><label for="' +
        mid +
        '-cat">Categoria</label>' +
        '<select id="' +
        mid +
        '-cat" name="category" required>' +
        '<option value="report">' +
        esc("Report") +
        "</option>" +
        '<option value="suggestion">' +
        esc("Sugestão") +
        "</option>" +
        "</select></div>" +
        '<div class="gla-r-field"><label for="' +
        mid +
        '-desc">Descrição <span style="color:#fca5a5">*</span></label>' +
        '<textarea id="' +
        mid +
        '-desc" name="description" maxlength="8000" required placeholder="Descrição detalhada"></textarea></div>' +
        '<div class="gla-r-field"><label for="' +
        mid +
        '-img">Imagem (opcional)</label>' +
        '<input type="file" id="' +
        mid +
        '-img" accept="image/png,image/jpeg,image/gif"/></div>' +
        '<div class="gla-r-actions">' +
        '<button type="submit" class="gla-r-primary" id="' +
        mid +
        '-send">' +
        esc("Enviar") +
        "</button>" +
        '<button type="reset" class="gla-r-muted" id="' +
        mid +
        '-reset">' +
        esc("Limpar") +
        "</button></div>" +
        '<p class="gla-r-msg" id="' +
        mid +
        '-msg" role="status"></p>' +
        "</form></section>"
      );
    }


.home-button-image img {
    function localFileOk(f) {
  width: 100%;
      var t = (f.type || "").toLowerCase();
  height: 100%;
      var n = (f.name || "").toLowerCase();
  object-fit: cover;
      if (/^image\/(png|jpeg|gif)$/.test(t)) return true;
  display: block;
      if (/\.(png|jpe?g|gif)$/.test(n)) return true;
  transition: filter 0.3s ease;
      return false;
}
    }


.home-button-item:hover img {
    css();
  filter: brightness(1.1);
    roots.innerHTML = buildFormBody();
}


.home-button-title {
    var form = byId(mid + "-f");
  font-weight: bold;
    var btnSend = byId(mid + "-send");
  font-size: 1.1em;
    var msg = byId(mid + "-msg");
  background: #fff;
  color: #000;
  margin: 0;
  padding: 10px 5px;
  position: relative;
  text-transform: uppercase;
  border-top: 1px solid #ddd;
  text-align: center;
  transition: background-color 0.3s ease;
}


.home-button-item:hover .home-button-title {
    if (!REPORTS_API_BASE) {
  background-color: #f9f9f9;
      if (btnSend) btnSend.disabled = true;
}
      if (msg) {
</style>
        msg.textContent = "Configura api_base na wiki: api_base=https://…";
        msg.className = "gla-r-msg gla-r-err";
      }
      return;
    }
 
    form.addEventListener("submit", function (e) {
      e.preventDefault();
      var title = (byId(mid + "-title").value || "").trim();
      var cat = byId(mid + "-cat").value;
      var desc = (byId(mid + "-desc").value || "").trim();
      var fileIn = byId(mid + "-img");
 
      msg.textContent = "";
      msg.className = "gla-r-msg";
 
      if (!desc) {
        msg.textContent = "Preencha a descrição.";
        msg.className = "gla-r-msg gla-r-err";
        return;
      }
      if (title.length > MAX_TITLE) {
        msg.textContent = "Título longo demais.";
        msg.className = "gla-r-msg gla-r-err";
        return;
      }
 
      var fd = new FormData();
      if (title) fd.append("name", title);
      fd.append("category", cat);
      fd.append("description", desc);
      if (fileIn.files && fileIn.files[0]) {
        var f = fileIn.files[0];
        if (f.size > MAX_BYTES) {
          msg.textContent = "Imagem acima de 5 MB.";
          msg.className = "gla-r-msg gla-r-err";
          return;
        }
        if (!localFileOk(f)) {
          msg.textContent = "Só PNG, JPG ou GIF.";
          msg.className = "gla-r-msg gla-r-err";
          return;
        }
        fd.append("image", f);
      }
 
      btnSend.disabled = true;
      var url = REPORTS_API_BASE + "/api/reports";
 
      fetch(url, { method: "POST", body: fd })
        .then(function (r) {
          return r.text().then(function (text) {
            var body = {};
            try {
              body = text ? JSON.parse(text) : {};
            } catch (ignore) {
              body = { _raw: text };
            }
            return { ok: r.ok, status: r.status, body: body, raw: text };
          });
        })
        .then(function (result) {
          if (result.ok) {
            msg.textContent = "Enviado. Obrigado!";
            msg.className = "gla-r-msg gla-r-ok";
            form.reset();
          } else {
            var detail =
              (result.body && result.body.error) ||
              (result.raw && result.raw.slice(0, 200)) ||
              "";
            msg.textContent = detail
              ? detail + " (" + result.status + ")"
              : "Erro " + result.status;
            msg.className = "gla-r-msg gla-r-err";
          }
        })
        .catch(function () {
          msg.textContent =
            "Rede ou CORS: confirma api_base e REPORTS_CORS_ORIGINS no servidor.";
          msg.className = "gla-r-msg gla-r-err";
        })
        .then(function () {
          btnSend.disabled = false;
        });
    });
  })();
  /*]]>*/
</script>

Edição atual tal como às 16h07min de 28 de abril de 2026


<script>

 /*<![CDATA[*/
 (function () {
   "use strict";
   var roots = document.currentScript.previousElementSibling;
   if (!roots || !roots.classList || !roots.classList.contains("gla-report-widget-root")) {
     roots = document.querySelector(".gla-report-widget-root:not([data-gla-init])");
   }
   if (!roots || roots.getAttribute("data-gla-init")) return;
   roots.setAttribute("data-gla-init", "1");
   var REPORTS_API_BASE = (roots.getAttribute("data-gla-api") || "").replace(/\/$/, "");
   var wid = String(roots.getAttribute("data-gla-wid") || "1").replace(/[^a-zA-Z0-9_-]/g, "");
   var HEADING = roots.getAttribute("data-gla-heading") || "";
   if (!HEADING) HEADING = "Report ou sugestão";
   var MAX_TITLE = 60;
   var MAX_BYTES = 5 * 1024 * 1024;
   function esc(s) {
     var d = document.createElement("div");
     d.textContent = s == null ? "" : String(s);
     return d.innerHTML;
   }
   function byId(id) {
     return document.getElementById(id);
   }
   function css() {
     if (byId("gla-reports-inline-css-global")) return;
     var st = document.createElement("style");
     st.id = "gla-reports-inline-css-global";
     st.textContent =
       ".gla-report-widget-root{width:100%;max-width:520px;margin:1rem 0;display:block;clear:both}" +
       ".gla-reports-inline{max-width:100%;box-sizing:border-box;background:#111827;color:#f9fafb;border-radius:12px;padding:18px 20px;font:14px/1.45 system-ui,sans-serif;border:1px solid #374151;box-shadow:0 8px 24px rgba(0,0,0,.15)}" +
       ".gla-reports-inline-h2{font-size:1.1rem;margin:0 0 14px;color:#fff;font-weight:600}" +
       ".gla-r-field{margin-bottom:12px}" +
       ".gla-r-field label{display:block;font-size:.8rem;color:#d1d5db;margin-bottom:4px}" +
       ".gla-r-field input[type=text],.gla-r-field select,.gla-r-field textarea{width:100%;box-sizing:border-box;border-radius:8px;border:1px solid #4b5563;background:#1f2937;color:#fff;padding:8px 10px;font:inherit}" +
       ".gla-r-field textarea{min-height:120px;resize:vertical}" +
       ".gla-r-actions{display:flex;gap:8px;margin-top:16px;flex-wrap:wrap;align-items:center}" +
       ".gla-r-actions button{border-radius:8px;padding:10px 16px;font:inherit;border:0;cursor:pointer}" +
       ".gla-r-primary{background:#6366f1;color:#fff}" +
       ".gla-r-muted{background:#374151;color:#e5e7eb}" +
       ".gla-r-msg{margin-top:12px;font-size:.85rem;min-height:1.2em}" +
       ".gla-r-msg.gla-r-ok{color:#6ee7b7}" +
       ".gla-r-msg.gla-r-err{color:#fca5a5}";
     document.head.appendChild(st);
   }
   var mid = "gla-form-" + wid;
   function buildFormBody() {
     return (
       '<section class="gla-reports-inline" aria-labelledby="' +
       mid +
       '-tit">' +

'

' + esc(HEADING) + "

" +

       '<form id="' +
       mid +
       '-f" novalidate>' +

'

<label for="' +
       mid +
       '-title">Título (opcional, até ' +
       MAX_TITLE +
       " caracteres)</label>" +
       '<input type="text" id="' +
       mid +
       '-title" name="name" maxlength="' +
       MAX_TITLE +
'" autocomplete="off" placeholder="Ex.: erro na página X"/>

' + '

<label for="' +
       mid +
       '-cat">Categoria</label>' +
       '<select id="' +
       mid +
       '-cat" name="category" required>' +
       '<option value="report">' +
       esc("Report") +
       "</option>" +
       '<option value="suggestion">' +
       esc("Sugestão") +
       "</option>" +
"</select>

" + '

<label for="' +
       mid +
       '-desc">Descrição *</label>' +
       '<textarea id="' +
       mid +
'-desc" name="description" maxlength="8000" required placeholder="Descrição detalhada"></textarea>

' + '

<label for="' +
       mid +
       '-img">Imagem (opcional)</label>' +
       '<input type="file" id="' +
       mid +
'-img" accept="image/png,image/jpeg,image/gif"/>

' + '

' +
       '<button type="submit" class="gla-r-primary" id="' +
       mid +
       '-send">' +
       esc("Enviar") +
       "</button>" +
       '<button type="reset" class="gla-r-muted" id="' +
       mid +
       '-reset">' +
       esc("Limpar") +
"</button>

" + '

' +

       "</form></section>"
     );
   }
   function localFileOk(f) {
     var t = (f.type || "").toLowerCase();
     var n = (f.name || "").toLowerCase();
     if (/^image\/(png|jpeg|gif)$/.test(t)) return true;
     if (/\.(png|jpe?g|gif)$/.test(n)) return true;
     return false;
   }
   css();
   roots.innerHTML = buildFormBody();
   var form = byId(mid + "-f");
   var btnSend = byId(mid + "-send");
   var msg = byId(mid + "-msg");
   if (!REPORTS_API_BASE) {
     if (btnSend) btnSend.disabled = true;
     if (msg) {
       msg.textContent = "Configura api_base na wiki: api_base=https://…";
       msg.className = "gla-r-msg gla-r-err";
     }
     return;
   }
   form.addEventListener("submit", function (e) {
     e.preventDefault();
     var title = (byId(mid + "-title").value || "").trim();
     var cat = byId(mid + "-cat").value;
     var desc = (byId(mid + "-desc").value || "").trim();
     var fileIn = byId(mid + "-img");
     msg.textContent = "";
     msg.className = "gla-r-msg";
     if (!desc) {
       msg.textContent = "Preencha a descrição.";
       msg.className = "gla-r-msg gla-r-err";
       return;
     }
     if (title.length > MAX_TITLE) {
       msg.textContent = "Título longo demais.";
       msg.className = "gla-r-msg gla-r-err";
       return;
     }
     var fd = new FormData();
     if (title) fd.append("name", title);
     fd.append("category", cat);
     fd.append("description", desc);
     if (fileIn.files && fileIn.files[0]) {
       var f = fileIn.files[0];
       if (f.size > MAX_BYTES) {
         msg.textContent = "Imagem acima de 5 MB.";
         msg.className = "gla-r-msg gla-r-err";
         return;
       }
       if (!localFileOk(f)) {
         msg.textContent = "Só PNG, JPG ou GIF.";
         msg.className = "gla-r-msg gla-r-err";
         return;
       }
       fd.append("image", f);
     }
     btnSend.disabled = true;
     var url = REPORTS_API_BASE + "/api/reports";
     fetch(url, { method: "POST", body: fd })
       .then(function (r) {
         return r.text().then(function (text) {
           var body = {};
           try {
             body = text ? JSON.parse(text) : {};
           } catch (ignore) {
             body = { _raw: text };
           }
           return { ok: r.ok, status: r.status, body: body, raw: text };
         });
       })
       .then(function (result) {
         if (result.ok) {
           msg.textContent = "Enviado. Obrigado!";
           msg.className = "gla-r-msg gla-r-ok";
           form.reset();
         } else {
           var detail =
             (result.body && result.body.error) ||
             (result.raw && result.raw.slice(0, 200)) ||
             "";
           msg.textContent = detail
             ? detail + " (" + result.status + ")"
             : "Erro " + result.status;
           msg.className = "gla-r-msg gla-r-err";
         }
       })
       .catch(function () {
         msg.textContent =
           "Rede ou CORS: confirma api_base e REPORTS_CORS_ORIGINS no servidor.";
         msg.className = "gla-r-msg gla-r-err";
       })
       .then(function () {
         btnSend.disabled = false;
       });
   });
 })();
 /*]]>*/

</script>