← Commit history

symbol viewer: speak the lbr-hover bus (post hovered pin, light pins the footprint posts) so symbol and footprint highlight together

John Lauer ·b1dd869821 · ·parent 842d98c
1 file changed +8−2
viewers/symbol.html+8−2
@@ -4284,6 +4284,12 @@ var PINS=[{"angle":0,"color":"#ef5350","desc":"","length":2.54,"name":"VIN","num   var NS='http://www.w3.org/2000/svg';   var tip=document.getElementById('tip');   var textMap=new Map();+  // lbr-hover bus (same contract as adom-lbr's footprint and 3D viewers): post the hovered pin to the+  // page, and light a pin when another viewer posts one, so symbol and footprint highlight together.+  function lbrPost(n){ try{ parent.postMessage({type:'lbr-hover', pin:n==null?null:String(n), mpn:(PINS&&PINS.mpn)||document.title}, '*'); }catch(_){} }+  window.addEventListener('message', function(e){ var d=e.data||{}; if(d.type!=='lbr-hover') return;+    var q=d.pin==null?null:PINS.filter(function(x){ return String(x.number)===String(d.pin); })[0];+    if(q) highlightPin(q); else if(typeof clearHL==='function') clearHL(); });   function highlightPin(p){     clearHL();     [p.name,p.number].forEach(function(k){ var a=textMap.get(AdomSymViewer.norm(k)); if(a) a.forEach(function(g){ g.classList.add('hl'); }); });@@ -4314,9 +4320,9 @@ var PINS=[{"angle":0,"color":"#ef5350","desc":"","length":2.54,"name":"VIN","num     if(!document.getElementById('pinmark')){ var pm=document.createElementNS(NS,'circle'); pm.id='pinmark'; svg.appendChild(pm); }     var hideT=null;     var hits=AdomSymViewer.buildPinHits(svg, PINS, OFF, NS, {-      enter:function(p,ev){ clearTimeout(hideT); showTip(p,ev.clientX,ev.clientY); highlightPin(p); },+      enter:function(p,ev){ clearTimeout(hideT); showTip(p,ev.clientX,ev.clientY); highlightPin(p); lbrPost(p.number); },       move:function(ev){ if(tip.classList.contains('show')) posTip(ev.clientX,ev.clientY); },-      leave:function(){ clearTimeout(hideT); hideT=setTimeout(hideTip,45); }+      leave:function(){ clearTimeout(hideT); hideT=setTimeout(hideTip,45); lbrPost(null); }     });     textMap=hits.textMap;   }