PageSourceSearch

https://itpnews.com/persian/wp-content/plugins/itp-companies-previ…/assets/itp-companies.js?ver=0.5.0

js itpnews.com collected 2026-10-03 23:05:02 UTC 3,332 bytes, 49 lines download raw bytes

1(function(){
2 function norm(s){return String(s||'').toLowerCase().replace(/ي/g,'ی').replace(/ى/g,'ی').replace(/ك/g,'ک').replace(/\s+/g,' ').trim();}
3 function init(section){
4  var grid=section.querySelector('.itp-companies-grid');
5  var resultGrid=section.querySelector('.itp-companies-results-grid');
6  var search=section.querySelector('.itp-companies-search');
7  var status=section.querySelector('.itp-companies-search-status');
8  var catGrid=section.querySelector('.itp-company-category-grid');
9  var data=[], cats=[];
10  try{data=JSON.parse(section.getAttribute('data-companies')||'[]');cats=JSON.parse(section.getAttribute('data-categories')||'[]')}catch(e){return}
11  function shuffle(a){a=a.slice();for(var i=a.length-1;i>0;i--){var j=Math.floor(Math.random()*(i+1)),t=a[i];a[i]=a[j];a[j]=t}return a}
12  function card(item){
13   var card=document.createElement('article');card.className='itp-company-card';
14   var name=document.createElement('div');name.className='itp-company-name';name.textContent=item.name||'';
15   var a=document.createElement('a');a.className='itp-company-link';a.href=item.internal_url||'#';a.textContent='اطلاعات بیشتر';
16   card.appendChild(name);card.appendChild(a);return card;
17  }
18  function renderTop(){grid.innerHTML='';shuffle(data).slice(0,4).forEach(function(i){grid.appendChild(card(i));});}
19  function renderResults(list,title){
20   resultGrid.innerHTML='';
21   if(title){var h=document.createElement('h3');h.className='itp-company-results-title';h.textContent=title;resultGrid.appendChild(h);}
22   if(!list.length){var e=document.createElement('div');e.className='itp-company-no-results';e.textContent='شرکتی با این مشخصات پیدا نشد.';resultGrid.appendChild(e);return;}
23   var g=document.createElement('div');g.className='itp-company-results-grid-inner';list.forEach(function(i){g.appendChild(card(i));});resultGrid.appendChild(g);
24   resultGrid.scrollIntoView({behavior:'smooth',block:'nearest'});
25  }
26  function renderCats(){
27   catGrid.innerHTML='';
28   cats.forEach(function(cat){
29    var a=document.createElement('button');a.type='button';a.className='itp-company-category';a.textContent=cat;
30    a.addEventListener('click',function(){
31      var list=data.filter(function(i){return Array.isArray(i.categories)&&i.categories.indexOf(cat)!==-1;});
32      renderResults(list,cat);status.textContent='تعداد شرکت‌ها: '+list.length;
33    });catGrid.appendChild(a);
34   });
35  }
36  search.addEventListener('submit',function(e){
37   e.preventDefault();var q=norm(search.q.value);
38   if(!q){renderResults([], 'نتایج جستجو');status.textContent='عبارت جستجو را وارد کنید.';return;}
39   var list=data.filter(function(i){
40    var hay=[i.name,i.source_id,(i.categories||[]).join(' ')].map(norm).join(' ');
41    return hay.indexOf(q)!==-1;
42   });
43   renderResults(list,'نتایج جستجو برای «'+search.q.value+'»');status.textContent='تعداد نتایج: '+list.length;
44  });
45  section.querySelector('.itp-companies-clear').addEventListener('click',function(){search.q.value='';resultGrid.innerHTML='';status.textContent='';});
46  renderTop();renderCats();setInterval(renderTop,60000);
47 }
48 document.addEventListener('DOMContentLoaded',function(){document.querySelectorAll('.itp-companies-section').forEach(init);});
49})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.