Widget:ProjectLabel: Difference between revisions

From Makerpedia

No edit summary
No edit summary
 
(35 intermediate revisions by the same user not shown)
Line 3: Line 3:
   if(pageParams["page"]){
   if(pageParams["page"]){
     mw.loader.using(['mediawiki.api', 'jquery']).then(()=>{
     mw.loader.using(['mediawiki.api', 'jquery']).then(()=>{
var logo = "https://makerspace.cc/wiki/images/LogoLarge.png";
       new mw.Api().get({
       new mw.Api().get({
           action: 'query',
           action: 'query',
Line 14: Line 17:
           var pageUrl = mw.util.getUrl(pageParams["page"]);
           var pageUrl = mw.util.getUrl(pageParams["page"]);
           var badges = [];
           var badges = [];
           ProjectTitle.textContent = pageParams["page"];
 
          QRLink.src = "https://quickchart.io/qr?text=https://makerspace.cc"+pageUrl+"&centerImageUrl="+logo+"&size=200x200&dark=003069&light=FFFFFF"
 
           ProjectTitle.textContent = pageParams["page"].split("(")[0].replaceAll('_', ' ');
 
           const regex = /\[\[Category:(.*?)\]\]/gi;
           const regex = /\[\[Category:(.*?)\]\]/gi;
           let cats = content.match(regex);
           let cats = content.match(regex);
Line 32: Line 39:
             Badges.appendChild(bdg);
             Badges.appendChild(bdg);
           })
           })
          if(badges.length>4) Badges.classList.add("fivePlus");
           //μ('.badgeBox')[0].textContent = "weee";
           //μ('.badgeBox')[0].textContent = "weee";
       });
       });
Line 47: Line 55:
   width:525px;
   width:525px;
   height: 400px;
   height: 400px;
   --cc-badge-size: 100px;
   --cc-badge-size: 110px;
}
}


#projectLabel>img{
#labelFrame{
   position: absolute;
   position: absolute;
   left: 0;
   left: 0;
Line 58: Line 66:
}
}


#projectTitle{
#ProjectTitle{
   position: absolute;
   position: absolute;
   left: 18px;
   left: 18px;
Line 66: Line 74:
   text-align: center;
   text-align: center;
   line-height: 78px;
   line-height: 78px;
   font-family: serif;
   font-family: sans-serif;
   font-size:48px;
   font-size:36px;
  color: #003069;
  font-weight: bolder;
}
}


Line 76: Line 86:
   width: 244px;
   width: 244px;
   height: 234px;
   height: 234px;
}
.badgeBox.fivePlus {
  --cc-badge-size: 66px;
}
}


Line 82: Line 96:
   height: var(--cc-badge-size);
   height: var(--cc-badge-size);
   width:var(--cc-badge-size);
   width:var(--cc-badge-size);
   margin: 10px;
   margin: 5px;
}
 
#QRLink {
  position: absolute;
  left:280px;
  top: 158px;
  height: 200px;
  width: 200px;
}
}
</style>
</style>
<div id="projectLabel">
<div id="projectLabel">
   <img src="images/frames/projectLabelFrame.png"></img>
   <img id="labelFrame" src="images/frames/projectLabelFrame.png"></img>
   <div id="ProjectTitle">Test</div>
   <div id="ProjectTitle">Test</div>
  <div class="badgeBox" id="Badges">
    <img id="QRLink"></img>
    <div class="badgeBox" id="Badges">
   </div>
   </div>
 
</div>
</div>

Latest revision as of 14:10, 28 March 2025

<script> function appStart(){

 if(pageParams["page"]){
   mw.loader.using(['mediawiki.api', 'jquery']).then(()=>{

var logo = "LogoLarge.png";

     new mw.Api().get({
         action: 'query',
         prop: 'revisions',
         rvprop: 'content',
         titles: pageParams["page"],
         format: 'json'
     }).done(function (pageData) {
         var pageId = Object.keys(pageData.query.pages)[0];
         var content = pageData.query.pages[pageId].revisions[0]['*'];
         var pageUrl = mw.util.getUrl(pageParams["page"]);
         var badges = [];
         QRLink.src = "https://quickchart.io/qr?text=https://makerspace.cc"+pageUrl+"&centerImageUrl="+logo+"&size=200x200&dark=003069&light=FFFFFF"
         ProjectTitle.textContent = pageParams["page"].split("(")[0].replaceAll('_', ' ');
         const regex = /\[\[Category:(.*?)\]\]/gi;
         let cats = content.match(regex);
         cats = cats.map(match => /\[\[Category:(.*?)\]\]/i.exec(match)[1]);
         console.log(cats);
         cats.forEach(cat=>{
           makerSkills.forEach(skill=>{
             if(cat == skill.name) badges.push(skill.image);
           });
         });
         console.log(badges);
         badges.forEach(el=>{
           let bdg = document.createElement('img');
           bdg.src = el;
           Badges.appendChild(bdg);
         })
         if(badges.length>4) Badges.classList.add("fivePlus");
         //μ('.badgeBox')[0].textContent = "weee";
     });
   });
 }

}


if(!window.widgets) window.widgets = []; window.widgets.push(appStart); </script> <style>

  1. projectLabel {
 position: relative;
 width:525px;
 height: 400px;
 --cc-badge-size: 110px;

}

  1. labelFrame{
 position: absolute;
 left: 0;
 top: 0;
 width:525px;
 height: 400px;

}

  1. ProjectTitle{
 position: absolute;
 left: 18px;
 top: 18px;
 width: calc(525px - 36px);
 height: 78px;
 text-align: center;
 line-height: 78px;
 font-family: sans-serif;
 font-size:36px;
 color: #003069;
 font-weight: bolder;

}

.badgeBox {

 position: absolute; 
 left: 18px;
 top: 148px;
 width: 244px;
 height: 234px;

}

.badgeBox.fivePlus {

 --cc-badge-size: 66px;

}

.badgeBox img {

 display: inline-block;
 height: var(--cc-badge-size);
 width:var(--cc-badge-size);
 margin: 5px;

}

  1. QRLink {
 position: absolute;
 left:280px;
 top: 158px;
 height: 200px;
 width: 200px;

} </style>

 <img id="labelFrame" src="images/frames/projectLabelFrame.png"></img>
Test
   <img id="QRLink"></img>