synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# 📌 Post-it
|
||||
|
||||
Pose des post-it n’importe où, déplace-les, change la couleur — un mur à idées.
|
||||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| id | `post-it` |
|
||||
| fournit | `sticky-notes` `board` |
|
||||
| bions qu'il nomme | `jOSApps` `jOSBoxion` `jOSMobile` `jOSPorts` `jOSPresence` `jOSXui` |
|
||||
| fichiers | `app.blade.php` |
|
||||
| dans le labo | `resources/views/ploxions/post-it/` (dépôt `my_website2`) |
|
||||
|
||||
## Contribuer
|
||||
|
||||
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=post-it — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||
- **Dans VS Code** : `xb prendre post-it` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||
|
||||
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||
|
||||
© 2026 chill-tekk · ne pas nuire
|
||||
477
app.blade.php
Normal file
477
app.blade.php
Normal file
@@ -0,0 +1,477 @@
|
||||
{{-- PL0XI0N post-it — mur INFINI collaboratif (RS-7 2026-06-29) :
|
||||
· carte infinie zoomable (molette/pince + pan) ;
|
||||
· ZONES (grandes, avec un BACKGROUND couleur/image) > GROUPES (contiennent des post-it,
|
||||
bouger le groupe bouge ses notes) > POST-IT (texte, image, couleur, police, resize) ;
|
||||
· multi-sélection Ctrl/Maj-clic ; supprimer une image ;
|
||||
· LIVE collaboratif (bouton 🔴) : sync temps quasi-réel entre tablette/tel/ordi ET amis
|
||||
invités (merge par-item LWW côté serveur /wall/<code>), avec lien d'invitation.
|
||||
100% client-side. mount(container,ctx) -> {unmount}. --}}
|
||||
<style>
|
||||
.pit { position:relative; height:100%; overflow:hidden; background:
|
||||
radial-gradient(circle at 20% 15%, rgba(30,44,66,.5), var(--xr-bg,#06090d) 70%);
|
||||
font-family:ui-sans-serif,system-ui,sans-serif; }
|
||||
.pit__bar { position:absolute; top:0; left:0; right:0; z-index:6; display:flex; align-items:center; gap:8px;
|
||||
padding:7px 11px; background:rgba(6,9,13,.7); border-bottom:1px solid rgba(120,160,230,.18); flex-wrap:wrap; }
|
||||
.pit__t { font-weight:700; letter-spacing:.04em; color:rgba(160,195,255,.95); font-size:.82rem; }
|
||||
.pit__sp { flex:1; }
|
||||
.pit__btn { cursor:pointer; padding:3px 10px; border-radius:6px; border:1px solid rgba(120,160,230,.3);
|
||||
background:none; color:rgba(160,195,255,.85); font-size:.74rem; }
|
||||
.pit__btn:hover { background:rgba(120,160,230,.12); color:#fff; }
|
||||
.pit__btn.live { border-color:rgba(232,90,90,.5); color:#ff9a9a; }
|
||||
.pit__btn.live.on { background:rgba(232,60,60,.22); color:#ffd0d0; border-color:#e85a5a; }
|
||||
.pit__zoom { display:flex; align-items:center; gap:4px; color:rgba(160,195,255,.7); font-size:.72rem; }
|
||||
.pit__zoom button { width:26px; height:24px; cursor:pointer; border-radius:6px; border:1px solid rgba(120,160,230,.3); background:none; color:rgba(160,195,255,.85); }
|
||||
.pit__board { position:absolute; inset:0; top:38px; overflow:hidden; touch-action:none; cursor:grab; }
|
||||
.pit__board.grab { cursor:grabbing; }
|
||||
.pit__world { position:absolute; left:0; top:0; transform-origin:0 0; will-change:transform; }
|
||||
/* ZONE = grand cadre avec background */
|
||||
.pit__zone { position:absolute; z-index:0; border:1px solid rgba(120,160,230,.22); border-radius:18px; overflow:hidden;
|
||||
background:var(--zb,rgba(120,160,230,.05)); background-size:cover; background-position:center; }
|
||||
.pit__zoneh { position:absolute; top:8px; left:10px; z-index:1; display:flex; align-items:center; gap:6px; padding:3px 9px;
|
||||
border-radius:8px; background:rgba(6,11,18,.66); cursor:grab; touch-action:none; }
|
||||
.pit__zoneh input { background:none; border:0; outline:none; color:rgba(200,224,255,.95); font-weight:800; font-size:.86rem; font-family:inherit; }
|
||||
.pit__grp { position:absolute; z-index:1; border:1.5px dashed var(--gc,#5a6e8e); border-radius:14px;
|
||||
background:color-mix(in srgb, var(--gc,#5a6e8e) 8%, transparent); }
|
||||
.pit__grph { position:absolute; top:-13px; left:14px; display:flex; align-items:center; gap:5px; padding:2px 8px;
|
||||
border-radius:8px; background:var(--xr-surface,#0b1119); border:1px solid var(--gc,#5a6e8e); cursor:grab; touch-action:none; }
|
||||
.pit__grph:active,.pit__zoneh:active { cursor:grabbing; }
|
||||
.pit__gtitle { background:none; border:0; outline:none; color:var(--gc,#9fb3d6); font-weight:800; font-size:.84rem; min-width:40px; font-family:inherit; }
|
||||
.pit__gdot { width:11px; height:11px; border-radius:3px; cursor:pointer; flex:0 0 auto; }
|
||||
.pit__gx { cursor:pointer; border:0; background:none; color:rgba(160,195,255,.6); font-size:.8rem; line-height:1; }
|
||||
.pit__n { position:absolute; z-index:3; width:200px; height:150px; border-radius:5px; box-shadow:0 6px 18px rgba(0,0,0,.4);
|
||||
display:flex; flex-direction:column; transform:rotate(var(--r,0deg)); }
|
||||
.pit__n.sel { outline:2px solid var(--xr-accent,#3fe0d0); outline-offset:2px; box-shadow:0 0 0 2px rgba(63,224,208,.55), 0 8px 22px rgba(0,0,0,.5); }
|
||||
.pit__selbar { position:absolute; left:50%; bottom:14px; transform:translateX(-50%); z-index:70; display:flex; align-items:center; gap:8px;
|
||||
padding:7px 12px; border-radius:999px; background:rgba(10,16,24,.92); border:1px solid rgba(63,224,208,.4); box-shadow:0 10px 30px rgba(0,0,0,.5); color:rgba(200,224,255,.95); font-size:.8rem; }
|
||||
.pit__selbar[hidden],.pit__live[hidden] { display:none; }
|
||||
.pit__selbar button { cursor:pointer; border:1px solid rgba(120,160,230,.3); background:none; color:rgba(200,224,255,.9); border-radius:8px; padding:5px 9px; font-size:.78rem; }
|
||||
.pit__selbar button.del { border-color:rgba(232,122,106,.5); color:#ffb3a8; }
|
||||
.pit__nh { height:24px; cursor:grab; display:flex; align-items:center; gap:4px; padding:0 5px; border-radius:5px 5px 0 0; background:rgba(0,0,0,.14); touch-action:none; flex:0 0 auto; }
|
||||
.pit__nh:active { cursor:grabbing; }
|
||||
.pit__dot { width:13px; height:13px; border-radius:50%; cursor:pointer; border:1px solid rgba(0,0,0,.3); flex:0 0 auto; }
|
||||
.pit__hb { cursor:pointer; border:0; background:none; color:rgba(0,0,0,.5); font-size:.78rem; line-height:1; padding:2px 3px; border-radius:4px; }
|
||||
.pit__hb:hover { color:#000; background:rgba(0,0,0,.08); }
|
||||
.pit__x { margin-left:auto; }
|
||||
.pit__imw { position:relative; flex:0 0 auto; }
|
||||
.pit__img { width:100%; max-height:160px; object-fit:cover; cursor:zoom-in; display:block; }
|
||||
.pit__imx { position:absolute; top:4px; right:4px; width:20px; height:20px; border-radius:50%; border:0; cursor:pointer; background:rgba(0,0,0,.55); color:#fff; font-size:.8rem; line-height:20px; text-align:center; }
|
||||
.pit__ta { flex:1; min-height:0; border:0; background:none; resize:none; outline:none; padding:7px 8px; line-height:1.35; color:rgba(20,20,25,.92); font-family:inherit; }
|
||||
.pit__ta::placeholder { color:rgba(0,0,0,.32); }
|
||||
.pit__rz { position:absolute; right:0; bottom:0; width:18px; height:18px; cursor:nwse-resize; touch-action:none; background:linear-gradient(135deg,transparent 50%,rgba(0,0,0,.28) 50%); border-radius:0 0 5px 0; z-index:2; }
|
||||
.pit__zone .pit__rz { background:linear-gradient(135deg,transparent 50%,rgba(120,160,230,.4) 50%); }
|
||||
.pit__pal { position:absolute; z-index:60; display:flex; gap:6px; flex-wrap:wrap; width:166px; padding:8px; border-radius:10px; background:var(--xr-surface,#10161f); border:1px solid rgba(120,160,230,.3); box-shadow:0 10px 30px rgba(0,0,0,.5); }
|
||||
.pit__sw { width:24px; height:24px; border-radius:50%; cursor:pointer; border:2px solid transparent; }
|
||||
.pit__sw:hover { border-color:#fff; }
|
||||
.pit__pal input[type=color] { width:24px; height:24px; padding:0; border:0; background:none; cursor:pointer; }
|
||||
.pit__pal .imgb { width:100%; text-align:center; cursor:pointer; color:rgba(160,195,255,.85); font-size:.72rem; border:1px dashed rgba(120,160,230,.3); border-radius:7px; padding:5px; }
|
||||
.pit__live { position:absolute; right:12px; top:46px; z-index:71; width:min(330px,92vw); padding:12px 13px; border-radius:12px;
|
||||
background:rgba(10,16,24,.96); border:1px solid rgba(232,90,90,.4); box-shadow:0 14px 40px rgba(0,0,0,.55); color:rgba(210,228,255,.95); font-size:.8rem; }
|
||||
.pit__live b { color:#ff9a9a; } .pit__live .row { display:flex; gap:6px; margin-top:8px; }
|
||||
.pit__live input { flex:1; min-width:0; background:var(--xr-surface,#0b1119); border:1px solid rgba(120,160,230,.3); border-radius:7px; color:rgba(200,224,255,.9); padding:7px 9px; font-size:.74rem; }
|
||||
.pit__live button { cursor:pointer; border:1px solid rgba(120,160,230,.3); background:none; color:rgba(200,224,255,.9); border-radius:7px; padding:7px 10px; font-size:.74rem; }
|
||||
.pit__ov { position:absolute; inset:0; z-index:80; display:none; align-items:center; justify-content:center; background:rgba(4,8,14,.72); backdrop-filter:blur(3px); padding:18px; }
|
||||
.pit__ov.on { display:flex; }
|
||||
.pit__big { width:min(760px,100%); height:min(86%,640px); border-radius:12px; display:flex; flex-direction:column; box-shadow:0 20px 60px rgba(0,0,0,.6); overflow:hidden; position:relative; }
|
||||
.pit__bigh { display:flex; align-items:center; gap:6px; padding:6px 8px; background:rgba(0,0,0,.16); flex:0 0 auto; }
|
||||
.pit__big .pit__imw { max-height:42%; } .pit__big img { width:100%; max-height:100%; object-fit:contain; background:rgba(0,0,0,.1); }
|
||||
.pit__big textarea { flex:1; border:0; background:none; outline:none; resize:none; padding:14px 16px; line-height:1.45; color:rgba(20,20,25,.92); font-family:inherit; }
|
||||
.pit__cursors { position:absolute; inset:0; pointer-events:none; z-index:5; overflow:hidden; }
|
||||
.pit__cur { position:absolute; transition:transform .12s linear; will-change:transform; }
|
||||
.pit__cur svg { display:block; filter:drop-shadow(0 1px 1px rgba(0,0,0,.5)); }
|
||||
.pit__cur .nm { position:absolute; left:14px; top:14px; white-space:nowrap; font-size:.66rem; font-weight:800; color:#08111b; padding:1px 7px; border-radius:9px; }
|
||||
.pit__pres { position:absolute; right:12px; top:46px; z-index:69; display:flex; align-items:center; gap:-6px; }
|
||||
.pit__pres[hidden] { display:none; }
|
||||
.pit__pa { width:30px; height:30px; border-radius:50%; margin-left:-8px; display:flex; align-items:center; justify-content:center;
|
||||
font-size:.72rem; font-weight:800; color:#08111b; border:2px solid #0b1119; box-shadow:0 2px 6px rgba(0,0,0,.4); position:relative; }
|
||||
.pit__pa .dv { position:absolute; bottom:-3px; right:-3px; font-size:.6rem; }
|
||||
.pit__pa.more { background:#2a3550; color:rgba(200,224,255,.9); }
|
||||
.pit__hint { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); color:rgba(190,212,228,.4); font-size:.82rem; pointer-events:none; text-align:center; }
|
||||
/* TÉLÉPHONE : cibles tactiles plus grosses (RS-7 : « ajoute ça pour téléphone ») */
|
||||
@media (max-width:768px) {
|
||||
.pit__nh { height:32px; gap:6px; padding:0 7px; }
|
||||
.pit__hb { font-size:1rem; padding:5px 7px; }
|
||||
.pit__dot { width:18px; height:18px; }
|
||||
.pit__imx { width:26px; height:26px; line-height:26px; font-size:.95rem; }
|
||||
.pit__rz { width:26px; height:26px; }
|
||||
.pit__bar .pit__btn { padding:7px 11px; font-size:.8rem; }
|
||||
.pit__gdot { width:15px; height:15px; }
|
||||
.pit__zoneh, .pit__grph { padding:4px 10px; }
|
||||
.pit__selbar { bottom:calc(14px + env(safe-area-inset-bottom)); }
|
||||
.pit__selbar button { padding:8px 11px; }
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
(function () {
|
||||
var KEY='xb:post-it', GKEY='xb:post-it:groups', ZKEY='xb:post-it:zones', DKEY='xb:post-it:del', VKEY='xb:post-it:view', WKEY='xb:post-it:wall', LKEY='xb:post-it:live', NS='postit';
|
||||
var COLORS=['#ffe27a','#ffb3ba','#baffc9','#b3d9ff','#e0baff','#ffd9a0','#c8d6e5','#f8a5c2'];
|
||||
var GCOLORS=['#5a6e8e','#7cf3a0','#ffd166','#ff9ecb','#c79bff','#5ad1c8'];
|
||||
|
||||
function ls(k,d){ try { return JSON.parse(localStorage.getItem(k)) || d; } catch (e) { return d; } }
|
||||
function uid(){ return 'p'+Date.now().toString(36)+Math.floor(performance.now()).toString(36)+Math.floor(Math.random()*1e4).toString(36); }
|
||||
function now(){ return Date.now(); }
|
||||
function csrf(){return window.jOSb&&window.jOSb.csrf?window.jOSb.csrf():(function(){var m=document.querySelector('meta[name=csrf-token]');return m?(m.getAttribute('content')||m.content||''):'';})();}
|
||||
function clamp(v,a,b){return window.jOSb&&window.jOSb.clamp?window.jOSb.clamp(v,a,b):(v<a?a:(v>b?b:v));}
|
||||
function rid(){return window.jOSb&&window.jOSb.rid?window.jOSb.rid():Math.random().toString(36).slice(2,10);}
|
||||
// OUT bus (topic ploxion.post-it.note) : un post-it écrit se pose comme item d'inbox du murion
|
||||
function emitNote(n){ try { if (window.jOSPorts && n && (n.text||'').trim()){
|
||||
var p={ id:n.id, text:String(n.text).slice(0,2000), color:n.color||null };
|
||||
if (n.img && String(n.img).indexOf('data:')!==0) p.img=n.img; // url seulement, jamais de blob dataURL
|
||||
window.jOSPorts.emit('post-it','note',p); } } catch (e) {} }
|
||||
|
||||
function mount(container, ctx) {
|
||||
var notes=ls(KEY,[]), groups=ls(GKEY,[]), zones=ls(ZKEY,[]), del=ls(DKEY,{}), view=ls(VKEY,{x:40,y:30,s:1});
|
||||
// wall code : ?wall=... (ami invité) sinon mon mur perso (localStorage)
|
||||
var urlWall=null; try { urlWall=new URLSearchParams(location.search).get('wall'); } catch (e) {}
|
||||
var wall = urlWall || ls(WKEY,null); if (!wall){ wall=rid(); try{ localStorage.setItem(WKEY,JSON.stringify(wall)); }catch(e){} }
|
||||
var live = urlWall ? true : (ls(LKEY,'0')==='1');
|
||||
var lastT=0, pushPending=false, pushT=null, pollIv=null;
|
||||
|
||||
container.innerHTML =
|
||||
'<div class="pit">'
|
||||
+ ' <div class="pit__bar"><span class="pit__t">📌</span>'
|
||||
+ ' <span class="pit__zoom"><button data-z="-1">−</button><span data-zl>100%</span><button data-z="1">+</button><button data-z="0" title="recentrer">⤾</button></span>'
|
||||
+ ' <span class="pit__zoom"><button data-undo title="annuler (Ctrl+Z)">↶</button><button data-redo title="rétablir (Ctrl+Maj+Z)">↷</button></span>'
|
||||
+ ' <span class="pit__sp"></span>'
|
||||
+ ' <button class="pit__btn live" data-live>⚪ Live</button>'
|
||||
+ ' <button class="pit__btn" data-zone>+ zone</button>'
|
||||
+ ' <button class="pit__btn" data-grp>+ groupe</button>'
|
||||
+ ' <button class="pit__btn" data-add>+ post-it</button>'
|
||||
+ ' <button class="pit__btn" data-clear>tout vider</button></div>'
|
||||
+ ' <div class="pit__board"><div class="pit__world"></div><div class="pit__cursors" data-cursors></div></div>'
|
||||
+ ' <div class="pit__hint">clique « + post-it » et déverse<br><small>molette/pince = zoom · glisse le fond = déplacer · appui long (ou Ctrl/Maj-clic) = sélectionner · 🔴 Live = collaborer</small></div>'
|
||||
+ ' <div class="pit__selbar" data-selbar hidden><b data-selc>0</b> sélectionné(s)<button data-selcol>🎨 couleur</button><button class="del" data-seldel>✕ supprimer</button><button data-selclr>désélectionner</button></div>'
|
||||
+ ' <div class="pit__pres" data-pres hidden></div>'
|
||||
+ ' <div class="pit__live" data-livep hidden></div>'
|
||||
+ ' <div class="pit__ov" data-ov></div>'
|
||||
+ '</div>';
|
||||
var root=container.querySelector('.pit'), board=container.querySelector('.pit__board'), world=container.querySelector('.pit__world');
|
||||
var hint=container.querySelector('.pit__hint'), ovEl=container.querySelector('[data-ov]'), zl=container.querySelector('[data-zl]');
|
||||
var selbar=container.querySelector('[data-selbar]'), livep=container.querySelector('[data-livep]'), liveBtn=container.querySelector('[data-live]');
|
||||
var undoBtn=container.querySelector('[data-undo]'), redoBtn=container.querySelector('[data-redo]');
|
||||
var presEl=container.querySelector('[data-pres]'), presHandle=null;
|
||||
var curLayer=container.querySelector('[data-cursors]'), lastMembers=[];
|
||||
|
||||
// ---------- historique annuler/rétablir ----------
|
||||
var hist=[], hi=-1, applying=false, recT=null;
|
||||
function snap(){ return JSON.stringify({ n:notes, g:groups, z:zones }); }
|
||||
function histInit(){ hist=[snap()]; hi=0; updUndo(); }
|
||||
function record(){ if (applying) return; clearTimeout(recT); recT=setTimeout(function(){
|
||||
var s=snap(); if (hi>=0 && hist[hi]===s) return; hist=hist.slice(0,hi+1); hist.push(s); hi=hist.length-1;
|
||||
if (hist.length>60){ hist.shift(); hi--; } updUndo(); }, 280); }
|
||||
function applySnap(s){ var d; try { d=JSON.parse(s); } catch (e) { return; } applying=true;
|
||||
var before={}; notes.concat(groups).concat(zones).forEach(function(o){ before[o.id]=1; });
|
||||
notes=d.n||[]; groups=d.g||[]; zones=d.z||[];
|
||||
var after={}; notes.concat(groups).concat(zones).forEach(function(o){ o.m=now(); after[o.id]=1; });
|
||||
Object.keys(before).forEach(function(id){ if (!after[id]) addDel(id); }); // re-supprime ce qui n'existe plus
|
||||
renderAll(); writeLocal(); if (live) pushSoon(); applying=false; updUndo(); }
|
||||
function undo(){ if (hi<=0) return; hi--; applySnap(hist[hi]); }
|
||||
function redo(){ if (hi>=hist.length-1) return; hi++; applySnap(hist[hi]); }
|
||||
function updUndo(){ if (undoBtn) undoBtn.disabled=hi<=0; if (redoBtn) redoBtn.disabled=hi>=hist.length-1; }
|
||||
|
||||
// ---------- persistance + LIVE ----------
|
||||
function writeLocal(){ try { localStorage.setItem(KEY,JSON.stringify(notes)); localStorage.setItem(GKEY,JSON.stringify(groups));
|
||||
localStorage.setItem(ZKEY,JSON.stringify(zones)); localStorage.setItem(DKEY,JSON.stringify(del)); } catch (e) {}
|
||||
try { var b=window.jOSBoxion; if (b&&b.saveSoon){ b.saveSoon(NS,'notes',notes); b.saveSoon(NS,'groups',groups); b.saveSoon(NS,'zones',zones); } } catch (e) {}
|
||||
if (!applying) record(); }
|
||||
function save(obj){ if (obj) obj.m=now(); writeLocal(); if (live) pushSoon(); }
|
||||
function addDel(id){ del[id]=now(); }
|
||||
function pushSoon(){ pushPending=true; clearTimeout(pushT); pushT=setTimeout(pushNow, 600); }
|
||||
function pushNow(){ if (!live){ pushPending=false; return; }
|
||||
fetch('/wall/'+wall, { method:'POST', headers:{ 'Content-Type':'application/json','X-CSRF-TOKEN':csrf(),'X-Requested-With':'XMLHttpRequest','Accept':'application/json' },
|
||||
credentials:'same-origin', body:JSON.stringify({ notes:notes, groups:groups, zones:zones, del:del }) })
|
||||
.then(function(r){ return r.ok?r.json():null; }).then(function(d){ pushPending=false; if (d) adopt(d, true); }).catch(function(){ pushPending=false; }); }
|
||||
function pull(){ if (!live || pushPending) return;
|
||||
var ae=document.activeElement; if (ae && root.contains(ae) && (ae.tagName==='TEXTAREA'||ae.tagName==='INPUT')) return; // ne pas casser une saisie
|
||||
fetch('/wall/'+wall+'.json', { headers:{Accept:'application/json'} }).then(function(r){ return r.ok?r.json():null; })
|
||||
.then(function(d){ if (d && (d.t||0) > lastT) adopt(d, false); }).catch(function(){}); }
|
||||
function adopt(d, fromPush){ notes=d.notes||[]; groups=d.groups||[]; zones=d.zones||[]; del=d.del||{}; lastT=d.t||lastT;
|
||||
try { localStorage.setItem(KEY,JSON.stringify(notes)); localStorage.setItem(GKEY,JSON.stringify(groups)); localStorage.setItem(ZKEY,JSON.stringify(zones)); localStorage.setItem(DKEY,JSON.stringify(del)); } catch (e) {}
|
||||
renderAll(); hist=[snap()]; hi=0; updUndo(); } // une maj distante = nouvelle base d'historique
|
||||
function setLive(on){ live=on; try{ localStorage.setItem(LKEY, on?'1':'0'); }catch(e){}
|
||||
liveBtn.classList.toggle('on',on); liveBtn.textContent = on?'🔴 LIVE':'⚪ Live';
|
||||
if (on){ pushNow(); if (!pollIv) pollIv=setInterval(pull, 2000);
|
||||
if (window.jOSPresence && !presHandle){ presHandle=window.jOSPresence.join('wall-'+wall); presHandle.on(renderPres); presEl.hidden=false; } }
|
||||
else { if (pollIv){ clearInterval(pollIv); pollIv=null; } livep.hidden=true;
|
||||
if (presHandle){ presHandle.leave(); presHandle=null; } presEl.hidden=true; presEl.innerHTML=''; } }
|
||||
function renderPres(members){ members=members||[]; lastMembers=members;
|
||||
var meId = window.jOSPresence ? window.jOSPresence.me().id : null;
|
||||
var ord=members.slice().sort(function(a,b){ return a.id===meId?-1:(b.id===meId?1:0); });
|
||||
var show=ord.slice(0,6), extra=ord.length-show.length;
|
||||
presEl.innerHTML = show.map(function(m){ var ini=(m.name||'?').trim().charAt(0).toUpperCase()||'?';
|
||||
return '<div class="pit__pa" style="background:'+(m.color||'#3fe0d0')+'" title="'+(m.name||'')+(m.id===meId?' (toi)':'')+'">'+ini+'<span class="dv">'+(m.device||'')+'</span></div>'; }).join('')
|
||||
+ (extra>0?'<div class="pit__pa more">+'+extra+'</div>':'');
|
||||
paintCursors();
|
||||
}
|
||||
// curseurs LIVE des autres (coords room -> écran via la vue). Couche écran, repositionnée au pan/zoom.
|
||||
function paintCursors(){ if (!curLayer) return; var meId = window.jOSPresence ? window.jOSPresence.me().id : null; var seen={};
|
||||
(lastMembers||[]).forEach(function(m){ if (m.id===meId || m.cx==null) return; seen[m.id]=1;
|
||||
var el=curLayer.querySelector('[data-c="'+m.id+'"]');
|
||||
if (!el){ el=document.createElement('div'); el.className='pit__cur'; el.dataset.c=m.id;
|
||||
el.innerHTML='<svg width="20" height="20" viewBox="0 0 20 20"><path d="M2 2 L2 16 L6 12 L9 18 L11 17 L8 11 L14 11 Z" fill="'+(m.color||'#3fe0d0')+'" stroke="#0b1119" stroke-width="1"/></svg><span class="nm" style="background:'+(m.color||'#3fe0d0')+'">'+esc(m.name||'')+'</span>'; curLayer.appendChild(el); }
|
||||
var sx=view.x+m.cx*view.s, sy=view.y+m.cy*view.s; el.style.transform='translate('+sx+'px,'+sy+'px)';
|
||||
});
|
||||
curLayer.querySelectorAll('[data-c]').forEach(function(el){ if(!seen[el.dataset.c]) el.remove(); });
|
||||
}
|
||||
function showLiveP(){ var url=location.origin+'/?px=post-it&wall='+wall; var acc=authed();
|
||||
livep.hidden=false; livep.innerHTML='<b>🔴 Mur en LIVE</b>'+(acc?' — lié à ton compte j0bot : <b>même mur sur tous tes appareils</b>.':' — synchronisé sur ce mur partagé.')+'<br>'
|
||||
+ '<div class="row"><input readonly value="'+url+'"><button data-cp>copier</button><button data-sh>inviter un ami</button></div>'
|
||||
+ '<div class="row"><button data-stop>⏸ arrêter le live</button><button data-closep>fermer</button></div>';
|
||||
livep.querySelector('[data-cp]').onclick=function(){ try{ navigator.clipboard.writeText(url); this.textContent='copié ✓'; }catch(e){} };
|
||||
livep.querySelector('[data-sh]').onclick=function(){ if (navigator.share) navigator.share({ title:'Mon mur de post-it', url:url }).catch(function(){}); else { try{ navigator.clipboard.writeText(url); this.textContent='lien copié ✓'; }catch(e){} } };
|
||||
livep.querySelector('[data-stop]').onclick=function(){ setLive(false); };
|
||||
livep.querySelector('[data-closep]').onclick=function(){ livep.hidden=true; }; }
|
||||
|
||||
function refreshHint(){ hint.style.display=(notes.length||groups.length||zones.length)?'none':'block'; }
|
||||
function applyView(){ world.style.transform='translate('+view.x+'px,'+view.y+'px) scale('+view.s+')'; zl.textContent=Math.round(view.s*100)+'%'; paintCursors(); }
|
||||
function saveView(){ try{ localStorage.setItem(VKEY,JSON.stringify(view)); }catch(e){} }
|
||||
function worldCenter(){ return { x:(board.clientWidth/2-view.x)/view.s, y:(board.clientHeight/2-view.y)/view.s }; }
|
||||
|
||||
// jOSBoxion (sync passive de MON compte quand pas en live)
|
||||
try { if (!live && window.jOSBoxion && window.jOSBoxion.load){ ['notes','groups','zones'].forEach(function(k){ Promise.resolve(window.jOSBoxion.load(NS,k)).then(function(v){
|
||||
if (Array.isArray(v) && v.length){ if (k==='notes'&&!notes.length) notes=v; if (k==='groups'&&!groups.length) groups=v; if (k==='zones'&&!zones.length) zones=v; renderAll(); }
|
||||
}).catch(function(){}); }); } } catch (e) {}
|
||||
|
||||
// ---------- images ----------
|
||||
function downscale(file,cb){ var img=new Image(),u=URL.createObjectURL(file);
|
||||
img.onload=function(){ var m=1100,w=img.width,h=img.height; if(w>m||h>m){var s=m/Math.max(w,h);w=Math.round(w*s);h=Math.round(h*s);}
|
||||
var c=document.createElement('canvas');c.width=w;c.height=h;c.getContext('2d').drawImage(img,0,0,w,h);URL.revokeObjectURL(u);cb(c.toDataURL('image/jpeg',0.82)); };
|
||||
img.onerror=function(){URL.revokeObjectURL(u);cb(null);};img.src=u; }
|
||||
function upload(file,cb){ var fd=new FormData();fd.append('file',file);
|
||||
fetch('/share-media',{method:'POST',body:fd,headers:{'X-CSRF-TOKEN':csrf(),'X-Requested-With':'XMLHttpRequest'},credentials:'same-origin'})
|
||||
.then(function(r){return r.ok?r.json():null;}).then(function(d){ if(d&&d.url) cb(d.url); else downscale(file,cb); }).catch(function(){ downscale(file,cb); }); }
|
||||
function attachImage(n,file,after){ upload(file,function(u){ if(u){ n.img=u; save(n); after(); } }); }
|
||||
|
||||
// ---------- NOTES ----------
|
||||
function render(n){
|
||||
var el=document.createElement('div'); el.className='pit__n'; el.dataset.id=n.id;
|
||||
el.style.left=n.x+'px'; el.style.top=n.y+'px'; el.style.width=(n.w||200)+'px'; el.style.height=(n.h||150)+'px';
|
||||
el.style.background=n.color; el.style.setProperty('--r',(n.rot||0)+'deg');
|
||||
el.innerHTML='<div class="pit__nh"><span class="pit__dot" title="couleur"></span>'
|
||||
+'<button class="pit__hb" data-fs="-1" title="police -">A−</button><button class="pit__hb" data-fs="1" title="police +">A+</button>'
|
||||
+'<button class="pit__hb" data-img title="image">🖼</button><button class="pit__hb" data-big title="agrandir">⤢</button>'
|
||||
+'<button class="pit__hb pit__x" data-del title="supprimer">✕</button></div>'
|
||||
+(n.img?'<div class="pit__imw"><img class="pit__img" src="'+n.img+'" alt=""><button class="pit__imx" data-imgdel title="retirer l\'image">✕</button></div>':'')
|
||||
+'<textarea class="pit__ta" placeholder="…"></textarea><input type="file" accept="image/*" hidden data-file><div class="pit__rz"></div>';
|
||||
var ta=el.querySelector('.pit__ta'); ta.value=n.text||''; ta.style.fontSize=(n.fs||14)+'px';
|
||||
ta.addEventListener('input',function(){ n.text=ta.value; save(n); });
|
||||
ta.addEventListener('change',function(){ emitNote(n); }); // note terminée (blur) -> murion.inbox
|
||||
el.querySelector('.pit__dot').addEventListener('click',function(e){ openPalette(COLORS,function(c){ n.color=c; el.style.background=c; save(n); }, n.x, n.y, e, n.color); });
|
||||
el.querySelectorAll('[data-fs]').forEach(function(b){ b.addEventListener('click',function(){ n.fs=clamp((n.fs||14)+parseInt(b.dataset.fs,10)*2,10,40); ta.style.fontSize=n.fs+'px'; save(n); }); });
|
||||
var fileIn=el.querySelector('[data-file]'); el.querySelector('[data-img]').addEventListener('click',function(){ fileIn.click(); });
|
||||
fileIn.addEventListener('change',function(){ if(fileIn.files&&fileIn.files[0]) attachImage(n,fileIn.files[0],function(){ rerender(n); }); });
|
||||
var imd=el.querySelector('[data-imgdel]'); if(imd) imd.addEventListener('click',function(e){ e.stopPropagation(); n.img=null; save(n); rerender(n); });
|
||||
ta.addEventListener('paste',function(e){ var it=(e.clipboardData||{}).items||[]; for(var i=0;i<it.length;i++){ if(it[i].type&&it[i].type.indexOf('image')===0){ var f=it[i].getAsFile(); if(f){ e.preventDefault(); attachImage(n,f,function(){ rerender(n); }); return; } } } });
|
||||
el.querySelector('[data-big]').addEventListener('click',function(){ openBig(n); });
|
||||
el.querySelector('[data-del]').addEventListener('click',function(){ notes=notes.filter(function(m){return m.id!==n.id;}); addDel(n.id); el.remove(); save(); refreshHint(); });
|
||||
var im=el.querySelector('.pit__img'); if(im) im.addEventListener('click',function(){ openBig(n); });
|
||||
if (sel[n.id]) el.classList.add('sel');
|
||||
el.addEventListener('pointerdown',function(e){ if(e.ctrlKey||e.metaKey||e.shiftKey){ e.preventDefault(); e.stopPropagation(); toggleSel(n.id); } },true);
|
||||
noteDrag(el.querySelector('.pit__nh'), el, n);
|
||||
resizify(el.querySelector('.pit__rz'), el, n, 130, 90);
|
||||
world.appendChild(el); return el;
|
||||
}
|
||||
function rerender(n){ var o=world.querySelector('.pit__n[data-id="'+n.id+'"]'); if(o) o.remove(); render(n); }
|
||||
|
||||
// ---------- GROUPES (contiennent les post-it) ----------
|
||||
function rectOf(g){ return { x:g.x, y:g.y, w:g.w||340, h:g.h||260 }; }
|
||||
function noteCenter(n){ return { x:n.x+(n.w||200)/2, y:n.y+(n.h||150)/2 }; }
|
||||
function inRect(c,r){ return c.x>=r.x && c.x<=r.x+r.w && c.y>=r.y && c.y<=r.y+r.h; }
|
||||
function assignGroup(n){ var c=noteCenter(n), g=null; groups.forEach(function(gr){ if(inRect(c,rectOf(gr))) g=gr; }); n.gid=g?g.id:null; }
|
||||
function groupMembers(g){ return notes.filter(function(n){ return n.gid===g.id || inRect(noteCenter(n),rectOf(g)); }); }
|
||||
function renderGroup(g){
|
||||
var el=document.createElement('div'); el.className='pit__grp'; el.dataset.id=g.id;
|
||||
el.style.left=g.x+'px'; el.style.top=g.y+'px'; el.style.width=(g.w||340)+'px'; el.style.height=(g.h||260)+'px'; el.style.setProperty('--gc',g.color||'#5a6e8e');
|
||||
el.innerHTML='<div class="pit__grph"><span class="pit__gdot" title="couleur"></span><input class="pit__gtitle" value="'+(g.title||'Groupe').replace(/"/g,'"')+'" size="'+Math.max(6,(g.title||'Groupe').length)+'"><button class="pit__gx" title="supprimer">✕</button></div><div class="pit__rz"></div>';
|
||||
var ti=el.querySelector('.pit__gtitle'); ti.addEventListener('input',function(){ g.title=ti.value; ti.size=Math.max(6,ti.value.length); save(g); });
|
||||
el.querySelector('.pit__gdot').addEventListener('click',function(e){ openPalette(GCOLORS,function(c){ g.color=c; el.style.setProperty('--gc',c); save(g); }, g.x, g.y, e, g.color); });
|
||||
el.querySelector('.pit__gx').addEventListener('click',function(){ groups=groups.filter(function(m){return m.id!==g.id;}); addDel(g.id); el.remove(); save(); refreshHint(); });
|
||||
groupDrag(el.querySelector('.pit__grph'), el, g);
|
||||
resizify(el.querySelector('.pit__rz'), el, g, 160, 110);
|
||||
world.appendChild(el); return el;
|
||||
}
|
||||
// drag d'un groupe : déplace le groupe ET ses post-it membres
|
||||
function groupDrag(handle, el, g){ var d=null;
|
||||
handle.addEventListener('pointerdown',function(e){ if(e.target.closest('.pit__gx,.pit__gdot,.pit__gtitle')) return;
|
||||
var mem=groupMembers(g).map(function(n){ return { n:n, ox:n.x, oy:n.y, el:world.querySelector('.pit__n[data-id="'+n.id+'"]') }; });
|
||||
d={ px:e.clientX, py:e.clientY, ox:g.x, oy:g.y, mem:mem }; handle.setPointerCapture(e.pointerId); el.style.zIndex=50; e.stopPropagation(); });
|
||||
handle.addEventListener('pointermove',function(e){ if(!d) return; var dx=(e.clientX-d.px)/view.s, dy=(e.clientY-d.py)/view.s;
|
||||
g.x=Math.max(0,d.ox+dx); g.y=Math.max(0,d.oy+dy); el.style.left=g.x+'px'; el.style.top=g.y+'px';
|
||||
d.mem.forEach(function(s){ s.n.x=Math.max(0,s.ox+dx); s.n.y=Math.max(0,s.oy+dy); if(s.el){ s.el.style.left=s.n.x+'px'; s.el.style.top=s.n.y+'px'; } }); });
|
||||
handle.addEventListener('pointerup',function(e){ if(!d) return; var mem=d.mem; d=null; el.style.zIndex=''; try{handle.releasePointerCapture(e.pointerId);}catch(_){}
|
||||
g.m=now(); mem.forEach(function(s){ s.n.gid=g.id; s.n.m=now(); }); writeLocal(); if(live) pushSoon(); }); }
|
||||
|
||||
// ---------- ZONES (background) ----------
|
||||
function renderZone(z){
|
||||
var el=document.createElement('div'); el.className='pit__zone'; el.dataset.id=z.id;
|
||||
el.style.left=z.x+'px'; el.style.top=z.y+'px'; el.style.width=(z.w||520)+'px'; el.style.height=(z.h||400)+'px';
|
||||
if (z.img) el.style.setProperty('--zb','center/cover no-repeat url("'+z.img+'")'); else if (z.bg) el.style.setProperty('--zb', z.bg);
|
||||
el.innerHTML='<div class="pit__zoneh"><span class="pit__gdot" title="fond"></span><input value="'+(z.title||'Zone').replace(/"/g,'"')+'" size="'+Math.max(5,(z.title||'Zone').length)+'"><button class="pit__hb" data-zimg title="image de fond" style="color:rgba(200,224,255,.8)">🖼</button><button class="pit__gx" title="supprimer">✕</button></div><input type="file" accept="image/*" hidden data-zfile><div class="pit__rz"></div>';
|
||||
var ti=el.querySelector('input:not([type=file])'); ti.addEventListener('input',function(){ z.title=ti.value; ti.size=Math.max(5,ti.value.length); save(z); });
|
||||
el.querySelector('.pit__gdot').addEventListener('click',function(e){ openPalette(['#1b2436','#2a1f3a','#10241c','#2a2410','#241016','#0e1f2e','#1a1a22'],function(c){ z.bg='color-mix(in srgb,'+c+' 70%, transparent)'; z.img=null; el.style.setProperty('--zb',z.bg); save(z); }, z.x, z.y, e, '#1b2436'); });
|
||||
var zf=el.querySelector('[data-zfile]'); el.querySelector('[data-zimg]').addEventListener('click',function(){ zf.click(); });
|
||||
zf.addEventListener('change',function(){ if(zf.files&&zf.files[0]) upload(zf.files[0],function(u){ if(u){ z.img=u; z.bg=null; el.style.setProperty('--zb','center/cover no-repeat url("'+u+'")'); save(z); } }); });
|
||||
el.querySelector('.pit__gx').addEventListener('click',function(){ zones=zones.filter(function(m){return m.id!==z.id;}); addDel(z.id); el.remove(); save(); refreshHint(); });
|
||||
dragZone(el.querySelector('.pit__zoneh'), el, z);
|
||||
resizify(el.querySelector('.pit__rz'), el, z, 220, 180);
|
||||
world.appendChild(el); return el;
|
||||
}
|
||||
function dragZone(handle, el, z){ var d=null;
|
||||
handle.addEventListener('pointerdown',function(e){ if(e.target.closest('.pit__gx,.pit__gdot,.pit__hb')||e.target.tagName==='INPUT') return;
|
||||
d={ px:e.clientX, py:e.clientY, ox:z.x, oy:z.y }; handle.setPointerCapture(e.pointerId); e.stopPropagation(); });
|
||||
handle.addEventListener('pointermove',function(e){ if(!d) return; z.x=Math.max(0,d.ox+(e.clientX-d.px)/view.s); z.y=Math.max(0,d.oy+(e.clientY-d.py)/view.s); el.style.left=z.x+'px'; el.style.top=z.y+'px'; });
|
||||
handle.addEventListener('pointerup',function(e){ if(!d) return; d=null; try{handle.releasePointerCapture(e.pointerId);}catch(_){} save(z); }); }
|
||||
|
||||
function renderAll(){ world.innerHTML=''; zones.forEach(renderZone); groups.forEach(renderGroup); notes.forEach(render); applySel(); refreshHint(); }
|
||||
|
||||
// ---------- resize générique (coords monde) ----------
|
||||
function resizify(rz, el, obj, minW, minH){ minW=minW||130; minH=minH||90; var r=null;
|
||||
rz.addEventListener('pointerdown',function(e){ e.stopPropagation(); r={x:e.clientX,y:e.clientY,w:obj.w||200,h:obj.h||150}; rz.setPointerCapture(e.pointerId); });
|
||||
rz.addEventListener('pointermove',function(e){ if(!r) return; obj.w=Math.max(minW,r.w+(e.clientX-r.x)/view.s); obj.h=Math.max(minH,r.h+(e.clientY-r.y)/view.s); el.style.width=obj.w+'px'; el.style.height=obj.h+'px'; });
|
||||
rz.addEventListener('pointerup',function(e){ if(!r) return; r=null; try{rz.releasePointerCapture(e.pointerId);}catch(_){} save(obj); }); }
|
||||
|
||||
// ---------- multi-sélection ----------
|
||||
var sel={};
|
||||
function selCount(){ return Object.keys(sel).length; }
|
||||
function byId(id){ for(var i=0;i<notes.length;i++) if(notes[i].id===id) return notes[i]; return null; }
|
||||
function applySel(){ world.querySelectorAll('.pit__n').forEach(function(el){ el.classList.toggle('sel',!!sel[el.dataset.id]); }); updateSelbar(); }
|
||||
function toggleSel(id){ if(sel[id]) delete sel[id]; else sel[id]=1; applySel(); }
|
||||
function clearSel(){ if(!selCount()) return; sel={}; applySel(); }
|
||||
function updateSelbar(){ var n=selCount(); selbar.hidden=n<1; if(n) container.querySelector('[data-selc]').textContent=n; }
|
||||
// drag d'une note (souris ET tactile). La sélection n'est PAS décidée au pointerdown
|
||||
// (sinon l'appui long casserait) : on attend un VRAI mouvement (>6px) pour démarrer le
|
||||
// drag. APPUI LONG (450ms sans bouger) = (dé)sélectionner. TAP en mode sélection = ajouter.
|
||||
function noteDrag(handle, el, n){ var st=null, moved=false, set=null, lpT=null, lpFired=false;
|
||||
handle.addEventListener('pointerdown',function(e){ if(e.target.closest('.pit__hb')||e.target.classList.contains('pit__dot')) return;
|
||||
if(e.ctrlKey||e.metaKey||e.shiftKey) return; // desktop : géré par le capture
|
||||
st={px:e.clientX,py:e.clientY}; moved=false; set=null; lpFired=false; handle.setPointerCapture(e.pointerId);
|
||||
lpT=setTimeout(function(){ if(!moved){ lpFired=true; toggleSel(n.id); if(navigator.vibrate) try{navigator.vibrate(14);}catch(_){} } },450);
|
||||
e.stopPropagation(); });
|
||||
handle.addEventListener('pointermove',function(e){ if(!st||lpFired) return; var dx=(e.clientX-st.px)/view.s, dy=(e.clientY-st.py)/view.s;
|
||||
if(!moved){ if(Math.abs(e.clientX-st.px)+Math.abs(e.clientY-st.py)<6) return; moved=true; clearTimeout(lpT);
|
||||
var ids=(sel[n.id]&&selCount()>1)?Object.keys(sel):(clearSel(),[n.id]);
|
||||
set=ids.map(function(id){ var m=byId(id); return m?{id:id,ox:m.x,oy:m.y,el:world.querySelector('.pit__n[data-id="'+id+'"]')}:null; }).filter(Boolean); el.style.zIndex=50; }
|
||||
set.forEach(function(s){ var m=byId(s.id); if(!m||!s.el) return; m.x=Math.max(0,s.ox+dx); m.y=Math.max(0,s.oy+dy); s.el.style.left=m.x+'px'; s.el.style.top=m.y+'px'; }); });
|
||||
handle.addEventListener('pointerup',function(e){ clearTimeout(lpT); try{handle.releasePointerCapture(e.pointerId);}catch(_){}
|
||||
if(moved&&set){ el.style.zIndex=''; set.forEach(function(s){ var m=byId(s.id); if(m){ assignGroup(m); m.m=now(); } }); writeLocal(); if(live) pushSoon(); }
|
||||
else if(!lpFired && selCount()>0){ toggleSel(n.id); } // tap en mode sélection = ajouter/retirer
|
||||
st=null; });
|
||||
handle.addEventListener('pointercancel',function(){ clearTimeout(lpT); st=null; el.style.zIndex=''; }); }
|
||||
|
||||
// ---------- palette ----------
|
||||
function openPalette(palette, set, ax, ay, ev, cur){ closePalette();
|
||||
var p=document.createElement('div'); p.className='pit__pal';
|
||||
p.innerHTML=palette.map(function(c){ return '<span class="pit__sw" style="background:'+c+'" data-c="'+c+'"></span>'; }).join('')+'<input type="color" value="'+(cur||palette[0])+'">';
|
||||
p.style.left=clamp(ax+8,0,(board.clientWidth-180)/view.s)+'px'; p.style.top=(ay+30)+'px'; world.appendChild(p);
|
||||
p.querySelectorAll('[data-c]').forEach(function(s){ s.addEventListener('click',function(){ set(s.dataset.c); closePalette(); }); });
|
||||
p.querySelector('input').addEventListener('input',function(e){ set(e.target.value); });
|
||||
setTimeout(function(){ document.addEventListener('pointerdown',closePalette,{once:true}); },0); if(ev) ev.stopPropagation(); }
|
||||
function closePalette(){ var p=world.querySelector('.pit__pal'); if(p) p.remove(); }
|
||||
|
||||
// ---------- agrandir ----------
|
||||
function openBig(n){
|
||||
ovEl.innerHTML='<div class="pit__big" style="background:'+n.color+'"><div class="pit__bigh"><span class="pit__dot" data-bc></span><button class="pit__hb" data-bfs="-1">A−</button><button class="pit__hb" data-bfs="1">A+</button><button class="pit__hb" data-bimg>🖼</button><span style="flex:1"></span><button class="pit__hb" data-bx title="fermer">✕</button></div>'
|
||||
+(n.img?'<div class="pit__imw"><img src="'+n.img+'" alt=""><button class="pit__imx" data-bimgdel>✕</button></div>':'')
|
||||
+'<textarea placeholder="…"></textarea><input type="file" accept="image/*" hidden data-bfile></div>';
|
||||
ovEl.classList.add('on');
|
||||
var ta=ovEl.querySelector('textarea'); ta.value=n.text||''; ta.style.fontSize=Math.max(16,(n.fs||14)+2)+'px';
|
||||
ta.addEventListener('input',function(){ n.text=ta.value; save(n); var live2=world.querySelector('.pit__n[data-id="'+n.id+'"] .pit__ta'); if(live2) live2.value=n.text; });
|
||||
ta.addEventListener('change',function(){ emitNote(n); }); // note terminée (blur) -> murion.inbox
|
||||
ovEl.querySelector('[data-bc]').style.background=n.color;
|
||||
ovEl.querySelector('[data-bc]').addEventListener('click',function(){ openPalette(COLORS,function(c){ n.color=c; ovEl.querySelector('.pit__big').style.background=c; ovEl.querySelector('[data-bc]').style.background=c; var l=world.querySelector('.pit__n[data-id="'+n.id+'"]'); if(l) l.style.background=c; save(n); },0,0,null,n.color); });
|
||||
ovEl.querySelectorAll('[data-bfs]').forEach(function(b){ b.addEventListener('click',function(){ n.fs=clamp((n.fs||14)+parseInt(b.dataset.bfs,10)*2,10,40); ta.style.fontSize=Math.max(16,n.fs+2)+'px'; save(n); }); });
|
||||
var bf=ovEl.querySelector('[data-bfile]'); ovEl.querySelector('[data-bimg]').addEventListener('click',function(){ bf.click(); });
|
||||
bf.addEventListener('change',function(){ if(bf.files&&bf.files[0]) attachImage(n,bf.files[0],function(){ openBig(n); rerender(n); }); });
|
||||
var bid=ovEl.querySelector('[data-bimgdel]'); if(bid) bid.addEventListener('click',function(){ n.img=null; save(n); openBig(n); rerender(n); });
|
||||
ovEl.querySelector('[data-bx]').addEventListener('click',closeBig); }
|
||||
function closeBig(){ ovEl.classList.remove('on'); ovEl.innerHTML=''; }
|
||||
ovEl.addEventListener('click',function(e){ if(e.target===ovEl) closeBig(); });
|
||||
|
||||
// ---------- zoom / pan ----------
|
||||
applyView();
|
||||
var pan=null, ptrs={}, pinch=null;
|
||||
board.addEventListener('pointerdown',function(e){ if(e.target.closest('.pit__n,.pit__grp,.pit__zone,.pit__pal,.pit__selbar')) return;
|
||||
clearSel(); board.setPointerCapture(e.pointerId); ptrs[e.pointerId]={x:e.clientX,y:e.clientY};
|
||||
var k=Object.keys(ptrs); if(k.length===1){ pan={x:e.clientX-view.x,y:e.clientY-view.y}; board.classList.add('grab'); } else if(k.length===2){ pinch=startPinch(k); pan=null; } });
|
||||
// diffuse MON curseur (au survol/déplacement) quand le Live est actif -> les autres le voient
|
||||
board.addEventListener('pointermove',function(e){ if(live && presHandle){ var r=rect(); presHandle.cursor((e.clientX-r.left-view.x)/view.s,(e.clientY-r.top-view.y)/view.s); } });
|
||||
board.addEventListener('pointermove',function(e){ if(!ptrs[e.pointerId]) return; ptrs[e.pointerId]={x:e.clientX,y:e.clientY};
|
||||
var k=Object.keys(ptrs); if(pinch&&k.length>=2){ doPinch(k); return; } if(pan){ view.x=e.clientX-pan.x; view.y=e.clientY-pan.y; applyView(); } });
|
||||
function up(e){ delete ptrs[e.pointerId]; if(Object.keys(ptrs).length<2) pinch=null; if(!Object.keys(ptrs).length){ if(pan){pan=null;saveView();} board.classList.remove('grab'); } }
|
||||
board.addEventListener('pointerup',up); board.addEventListener('pointercancel',up);
|
||||
function rect(){ return board.getBoundingClientRect(); }
|
||||
function startPinch(k){ var a=ptrs[k[0]],b=ptrs[k[1]]; return {d:Math.hypot(a.x-b.x,a.y-b.y),s:view.s,cx:(a.x+b.x)/2,cy:(a.y+b.y)/2,vx:view.x,vy:view.y}; }
|
||||
function doPinch(k){ var a=ptrs[k[0]],b=ptrs[k[1]],dd=Math.hypot(a.x-b.x,a.y-b.y),r=rect();
|
||||
var ns=clamp(pinch.s*dd/pinch.d,0.15,2.6),cx=pinch.cx-r.left,cy=pinch.cy-r.top,wx=(cx-pinch.vx)/pinch.s,wy=(cy-pinch.vy)/pinch.s; view.s=ns; view.x=cx-wx*ns; view.y=cy-wy*ns; applyView(); saveView(); }
|
||||
board.addEventListener('wheel',function(e){ e.preventDefault(); var r=rect(),mx=e.clientX-r.left,my=e.clientY-r.top;
|
||||
var ns=clamp(view.s*(e.deltaY<0?1.12:0.89),0.15,2.6),wx=(mx-view.x)/view.s,wy=(my-view.y)/view.s; view.s=ns; view.x=mx-wx*ns; view.y=my-wy*ns; applyView(); saveView(); },{passive:false});
|
||||
function zoomBtn(dir){ var r=rect(),mx=r.width/2,my=r.height/2; if(dir===0){ view={x:40,y:30,s:1}; } else { var ns=clamp(view.s*(dir>0?1.2:0.83),0.15,2.6),wx=(mx-view.x)/view.s,wy=(my-view.y)/view.s; view.s=ns; view.x=mx-wx*ns; view.y=my-wy*ns; } applyView(); saveView(); }
|
||||
container.querySelectorAll('[data-z]').forEach(function(b){ b.addEventListener('click',function(){ zoomBtn(parseInt(b.dataset.z,10)); }); });
|
||||
|
||||
renderAll(); histInit();
|
||||
undoBtn.addEventListener('click', undo); redoBtn.addEventListener('click', redo);
|
||||
|
||||
root.querySelector('[data-add]').addEventListener('click',function(){ var c=worldCenter(); var n={id:uid(),x:Math.round(c.x-100),y:Math.round(c.y-75),w:200,h:150,color:COLORS[notes.length%COLORS.length],rot:(notes.length%5-2),text:'',fs:14}; assignGroup(n); notes.push(n); save(n); refreshHint(); render(n).querySelector('.pit__ta').focus(); });
|
||||
root.querySelector('[data-grp]').addEventListener('click',function(){ var c=worldCenter(); var g={id:uid(),x:Math.round(c.x-170),y:Math.round(c.y-130),w:340,h:260,color:GCOLORS[groups.length%GCOLORS.length],title:'Groupe'}; groups.push(g); save(g); refreshHint(); renderGroup(g); });
|
||||
root.querySelector('[data-zone]').addEventListener('click',function(){ var c=worldCenter(); var z={id:uid(),x:Math.round(c.x-260),y:Math.round(c.y-200),w:520,h:400,title:'Zone',bg:'color-mix(in srgb,#1b2436 70%, transparent)'}; zones.push(z); save(z); refreshHint(); renderZone(z); });
|
||||
root.querySelector('[data-clear]').addEventListener('click',function(){ if((!notes.length&&!groups.length&&!zones.length)||!confirm('Vider tout le mur ?')) return;
|
||||
notes.concat(groups).concat(zones).forEach(function(o){ addDel(o.id); }); notes=[]; groups=[]; zones=[]; save(); world.innerHTML=''; refreshHint(); });
|
||||
liveBtn.addEventListener('click',function(){ if(live){ showLiveP(); } else { setLive(true); showLiveP(); } });
|
||||
|
||||
// sélection : barre d'actions
|
||||
function applyColorToSel(c){ Object.keys(sel).forEach(function(id){ var m=byId(id); if(!m) return; m.color=c; m.m=now(); var el=world.querySelector('.pit__n[data-id="'+id+'"]'); if(el) el.style.background=c; }); writeLocal(); if(live) pushSoon(); }
|
||||
container.querySelector('[data-selclr]').addEventListener('click',clearSel);
|
||||
container.querySelector('[data-seldel]').addEventListener('click',function(){ var ids=Object.keys(sel); if(!ids.length) return; notes=notes.filter(function(m){return !sel[m.id];}); ids.forEach(function(id){ addDel(id); var el=world.querySelector('.pit__n[data-id="'+id+'"]'); if(el) el.remove(); }); clearSel(); save(); refreshHint(); });
|
||||
container.querySelector('[data-selcol]').addEventListener('click',function(){ var ex=root.querySelector('.pit__selpal'); if(ex){ ex.remove(); return; }
|
||||
var p=document.createElement('div'); p.className='pit__pal pit__selpal'; p.style.cssText='position:absolute;left:50%;bottom:52px;transform:translateX(-50%);z-index:71';
|
||||
p.innerHTML=COLORS.map(function(c){ return '<span class="pit__sw" style="background:'+c+'" data-c="'+c+'"></span>'; }).join('')+'<input type="color">';
|
||||
root.appendChild(p); p.querySelectorAll('[data-c]').forEach(function(s){ s.addEventListener('click',function(){ applyColorToSel(s.dataset.c); p.remove(); }); }); p.querySelector('input').addEventListener('input',function(e){ applyColorToSel(e.target.value); }); });
|
||||
function onKey(e){ var t=e.target, typing=t&&(t.tagName==='TEXTAREA'||t.tagName==='INPUT'||t.isContentEditable);
|
||||
if ((e.ctrlKey||e.metaKey) && (e.key==='z'||e.key==='Z')){ if (typing) return; e.preventDefault(); if (e.shiftKey) redo(); else undo(); return; }
|
||||
if ((e.ctrlKey||e.metaKey) && (e.key==='y'||e.key==='Y')){ if (typing) return; e.preventDefault(); redo(); return; }
|
||||
if (!selCount()||(e.key!=='Delete'&&e.key!=='Backspace')) return; if (typing) return; e.preventDefault(); container.querySelector('[data-seldel]').click(); }
|
||||
document.addEventListener('keydown',onKey);
|
||||
|
||||
// ---------- mur lié au COMPTE SSO (même mur sur tous mes appareils) ----------
|
||||
function authed(){ var m=document.querySelector('meta[name=user-authenticated]'); return m && m.content==='1'; }
|
||||
if (urlWall) { setLive(true); } // lien d'invitation -> ce mur, en live
|
||||
else if (authed()) { // connecté -> mon mur perso SSO
|
||||
fetch('/wall/mine', { headers:{Accept:'application/json'}, credentials:'same-origin' })
|
||||
.then(function(r){ return r.ok?r.json():null; })
|
||||
.then(function(d){ if (d && d.code){ wall=d.code; try{ localStorage.setItem(WKEY,JSON.stringify(wall)); }catch(e){}
|
||||
setLive(true); // push (seed/merge) + poll -> ordi/tel/tablette = MÊME mur
|
||||
} else if (live) setLive(true); })
|
||||
.catch(function(){ if (live) setLive(true); });
|
||||
}
|
||||
else if (live) setLive(true); // anonyme : reprend le mur live local si activé
|
||||
|
||||
return { unmount:function(){ document.removeEventListener('keydown',onKey); if(pollIv) clearInterval(pollIv); if(presHandle) presHandle.leave(); container.innerHTML=''; } };
|
||||
}
|
||||
|
||||
// ===== XUI (contrat v0, bion jOSXui) : describe() = mon mur de post-its, non monté =====
|
||||
// p1 = combien de post-its sur le mur (LA donnée maîtresse : xb:post-it, localStorage) ;
|
||||
// p2 = les derniers écrits ; p3 = groupes/zones. Pur, jamais le DOM, ne throw jamais.
|
||||
function describe(){
|
||||
var items=[];
|
||||
try{
|
||||
var notes=ls(KEY,[]), groups=ls(GKEY,[]), zones=ls(ZKEY,[]);
|
||||
items.push({ p:1, kind:'stat', label:'📌 post-its', value:notes.length });
|
||||
var last=notes.slice().sort(function(a,b){ return (b.at||0)-(a.at||0); }).slice(0,3)
|
||||
.filter(function(n){ return n && (n.text||'').trim(); });
|
||||
if(last.length) items.push({ p:2, kind:'list', label:'derniers', items:last.map(function(n){
|
||||
return { label:'▪', value:String(n.text).slice(0,60) }; }) });
|
||||
if(groups.length) items.push({ p:3, kind:'stat', label:'groupes', value:groups.length });
|
||||
if(zones.length) items.push({ p:3, kind:'stat', label:'zones', value:zones.length });
|
||||
var live = ls(LKEY,'0')==='1';
|
||||
items.push({ p:4, kind:'text', label:'mur', value:live?'live (partagé)':'perso (local)' });
|
||||
}catch(e){ items=[{ p:1, kind:'text', label:'📌 post-its', value:'mur indisponible' }]; }
|
||||
return { v:1, id:'post-it', title:'Post-it', icon:'📌', items:items };
|
||||
}
|
||||
|
||||
window.jOSApps = window.jOSApps || {};
|
||||
window.jOSApps['post-it'] = { manifest:{ id:'post-it', name:'Post-it', icon:'📌' }, mount:mount, describe:describe };
|
||||
|
||||
// deep-link : ?px=post-it (+ &wall=<code> pour rejoindre un mur partagé) -> auto-ouvre
|
||||
try { if (new URLSearchParams(location.search).get('px')==='post-it'){ var t=0,iv=setInterval(function(){
|
||||
if ((window.jOSMobile&&window.jOSMobile.open('post-it','Post-it'))||(window.jOS&&window.jOS.openPloxion&&window.jOS.openPloxion('post-it'))||++t>50) clearInterval(iv); },150); } } catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user