web/drupal/modules/xmlsitemap/gss/gss.js
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 // $Id: gss.js,v 1.1.6.3 2009/06/12 14:34:45 earnie Exp $
       
     2 
       
     3 var selectedColor = "blue";
       
     4 var defaultColor = "black";
       
     5 var hdrRows = 1;
       
     6 var numeric = '..';
       
     7 var desc = '..';
       
     8 var html = '..';
       
     9 var freq = '..';
       
    10 
       
    11 function initXsl(tabName,fileType) {
       
    12   hdrRows = 1;
       
    13 
       
    14   if(fileType=="sitemap") {
       
    15     numeric = ".3.";
       
    16     desc = ".1.";
       
    17     html = ".0.";
       
    18     freq = ".2.";
       
    19     initTable(tabName);
       
    20   }
       
    21   else {
       
    22     desc = ".1.";
       
    23     html = ".0.";
       
    24     initTable(tabName);
       
    25   }
       
    26 
       
    27   var theURL = document.getElementById("head1");
       
    28   theURL.innerHTML += ' ' + location;
       
    29   document.title += ': ' + location;
       
    30 }
       
    31 
       
    32 function initTable(tabName) {
       
    33   var theTab = document.getElementById(tabName);
       
    34   for(r=0;r<hdrRows;r++)
       
    35    for(c=0;c<theTab.rows[r].cells.length;c++)
       
    36      if((r+theTab.rows[r].cells[c].rowSpan)>hdrRows)
       
    37        hdrRows=r+theTab.rows[r].cells[c].rowSpan;
       
    38   for(r=0;r<hdrRows; r++){
       
    39     colNum = 0;
       
    40     for(c=0;c<theTab.rows[r].cells.length;c++, colNum++){
       
    41       if(theTab.rows[r].cells[c].colSpan<2){
       
    42         theCell = theTab.rows[r].cells[c];
       
    43         rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;/g,'');
       
    44         if(rTitle>""){
       
    45           theCell.title = "Change sort order for " + rTitle;
       
    46           theCell.onmouseover = function(){setCursor(this, "selected")};
       
    47           theCell.onmouseout = function(){setCursor(this, "default")};
       
    48           var sortParams = 15; // bitmapped: numeric|desc|html|freq
       
    49           if(numeric.indexOf("."+colNum+".")>-1) sortParams -= 1;
       
    50           if(desc.indexOf("."+colNum+".")>-1) sortParams -= 2;
       
    51           if(html.indexOf("."+colNum+".")>-1) sortParams -= 4;
       
    52           if(freq.indexOf("."+colNum+".")>-1) sortParams -= 8;
       
    53           theCell.onclick = new Function("sortTable(this,"+(colNum+r)+","+hdrRows+","+sortParams+")");
       
    54         }
       
    55       } else {
       
    56         colNum = colNum+theTab.rows[r].cells[c].colSpan-1;
       
    57       }
       
    58     }
       
    59   }
       
    60 }
       
    61 
       
    62 function setSort(tabName, colNum, sortDir) {
       
    63   var theTab = document.getElementById(tabName);
       
    64   theTab.rows[0].sCol = colNum;
       
    65   theTab.rows[0].sDir = sortDir;
       
    66   if (sortDir)
       
    67     theTab.rows[0].cells[colNum].className='sortdown'
       
    68   else
       
    69     theTab.rows[0].cells[colNum].className='sortup';
       
    70 }
       
    71 
       
    72 function setCursor(theCell, mode){
       
    73   rTitle = theCell.innerHTML.replace(/<[^>]+>|&nbsp;|\W/g,'');
       
    74   if(mode=="selected"){
       
    75     if(theCell.style.color!=selectedColor)
       
    76       defaultColor = theCell.style.color;
       
    77     theCell.style.color = selectedColor;
       
    78     theCell.style.cursor = "hand";
       
    79     window.status = "Click to sort by '"+rTitle+"'";
       
    80   } else {
       
    81     theCell.style.color = defaultColor;
       
    82     theCell.style.cursor = "";
       
    83     window.status = "";
       
    84   }
       
    85 }
       
    86 
       
    87 function sortTable(theCell, colNum, hdrRows, sortParams){
       
    88   var typnum = !(sortParams & 1);
       
    89   sDir = !(sortParams & 2);
       
    90   var typhtml = !(sortParams & 4);
       
    91   var typfreq = !(sortParams & 8);
       
    92   var tBody = theCell.parentNode;
       
    93   while(tBody.nodeName!="TBODY"){
       
    94     tBody = tBody.parentNode;
       
    95   }
       
    96   var tabOrd = new Array();
       
    97   if(tBody.rows[0].sCol==colNum) sDir = !tBody.rows[0].sDir;
       
    98   if (tBody.rows[0].sCol>=0)
       
    99     tBody.rows[0].cells[tBody.rows[0].sCol].className='';
       
   100   tBody.rows[0].sCol = colNum;
       
   101   tBody.rows[0].sDir = sDir;
       
   102   if (sDir)
       
   103      tBody.rows[0].cells[colNum].className='sortdown'
       
   104   else
       
   105      tBody.rows[0].cells[colNum].className='sortup';
       
   106   for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
       
   107     colCont = tBody.rows[r].cells[colNum].innerHTML;
       
   108     if(typhtml) colCont = colCont.replace(/<[^>]+>/g,'');
       
   109     if(typnum) {
       
   110       colCont*=1;
       
   111       if(isNaN(colCont)) colCont = 0;
       
   112     }
       
   113     if(typfreq) {
       
   114     switch(colCont.toLowerCase()) {
       
   115       case "always":  { colCont=0; break; }
       
   116       case "hourly":  { colCont=1; break; }
       
   117       case "daily":   { colCont=2; break; }
       
   118       case "weekly":  { colCont=3; break; }
       
   119       case "monthly": { colCont=4; break; }
       
   120       case "yearly":  { colCont=5; break; }
       
   121       case "never":   { colCont=6; break; }
       
   122     }
       
   123   }
       
   124     tabOrd[i] = [r, tBody.rows[r], colCont];
       
   125   }
       
   126   tabOrd.sort(compRows);
       
   127   for(i=0,r=hdrRows;r<tBody.rows.length;i++,r++){
       
   128     tBody.insertBefore(tabOrd[i][1],tBody.rows[r]);
       
   129   }
       
   130   window.status = "";
       
   131 }
       
   132 
       
   133 function compRows(a, b){
       
   134   if(sDir){
       
   135     if(a[2]>b[2]) return -1;
       
   136     if(a[2]<b[2]) return 1;
       
   137   } else {
       
   138     if(a[2]>b[2]) return 1;
       
   139     if(a[2]<b[2]) return -1;
       
   140   }
       
   141   return 0;
       
   142 }
       
   143