[ Index ]

PHP Cross Reference of Nucleus CMS 3.32

title

Body

[close]

/skins/default/ -> nicetitle.js (source)

   1  // from http://www.kryogenix.org
   2  // by Scott Andrew - http://scottandrew.com
   3  // add an eventlistener to browsers that can do it somehow.
   4  function addEvent(obj, evType, fn)
   5      {
   6      if (obj.addEventListener)
   7          {
   8          obj.addEventListener(evType, fn, false);
   9          return true;
  10          }
  11      else if (obj.attachEvent)
  12          {
  13          var r = obj.attachEvent('on'+evType, fn);
  14          return r;
  15          }
  16      else
  17          {
  18          return false;
  19          }
  20      }
  21  
  22  function floatImages()
  23      {
  24      // adapted from http://www.dithered.com/javascript/browser_detect/
  25      //**************************************************************//
  26      // sniff user agent
  27      var userAgent = navigator.userAgent.toLowerCase();
  28  
  29      // if Mozilla 1.4 then quit
  30      if ((userAgent.indexOf('gecko') != -1) && (userAgent.indexOf('gecko/') + 14 == userAgent.length) && (parseFloat(userAgent.substring(userAgent.indexOf('rv:') + 3)) == '1.4')) return;
  31  
  32      // if Opera then quit
  33      if (document.all && window.Event) return;
  34      //**************************************************************//
  35  
  36      // check this browser can cope with what we want to do
  37      if (!document.getElementById) return;
  38      var blogDiv = document.getElementById('blog');
  39      if (!blogDiv) return;
  40      if (!blogDiv.offsetWidth) return;
  41  
  42      blogDiv.className = (blogDiv.offsetWidth >= 500) ? "float-images" : "block-images";
  43      }
  44  
  45  // Blockquote citations
  46  
  47  // Simon Willison's work:
  48  // http://simon.incutio.com/archive/2002/12/20/#blockquoteCitations
  49  
  50  // Also Dunstan Orchard's work:
  51  // http://1976design.com/blog/archive/2003/11/10/updates/
  52  function blockquoteCite()
  53      {
  54      if (!document.createElementNS)
  55          {
  56          document.createElementNS = function(ns, elt)
  57              {
  58              return document.createElement(elt);
  59              }
  60          }
  61      quotes = document.getElementsByTagName('blockquote');
  62      for (i = 0; i < quotes.length; i++)
  63          {
  64          var cite = quotes[i].getAttribute('cite');
  65          // value of cite attribute should only contain URI, not any other
  66          if ((cite) && (cite != ''))
  67              {
  68              newlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  69              newlink.setAttribute('href', cite);
  70              newlink.className = 'cite-link';
  71              newlink.appendChild(document.createTextNode(cite));
  72              newdiv = document.createElementNS('http://www.w3.org/1999/xhtml', 'cite');
  73              newdiv.className = 'blockquote-cite';
  74              newdiv.appendChild(document.createTextNode('Source: '));
  75              newdiv.appendChild(newlink);
  76              quotes[i].appendChild(newdiv);
  77              quotes[i].removeAttribute('cite');
  78              }
  79          }
  80      }
  81  
  82  // Ins and Del tags citations
  83  function insdelCite()
  84      {
  85      if (!document.createElementNS)
  86          {
  87          document.createElementNS = function(ns, elt)
  88              {
  89              return document.createElement(elt);
  90              }
  91          }
  92      var insdel = new Array(2);
  93      insdel[0] = document.getElementsByTagName('ins');
  94      insdel[1] = document.getElementsByTagName('del');
  95      for (var i=0; i<insdel.length; i++)
  96          {
  97          if (insdel[i])
  98              {
  99              for (var id=0; id<insdel[i].length; id++)
 100                  {
 101                  var isdl = insdel[i][id].getAttribute('cite');
 102                  if ((isdl) && (isdl != ""))
 103                      {
 104                      idlink = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
 105                      idlink.setAttribute('href', isdl);
 106                      idlink.className = 'cite-link ' + (i == 0 ? 'ins-cite' : 'del-cite');
 107                      idlink.setAttribute('title','citation of ' + (i == 0 ? 'added' : 'deleted') + ' text');
 108                      idlink.appendChild(document.createTextNode('#'));
 109                      insdel[i][id].appendChild(idlink);
 110                      insdel[i][id].removeAttribute('cite');
 111                      }
 112                  }
 113              }
 114          }
 115      }
 116  
 117  // Force IE not to show alternate text as tooltip
 118  function noAltTooltip()
 119      {
 120      images = document.getElementsByTagName('img');
 121      for (var i = 0; i < images.length; i++)
 122          {
 123          var title = images[i].getAttribute('title');
 124          var alt = images[i].getAttribute('alt');
 125          if ((document.all) && (alt) && (!title))
 126              {
 127              images[i].setAttribute('title', '');
 128              }
 129          }
 130      }
 131  
 132  // Nice Titles
 133  
 134  // original code by Stuart Langridge 2003-11
 135  // with additions to the code by other good people
 136  // http://www.kryogenix.org/code/browser/nicetitle/
 137  // thank you, sir
 138  
 139  // modified by Peter Janes 2003-03-25
 140  // http://peterjanes.ca/blog/archives/2003/03/25/nicetitles-for-ins-and-del
 141  // added in ins and del tags
 142  
 143  // modified by Dunstan Orchard 2003-11-18
 144  // http://1976design.com/blog/
 145  // added in accesskey information
 146  // tried ever-so-hard, but couldn't work out how to do what Ethan did
 147  
 148  // final genius touch by by Ethan Marcotte 2003-11-18
 149  // http://www.sidesh0w.com/
 150  // worked out how to delay showing the popups to make them more like the browser's own
 151  
 152  // set the namespace
 153  var XHTMLNS = 'http://www.w3.org/1999/xhtml';
 154  var CURRENT_NICE_TITLE;
 155  
 156  // browser sniff
 157  var browser = new Browser();
 158  
 159  // determine browser and version.
 160  function Browser()
 161      {
 162      var ua, s, i;
 163  
 164      this.isIE = false;
 165      this.isNS = false;
 166      this.version = null;
 167  
 168      ua = navigator.userAgent;
 169  
 170      s = 'MSIE';
 171      if ((i = ua.indexOf(s)) >= 0)
 172          {
 173          this.isIE = true;
 174          this.version = parseFloat(ua.substr(i + s.length));
 175          return;
 176          }
 177  
 178      s = 'Netscape6/';
 179      if ((i = ua.indexOf(s)) >= 0)
 180          {
 181          this.isNS = true;
 182          this.version = parseFloat(ua.substr(i + s.length));
 183          return;
 184          }
 185  
 186      // treat any other 'Gecko' browser as NS 6.1.
 187      s = 'Gecko';
 188      if ((i = ua.indexOf(s)) >= 0)
 189          {
 190          this.isNS = true;
 191          this.version = 6.1;
 192          return;
 193          }
 194      }
 195  
 196  // 2003-11-19 sidesh0w
 197  // set delay vars to emulate normal hover delay
 198  var delay;
 199  var interval = 0.60;
 200  
 201  // this function runs on window load
 202  // it runs through all the links on the page as starts listening for actions
 203  function makeNiceTitles()
 204      {
 205      if (!document.createElement || !document.getElementsByTagName) return;
 206      if (!document.createElementNS)
 207          {
 208          document.createElementNS = function(ns, elt)
 209              {
 210              return document.createElement(elt);
 211              }
 212          }
 213  
 214      // do regular links
 215      if (!document.links)
 216          {
 217          document.links = document.getElementsByTagName('a');
 218          }
 219      for (var ti=0; ti<document.links.length; ti++)
 220          {
 221          var lnk = document.links[ti];
 222          // * I added specific class names here..
 223          if (lnk.title)
 224              {
 225              lnk.setAttribute('nicetitle', lnk.title);
 226              lnk.removeAttribute('title');
 227              addEvent(lnk, 'mouseover', showDelay);
 228              addEvent(lnk, 'mouseout', hideNiceTitle);
 229              addEvent(lnk, 'focus', showDelay);
 230              addEvent(lnk, 'blur', hideNiceTitle);
 231              }
 232          }
 233  
 234      // 2003-03-25 Peter Janes
 235      // do ins and del tags
 236      var tags = new Array(2);
 237      tags[0] = document.getElementsByTagName('ins');
 238      tags[1] = document.getElementsByTagName('del');
 239      for (var tt=0; tt<tags.length; tt++)
 240          {
 241          if (tags[tt])
 242              {
 243              for (var ti=0; ti<tags[tt].length; ti++)
 244                  {
 245                  var tag = tags[tt][ti];
 246                  if (tag.dateTime)
 247                      {
 248                      var strDate = tag.dateTime;
 249                      // HTML/ISO8601 date: yyyy-mm-ddThh:mm:ssTZD (Z, -hh:mm, +hh:mm)
 250                      var month = strDate.substring(5,7);
 251                      var day = strDate.substring(8,10);
 252                      if (month[0] == '0')
 253                          {
 254                          month = month[1];
 255                          }
 256                      if (day[0] == '0')
 257                          {
 258                          day = day[1];
 259                          }
 260                      var dtIns = new Date(strDate.substring(0,4), month-1, day, strDate.substring(11,13), strDate.substring(14,16), strDate.substring(17,19));
 261                      tag.setAttribute('nicetitle', (tt == 0 ? 'Added' : 'Deleted') + ' on ' + dtIns.toString());
 262                      addEvent(tag, 'mouseover', showDelay);
 263                      addEvent(tag, 'mouseout', hideNiceTitle);
 264                      addEvent(tag, 'focus', showDelay);
 265                      addEvent(tag, 'blur', hideNiceTitle);
 266                      }
 267                  }
 268              }
 269          }
 270      }
 271  
 272  function findPosition(oLink)
 273      {
 274      if (oLink.offsetParent)
 275          {
 276          for (var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent)
 277              {
 278              posX += oLink.offsetLeft;
 279              posY += oLink.offsetTop;
 280              }
 281          return [posX, posY];
 282          }
 283      else
 284          {
 285          return [oLink.x, oLink.y];
 286          }
 287      }
 288  
 289  function getParent(el, pTagName)
 290      {
 291      if (el == null)
 292          {
 293          return null;
 294          }
 295      // gecko bug, supposed to be uppercase
 296      else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())
 297          {
 298          return el;
 299          }
 300      else
 301          {
 302          return getParent(el.parentNode, pTagName);
 303          }
 304      }
 305  
 306  // 2003-11-19 sidesh0w
 307  // trailerpark wrapper function
 308  function showDelay(e)
 309      {
 310      if (window.event && window.event.srcElement)
 311          {
 312          lnk = window.event.srcElement
 313          }
 314      else if (e && e.target)
 315          {
 316          lnk = e.target
 317          }
 318      if (!lnk) return;
 319  
 320      // lnk is a textnode or an elementnode that's not ins/del
 321      if (lnk.nodeType == 3 || (lnk.nodeType == 1 && lnk.tagName.toLowerCase() != 'ins' && lnk.tagName.toLowerCase() != 'del'))
 322          {
 323          // ascend parents until we hit a link
 324          lnk = getParent(lnk, 'a');
 325          }
 326  
 327      delay = setTimeout("showNiceTitle(lnk)", interval * 1000);
 328      }
 329  
 330  // build and show the nice titles
 331  function showNiceTitle(link)
 332      {
 333      if (CURRENT_NICE_TITLE) hideNiceTitle(CURRENT_NICE_TITLE);
 334      if (!document.getElementsByTagName) return;
 335  
 336      nicetitle = lnk.getAttribute('nicetitle');
 337  
 338      var d = document.createElementNS(XHTMLNS, 'div');
 339      d.className = 'nicetitle';
 340      var dc = document.createElementNS(XHTMLNS, 'div');
 341      dc.className = 'nicetitle-content';
 342      d.appendChild(dc);
 343      tnt = document.createTextNode(nicetitle);
 344      pat = document.createElementNS(XHTMLNS, 'p');
 345      pat.className = 'titletext';
 346      pat.appendChild(tnt);
 347  
 348      // 2003-11-18 Dunstan Orchard
 349      // added in accesskey info
 350      if (lnk.accessKey)
 351          {
 352          axs = document.createTextNode(' [' + lnk.accessKey + ']');
 353          axsk = document.createElementNS(XHTMLNS, 'span');
 354          axsk.className = 'accesskey';
 355          axsk.appendChild(axs);
 356          pat.appendChild(axsk);
 357          }
 358      dc.appendChild(pat);
 359  
 360      if (lnk.href)
 361          {
 362          tnd = document.createTextNode(lnk.href);
 363          pad = document.createElementNS(XHTMLNS, 'p');
 364          pad.className = 'destination';
 365          pad.appendChild(tnd);
 366          dc.appendChild(pad);
 367          }
 368  
 369      STD_WIDTH = 300;
 370  
 371      if (lnk.href)
 372          {
 373          h = lnk.href.length;
 374          }
 375      else
 376          {
 377          h = nicetitle.length;
 378          }
 379  
 380      if (nicetitle.length)
 381          {
 382          t = nicetitle.length;
 383          }
 384  
 385      h_pixels = h*6;
 386      t_pixels = t*10;
 387  
 388      if (h_pixels > STD_WIDTH)
 389          {
 390          w = h_pixels;
 391          }
 392      else if ((STD_WIDTH>t_pixels) && (t_pixels>h_pixels))
 393          {
 394          w = t_pixels;
 395          }
 396      else if ((STD_WIDTH>t_pixels) && (h_pixels>t_pixels))
 397          {
 398          w = h_pixels;
 399          }
 400      else
 401          {
 402          w = STD_WIDTH;
 403          }
 404  
 405      d.style.width = w + 'px';
 406  
 407      mpos = findPosition(lnk);
 408      mx = mpos[0];
 409      my = mpos[1];
 410  
 411      d.style.left = (mx+15) + 'px';
 412      d.style.top = (my+35) + 'px';
 413  
 414      if (window.innerWidth && ((mx+w) > window.innerWidth))
 415          {
 416          d.style.left = (window.innerWidth - w - 25) + 'px';
 417          }
 418      if (document.body.scrollWidth && ((mx+w) > document.body.scrollWidth))
 419          {
 420          d.style.left = (document.body.scrollWidth - w - 25) + 'px';
 421          }
 422  
 423      document.getElementsByTagName('body')[0].appendChild(d);
 424  
 425      CURRENT_NICE_TITLE = d;
 426      }
 427  
 428  function hideNiceTitle(e)
 429      {
 430      // 2003-11-19 sidesh0w
 431      // clearTimeout
 432      if (delay) clearTimeout(delay);
 433      if (!document.getElementsByTagName) return;
 434      if (CURRENT_NICE_TITLE)
 435          {
 436          document.getElementsByTagName('body')[0].removeChild(CURRENT_NICE_TITLE);
 437          CURRENT_NICE_TITLE = null;
 438          }
 439      }
 440  
 441  addEvent(window, "load", floatImages);
 442  addEvent(window, "resize", floatImages);
 443  addEvent(window, "load", blockquoteCite);
 444  addEvent(window, "load", insdelCite);
 445  addEvent(window, "load", noAltTooltip);
 446  addEvent(window, "load", makeNiceTitles);
 447  
 448  // I'm very poor in JavaScript. Please correct me if I'm wrong.


Generated: Tue Feb 12 15:34:36 2008 Cross-referenced by PHPXref 0.7