[ Index ]

PHP Cross Reference of Project Glazy import

title

Body

[close]

/projet/ -> phpxref.js (source)

   1  /**
   2  * Support routines for PHPXref
   3  * (c) Gareth Watts 2003-2004
   4  */
   5  
   6  // Number of items that are held in the user's search history cookie
   7  // The cookie spec says up to 4k per cookie, so at ~50 bytes per entry
   8  // that gives a maximum of around 80 items as a max value for this field
   9  var MAX_SEARCH_ITEMS=25; 
  10  
  11  
  12  
  13  /**
  14  ** Simple dynamic HTML popup handler
  15  ** (c) Gareth Watts, August 2003
  16  */
  17  var gwActivePopup=null; // global
  18  var gwTimeoutId=0;
  19  function gwPopup(e,layerid, noautoclose) {
  20      var isEvent=true;
  21      var x=null; var y=null;
  22  
  23      gwCloseActive();
  24      try { e.type } catch (e) { isEvent=false; }
  25      if (isEvent) {
  26          if (e.pageX||e.pageY) {
  27              x=e.pageX; y=e.pageY;
  28          } else if (e.clientX||e.clientY) {
  29              if (document.documentElement && document.documentElement.scrollTop) {
  30                  x=e.clientX+document.documentElement.scrollLeft; y=e.clientY+document.documentElement.scrollTop;
  31              } else {
  32                  x=e.clientX+document.body.scrollLeft; y=e.clientY+document.body.scrollTop;
  33              }
  34          } else {
  35              return; 
  36          }
  37      } else if (e != null) { /* assume it's an element */
  38          x=elementX(e);
  39          y=elementY(e);
  40      }
  41      layer=document.getElementById(layerid);
  42      if (x != null) {
  43          layer.style.left=x;
  44          layer.style.top=y;
  45      }
  46      layer.style.visibility='Visible';
  47      gwActivePopup=layer;
  48      clearTimeout(gwTimeoutId); gwTimeoutId=0;
  49      if (!noautoclose) {
  50          gwTimeoutId=setTimeout("gwCloseActive()", 5000);
  51          layer.onmouseout=function() { clearTimeout(gwTimeoutId); gwTimeoutId=setTimeout("gwCloseActive()", 350); } 
  52          layer.onmouseover=function() { clearTimeout(gwTimeoutId); gwTimeoutId=0;}
  53      }
  54  }
  55  
  56  /**
  57  * Close the active popup
  58  */
  59  function gwCloseActive() {
  60      if (gwActivePopup) {
  61          gwActivePopup.style.visibility='Hidden';
  62          gwActivePopup=null;
  63      }
  64  }
  65  
  66  spTimeoutId=0;
  67  function showSearchBox() {
  68      popup=document.getElementById('searchbox');
  69      popup.style.visibility='Visible';
  70      clearTimeout(spTimeoutId); spTimeoutId=0;
  71      spTimeoutId=setTimeout('closeSearchBox()', 5000);
  72      popup.onmouseout=function() { clearTimeout(spTimeoutId); spTimeoutId=setTimeout('closeSearchBox()', 350); }
  73      popup.onmouseover=function() { clearTimeout(spTimeoutId); spTimeoutId=0;}
  74  }
  75  
  76  function closeSearchBox() {
  77      popup=document.getElementById('searchbox');
  78      popup.style.visibility='Hidden';
  79  }
  80  
  81  /**
  82  * Display the hover-over-function-name popup
  83  */
  84  function funcPopup(e, encfuncname) {
  85      gwCloseActive();
  86      var title=document.getElementById('func-title');
  87      var body=document.getElementById('func-body');
  88      var desc=document.getElementById('func-desc');
  89  
  90      var funcdata=FUNC_DATA[encfuncname];
  91      title.innerHTML=funcdata[0]+'()';
  92      desc.innerHTML=funcdata[1];
  93      var bodyhtml='';
  94      var deflist=funcdata[2];
  95      var defcount=deflist.length;
  96      var funcurl=relbase+'_functions/'+encfuncname+'.html';
  97      if (defcount>0) {
  98          var pl=defcount==1 ? '' : 's';
  99          bodyhtml+=defcount+' definition'+pl+':<br>\n';
 100          for(var i=0;i<defcount;i++) {
 101               var dir=deflist[i][0];
 102               if (dir!='') { dir+='/'; }
 103               if (deflist[i][0]) {
 104                   var target = deflist[i][0]+'/'+deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 105               } else {
 106                   var target = deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 107               }
 108               bodyhtml+='&nbsp;&nbsp;<a onClick="logFunction(\''+encfuncname+'\', \''+target+'\')" href="'+relbase+target+'">'+dir+deflist[i][1]+'</a><br>\n';
 109              /* bodyhtml+='&nbsp;&nbsp;<a onClick="logFunction(\''+encfuncname+'\')" href="'+relbase+deflist[i][0]+'/'+deflist[i][1]+'.source'+ext+'#l'+deflist[i][2]+'">'+dir+deflist[i][1]+'</a><br>\n'; */
 110          }       
 111      } else {
 112          bodyhtml+='No definitions<br>\n';
 113      }
 114      bodyhtml+='<br>Referenced <a href="'+funcurl+'">'+funcdata[3]+' times</a><br>\n';
 115      body.innerHTML=bodyhtml;
 116  
 117      gwPopup(e, 'func-popup');
 118  }
 119  
 120  /**
 121  * Display the popup for built-in PHP functions
 122  */
 123  function phpfuncPopup(e, encfuncname) {
 124      gwCloseActive();
 125      var title=document.getElementById('func-title');
 126      var body=document.getElementById('func-body');
 127      var desc=document.getElementById('func-desc');
 128  
 129      var funcdata=FUNC_DATA[encfuncname];
 130      var funcname=funcdata[0];
 131      var funcurl=relbase+'_functions/'+encfuncname+'.html';
 132  
 133      title.innerHTML='PHP: '+funcname+'()';
 134      desc.innerHTML='Native PHP function';
 135      var funcnameenc=escape(funcname);
 136      var bodyhtml='Documentation: <a href="http://php.net/'+encfuncname+'" target="_new">'+funcname+'()</a><br>';
 137      bodyhtml+='<br>Referenced <a href="'+funcurl+'">'+funcdata[3]+' times</a><br>\n';
 138  
 139      body.innerHTML=bodyhtml;
 140      gwPopup(e, 'func-popup');
 141  }
 142  
 143  
 144  /**
 145  * Display the hover-over-class popup
 146  */
 147  function classPopup(e, encclassname) {
 148      gwCloseActive();
 149      var title=document.getElementById('class-title');
 150      var body=document.getElementById('class-body');
 151      var desc=document.getElementById('class-desc');
 152  
 153      var classdata=CLASS_DATA[encclassname];
 154      title.innerHTML=classdata[0]+'::';
 155      desc.innerHTML=classdata[1];
 156      var bodyhtml='';
 157      var deflist=classdata[2];
 158      var defcount=deflist.length;
 159      var classurl=relbase+'_classes/'+encclassname+'.html';
 160      if (defcount>0) {
 161          var pl=defcount==1 ? '' : 's';
 162          bodyhtml+=defcount+' definition'+pl+':<br>\n';
 163          for(var i=0;i<defcount;i++) {
 164               var dir=deflist[i][0];
 165               if (dir!='') { dir+='/'; }
 166               if (deflist[i][0]) {
 167                   var target = deflist[i][0]+'/'+deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 168               } else {
 169                   var target = deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 170               }
 171               bodyhtml+='&nbsp;&nbsp;<a onClick="logClass(\''+encclassname+'\', \''+target+'\')" href="'+relbase+target+'">'+dir+deflist[i][1]+'</a><br>\n';
 172          }       
 173      } else {
 174          bodyhtml+='No definitions<br>\n';
 175      }
 176      bodyhtml+='<br>Referenced <a href="'+classurl+'">'+classdata[3]+' times</a><br>\n';
 177      body.innerHTML=bodyhtml;
 178  
 179      gwPopup(e, 'class-popup');
 180  }
 181  
 182  
 183  /**
 184  * Display the hover-over-constant popup
 185  */
 186  function constPopup(e, constname) {
 187      gwCloseActive();
 188      var title=document.getElementById('const-title');
 189      var body=document.getElementById('const-body');
 190      var desc=document.getElementById('const-desc');
 191  
 192      var constdata=CONST_DATA[constname];
 193      title.innerHTML='Const: '+constdata[0];
 194      desc.innerHTML=constdata[1];
 195      var bodyhtml='';
 196      var deflist=constdata[2];
 197      var defcount=deflist.length;
 198      var consturl=relbase+'_constants/'+constname+'.html';
 199      if (defcount>0) {
 200          var pl=defcount==1 ? '' : 's';
 201          bodyhtml+=defcount+' definition'+pl+':<br>\n';
 202          for(var i=0;i<defcount;i++) {
 203               var dir=deflist[i][0];
 204               if (dir!='') { dir+='/'; }
 205               if (deflist[i][0]) {
 206                   var target = deflist[i][0]+'/'+deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 207               } else {
 208                   var target = deflist[i][1]+'.source'+ext+'#l'+deflist[i][2];
 209               }
 210               bodyhtml+='&nbsp;&nbsp;<a onClick="logConstant(\''+constname+'\', \''+target+'\')" href="'+relbase+target+'">'+dir+deflist[i][1]+'</a><br>\n';
 211          }       
 212      } else {
 213          bodyhtml+='No definitions<br>\n';
 214      }
 215      bodyhtml+='<br>Referenced <a href="'+consturl+'">'+constdata[3]+' times</a><br>\n';
 216      body.innerHTML=bodyhtml;
 217  
 218      gwPopup(e, 'const-popup');
 219  }
 220  
 221  /**
 222  * Display the hover-over-function-require (or include) popup
 223  */
 224  function reqPopup(e, name, baseurl) {
 225      gwCloseActive();
 226      var title=document.getElementById('req-title');
 227      var body=document.getElementById('req-body');
 228  
 229      title.innerHTML=name;
 230      body.innerHTML='<a href="'+baseurl+'.source'+ext+'">Source</a>&nbsp;|&nbsp;'
 231          +'<a href="'+baseurl+ext+'">Summary</a>';
 232      gwPopup(e, 'req-popup');
 233  }
 234  
 235  
 236  /**
 237  * Handle setting up the navigation frame, if the user
 238  * has the option turned on in a cookie
 239  */
 240  function handleNavFrame(relbase, subdir, filename) {
 241      var line = '';
 242      var navstatus=gwGetCookie('xrefnav');
 243      if (navstatus!='off' && (parent.name!='phpxref' || parent==self)) {
 244          if (subdir!='') { subdir+='/'; }
 245          var x=parent.location.toString().indexOf('#');
 246          if (x != -1) { /* Preserve the line number referenced in the parent */
 247              line = parent.location.toString().substr(x);
 248          }
 249          parent.location=relbase+'nav'+ext+'?'+subdir+filename+line;
 250      } else if (parent.nav && parent.nav.open_branch) {
 251          parent.nav.open_branch(subdir);
 252      }
 253  }
 254  
 255  /**
 256  * Fetch a cookie by name
 257  */
 258  function gwGetCookie(name) {
 259      var cookies=document.cookie;
 260      var offset; var endpoint;
 261      name = cookiekey + '-' + name;
 262      if ((offset=cookies.indexOf(name))==-1)
 263          return null;
 264      if ((endpoint=cookies.indexOf(';', offset))==-1)
 265          endpoint=cookies.length;
 266      var value=unescape(cookies.substring(offset+name.length+1, endpoint));
 267      return value;
 268  }
 269  
 270  /**
 271  * Set an individual cookie by name and value
 272  */
 273  function gwSetCookie(name, value) {
 274      var expire = new Date();
 275      expire.setTime( expire.getTime() + 86400*365*1000 );
 276      name = cookiekey + '-' + name;
 277      document.cookie=name+'='+escape(value)+';path=/;expires='+expire.toGMTString();
 278  }
 279  
 280  /**
 281  * Switch on the navigation frame 
 282  */
 283  function navOn() {
 284      gwSetCookie('xrefnav','on');
 285      self.location.reload();
 286  }
 287  
 288  /** 
 289  * Turn off the navigation frame
 290  */
 291  function navOff() {
 292      gwSetCookie('xrefnav','off');
 293      parent.location.href=self.location.href;
 294  }
 295  
 296  /**
 297  * Escape search strings
 298  */
 299  function pesc(str) {
 300      str=str.replace(/^(con|prn|aux|clock\\$|nul|lpt\\d|com\\d)\$/i, "-\$1");
 301      str=str.replace(/^(con|prn|aux|clock\\$|nul|lpt\\d|com\\d)\\./i, "-\$1.");
 302      return str;
 303  }
 304  
 305  /**
 306  * Run a 'search'
 307  */
 308  function jump() {
 309      if (document.search.classname.value.length) {
 310          jumpClass(document.search.classname.value);
 311      }
 312      if (document.search.funcname.value.length) {
 313          jumpFunction(document.search.funcname.value);
 314      }
 315      if (document.search.varname.value.length) {
 316          jumpVariable(document.search.varname.value);
 317      }
 318      if (document.search.constname.value.length) {
 319          jumpConstant(document.search.constname.value);
 320      }
 321      if (document.search.tablename.value.length) {
 322          jumpTable(document.search.tablename.value);
 323      }
 324      return false;
 325  }
 326  
 327  /**
 328  * Jump to a function reference page, and log in the history log
 329  */
 330  function jumpFunction(target) {
 331      var target=target.replace(/[()]/g,'');
 332      target=target.toLowerCase();
 333      logFunction(target);
 334      window.location=relbase+'_functions/'+escape(escape(pesc(target)))+ext;
 335  }
 336  
 337  /**
 338  * Jump to a class reference page, and log in the history log
 339  */
 340  function jumpClass(target) {
 341      var target=target.replace(/[()]/g,'');
 342      target=target.toLowerCase();
 343      logClass(target);
 344      window.location=relbase+'_classes/'+escape(escape(pesc(target)))+ext;
 345  }
 346  
 347  /**
 348  * Jump to a variable reference page, and log in the history log
 349  */
 350  function jumpVariable(target) {
 351      var target=target.replace(/[\$]/g,'');
 352      logVariable(target);
 353      window.location=relbase+'_variables/'+escape(escape(pesc(target)))+ext;
 354  }
 355  
 356  /**
 357  * Jump to a constant reference page, and log in the history log
 358  */
 359  function jumpConstant(target) {
 360      var target=target.toUpperCase();
 361      logConstant(target);
 362      window.location=relbase+'_constants/'+escape(escape(pesc(target)))+ext;
 363  }
 364  
 365  /**
 366  * Jump to a table reference page, and log in the history log
 367  */
 368  function jumpTable(target) {
 369      var target=toLowerCase();
 370      logTable(target);
 371      window.location=relbase+'_tables/'+escape(escape(pesc(target)))+ext;
 372  }
 373  
 374  /**
 375  * Log a function access in the history log
 376  * If urltarget is supplied, then the specific URL where
 377  * that function is defined is logged with the function name
 378  */
 379  function logFunction(target, urltarget) {
 380      var uritarget = '';
 381      if (urltarget)
 382          uritarget = ';' + escape(urltarget)
 383      addToSearchList('F' + escape(target) + uritarget);
 384      return true;
 385  }
 386  
 387  /**
 388  * Log a class access in the history log
 389  */
 390  function logClass(target, urltarget) {
 391      var uritarget = '';
 392      if (urltarget)
 393          uritarget = ';' + escape(urltarget)
 394      addToSearchList('C' + escape(target) + uritarget);
 395      return true;
 396  }
 397  
 398  /**
 399  * Log a variable access in the history log
 400  */
 401  function logVariable(target, urltarget) {
 402      var uritarget = '';
 403      if (urltarget)
 404          uritarget = ';' + escape(urltarget)
 405      addToSearchList('V' + escape(target) + uritarget);
 406      return true;
 407  }
 408  
 409  /**
 410  * Log a constant access in the history log
 411  */
 412  function logConstant(target, urltarget) {
 413      var uritarget = '';
 414      if (urltarget)
 415          uritarget = ';' + escape(urltarget)
 416      addToSearchList('A' + escape(target) + uritarget);
 417      return true;
 418  }
 419  
 420  /**
 421  * Log a table access in the history log
 422  */
 423  function logTable(target) {
 424      addToSearchList('T' + escape(target));
 425      return true;
 426  }
 427  
 428  /**
 429  * Get an array of previous searches/lookups
 430  */
 431  function getSearchList() {
 432      var searchlist=gwGetCookie('xrefsearch');
 433      if (!searchlist) {
 434          return false;
 435      }
 436      return searchlist.split(',');
 437  }
 438  
 439  /**
 440  * Add a new entry to the search history log
 441  */
 442  function addToSearchList(item) {
 443      if (typeof Array.prototype.unshift == 'undefined') {
 444          return false;
 445      }
 446      item.replace(/[^\w_]+/gi, '');
 447      if (!item.length)
 448          return false; // no point adding an empty string
 449  
 450      var searchlist=getSearchList();
 451      if (!searchlist) {
 452          searchlist = Array();
 453      }
 454      // Remove duplicate entries
 455      for (var i=searchlist.length-1; i>=0; i--) {
 456          if (searchlist[i] == item) {
 457              searchlist.splice(i,1);
 458          }
 459      }
 460      searchlist.unshift(item); // push newest onto the beginning of the list
 461      if (searchlist.length > MAX_SEARCH_ITEMS) {
 462          searchlist.splice(MAX_SEARCH_ITEMS);
 463      }
 464      gwSetCookie('xrefsearch', searchlist.join(','));
 465      return true;
 466  }
 467  
 468  /**
 469  * Calculate the absolute X offset of an html element
 470  */
 471  function elementX(el) {
 472      var x = el.offsetLeft;
 473      var parent = el.offsetParent;
 474      while (parent) {
 475          x += parent.offsetLeft;
 476          parent = parent.offsetParent;
 477      }
 478      return x;
 479  }
 480  
 481  /**
 482  * Calculate the absolute Y offset of an html element
 483  */
 484  function elementY(el) {
 485      var y = el.offsetTop;
 486      var parent = el.offsetParent;
 487      while (parent != null) {
 488          y += parent.offsetTop;
 489          parent = parent.offsetParent;
 490      }
 491      return y;
 492  }
 493  
 494  /**
 495  * Display a popup containing the user's most recent searches
 496  */
 497  function showSearchPopup() {
 498      gwCloseActive();
 499      var title=document.getElementById('searchpopup-title');
 500      var body=document.getElementById('searchpopup-body');
 501  
 502      var searchlist=getSearchList();
 503      title.innerHTML='Access History';
 504      if (!searchlist) {
 505          body.innerHTML='<p align="center">(no entries logged)</p>';
 506      } else {
 507          var content = '<table>';
 508          for (var i=0; i<searchlist.length; i++) {
 509              var parse = searchlist[i].split(';');
 510              var item = unescape(parse[0]);
 511              var itemsource = parse.length>1 ? unescape(parse[1]) : '';
 512              var type = item.charAt(0);
 513              var ref = item.substr(1);
 514              switch (type) {
 515                  case 'F':
 516                      var href = "javascript:jumpFunction('" + ref + "')"
 517                      var name = ref + "()";
 518                      var styleclass = 'function';
 519                      break;
 520                  case 'C':
 521                      var href = "javascript:jumpClass('" + ref + "')"
 522                      var name = ref + "::";
 523                      var styleclass = "class";
 524                      break;
 525                  case 'V':
 526                      var href = "javascript:jumpVariable('" + ref + "')"
 527                      var name = '$' + ref;
 528                      var styleclass = "var";
 529                      break;
 530                  case 'A':
 531                      var href = "javascript:jumpConstant('" + ref + "')"
 532                      var name = ref;
 533                      var styleclass = "const";
 534                      break;
 535                  case 'T':
 536                      var href = "javascript:jumpTable('" + ref + "')"
 537                      var name = 'SQL: ' + ref;
 538                      var styleclass = '';
 539                      break;
 540                  default:
 541                      continue; // unknown type
 542              }
 543              content += '<tr>';
 544              if (itemsource) {
 545                  content += '<td>[<a href="' + relbase + itemsource + '">S</a>]</td>';
 546              } else {
 547                  content += '<td align="right">&raquo;</td>';
 548              }
 549              content += '<td><a href="' + href + '"';
 550              if (styleclass)
 551                  content += ' class="' + styleclass + '"';
 552              content += '>' + name + '</a></td></tr>';
 553          }
 554          content += '</table>';
 555          body.innerHTML = content;
 556      }
 557      position=document.getElementById('funcsearchlink');
 558      gwPopup(null, 'search-popup', true);
 559  }               
 560  
 561  function hilite(itemid) {
 562      /* only mozilla and IE are really supported here atm. */
 563      try { 
 564      var agt=navigator.userAgent.toLowerCase();
 565      if (agt.indexOf('gecko') != -1) {
 566          document.getElementById('hilight').sheet.insertRule('.it'+itemid+' { background-color: #0f0; }', 0);
 567      } else {
 568          document.styleSheets["hilight"].addRule('.it'+itemid, 'background-color: #0f0', 0);
 569      }
 570      } catch(e) { } /* swallow any browser incompatibility errors */
 571  }
 572  
 573  function lolite() {
 574      try { 
 575      var agt=navigator.userAgent.toLowerCase();
 576      if (agt.indexOf('gecko') != -1) {
 577          document.getElementById('hilight').sheet.deleteRule(0);
 578      } else {
 579          document.styleSheets["hilight"].removeRule(0);
 580      }
 581      } catch(e) { }
 582  }


Generated: Thu Sep 14 11:31:49 2023 Cross-referenced by PHPXref 0.7.1