Выносим весь JS код Seditio в отдельный файл
Добавил: Amro   Дата: 28.11.2011 21:34

Как известно, чем меньше мусора на странице тем она лучше ранжируется поисковиками. 

В Seditio для вывода JS кода существует функция sed_javascript(см. functions.php). Приведу её содержимое:

Код:

function sed_javascript($more='')
  {
  $result = "<script type=\"text/javascript\">
<!--

function popup(code,w,h)
  { window.open('plug.php?o='+code,'','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width='+w+',height='+h+',left=32,top=16'); }

function pfs(id,c1,c2)
  { window.open('pfs.php?userid='+id+'&c1='+c1+'&c2='+c2,'PFS','status=1, toolbar=0,location=0,directories=0,menuBar=0,resizable=1,scrollbars=yes,width=754,height=512,left=32,top=16'); }

function help(rcode,c1,c2)
  { window.open('plug.php?h='+rcode+'&c1='+c1+'&c2='+c2,'Help','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=480,height=512,left=32,top=16'); }

function comments(rcode)
  { window.open('comments.php?id='+rcode,'Comments','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=480,height=512,left=16,top=16'); }

function ratings(rcode)
  { window.open('ratings.php?id='+rcode,'Ratings','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=480,height=512,left=16,top=16'); }

function polls(rcode)
  { window.open('polls.php?id='+rcode,'Polls','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=608,height=448,left=16,top=16'); }

function pollvote(rcode,rvote)
  { window.open('polls.php?a=send&id='+rcode+'&vote='+rvote,'Polls','toolbar=0,location=0,directories=0,menuBar=0,resizable=0,scrollbars=yes,width=608,height=448,left=16,top=16'); }

function picture(url,sx,sy)
  {
  var ptop=(window.screen.height-200)/2;
  var pleft=(window.screen.width-200)/2;
  window.open(url,'Picture','toolbar=0,location=0,status=0, directories=0,menubar=0,resizable=1,scrollbars=yes,width='+sx+',height='+sy+',left='+pleft+',top='+ptop+'');
  }
  
function redirect(url)
  { location.href = url.options[url.selectedIndex].value; }

function toggleblock(id)
  {
  var bl = document.getElementById(id);
  if(bl.style.display == 'none')
    { bl.style.display = ''; }
  else
    { bl.style.display = 'none'; }
  }

window.name='main';

".$more."

//-->
</script>";
  return ($result);
  }


Через переменную $more в эту функцию можно из любого плагина передать дополнительный JS код

В своих проектах я использую маленькую модификацию данной функции, а именно:

Код:

function sed_javascript($more='') {
global $skin;
$result = "<script type=\"text/javascript\" src=\"system/js/sedout.js\"></script>";
$result .= "
";
    if (empty($more))
      {$result .= ""; }
    else
      {
        $result .= "<script type=\"text/javascript\">
        <!--

        ".$more."

        //-->
        </script>";
      }
return ($result);
}


Таким образом весь кастрированный JS код помещается в файлик sedout.js

comments powered by HyperComments