X Library Viewer

Download the X Distribution File.

X Index

Animation

xAniLine, xAnimation.arc, xAnimation.corner, xAnimation.css, xAnimation.imgSize, xAnimation.line, xAnimation.opacity, xAnimation.para, xAnimation.rgb, xAnimation.rgbByClass, xAnimation.scroll, xAnimation.size, xAnimation, xAniOpacity, xAniRgb, xAniWH, xAniXY, xEllipse, xParaEq, xSequence, xSlideCornerTo, xSlideTo, xWinScrollTo.

DOM

xFirstChild, xGetElementById, xGetElementsByAttribute, xGetElementsByClassName, xGetElementsByTagName, xLoadLink, xLoadScript, xNextSib, xParent, xParentN, xPrevSib, xSmartLoad, xSmartLoad2, xSmartLoadScript.

Debug

xConsole, xEditable, xName, xParentChain, xSetIETitle.

Event

xAddEventListener, xDisableDrag, xDisableDrop, xEnableDrag, xEnableDrag2, xEnableDrop, xEvent, xHttpRequest, xPreventDefault, xRemoveEventListener, xStopPropagation.

Image

xImgAsyncWait, xImgRollSetup, xTriStateImage.

Iteration

xEach, xEachE, xEachN, xEachUntilReturn, xTimes, xWalkToFirst, xWalkToLast, xWalkTree, xWalkTree2, xWalkTree3, xWalkTreeRev, xWalkUL.

Misc

xCookie, xDef, xDeg, xGetURLArguments, xLibrary, xLinearScale, xNum, xRad, xRound, xStr.

Position

xCardinalPosition, xCen, xCenter, xGetEleAtPoint, xHasPoint, xIntersection, xLeft, xMoveTo, xOffset, xPageX, xPageY, xScrollLeft, xScrollTop, xTop.

Size

xClip, xColEqualizer, xDocSize, xHeight, xResizeTo, xWidth.

String

xCamelize, xCapitalize, xHex, xPad, xParseColor, xRgbToHex, xStrEndsWith, xStrRepeat, xStrReplaceEnd, xStrStartsWith, xTrim.

Style

xAddClass, xDisplay, xFindAfterByClassName, xFindBeforeByClassName, xGetComputedStyle, xGetCSSRules, xGetStyleSheetFromLink, xHasClass, xHasStyleSelector, xHasStyleSheets, xInsertRule, xOpacity, xRemoveClass, xStyle, xTagStyle, xToggleClass, xTraverseDocumentStyleSheets, xTraverseStyleSheet.

Table

xTable, xTableCellVisibility, xTableColDisplay, xTableCursor, xTableCursor2, xTableHeaderFixed, xTableIterate, xTableRowDisplay, xTableSync.

UI

xBar, xCalendar, xCollapsible, xDialog, xFenster, xFenster2, xMenu1, xMenu1A, xMenu1B, xMenu5, xMenu6, xModalDialog, xPopup, xSelect, xSplitter, xTabPanelGroup, xTextArea, xTooltipGroup.

Window

xClientHeight, xClientWidth, xWinClass, xWindow, xWinOpen.

xTooltipGroup

Description

Different tooltips applied to groups of elements.

Syntax

xTooltipGroup(grpClassOrIdList, tipClass, origin, xOffset, yOffset, hideDelay, sticky, textList)

Parameters

grpClassOrIdListThe css class name which you add to any element you want to trigger a tooltip - Or - an array of id strings.
tipClassThe css class name applied to the tooltip triggered by elements with the grpClass class name (or elements whose id is in the IdList).
originOne of 'right', 'top', or 'mouse'. For 'right' or 'top', the tooltip is positioned to the right (or top) of the trigger element. For 'mouse' the tooltip will follow the mouse. In all three cases the following offsets are applied.
xOffset/yOffsetThe tooltip is positioned relative to the above origin, offset by these amounts.
hideDelayAfter the mouse moves off of the trigger, this delay (in ms) will elapse before hiding the tip.
stickyIf true the tip will not be hidden until there is a click on the tip or a mouseover on some other trigger.
textListIf grpClassOrIdList is an array of IDs, then textList provides the tooltip text for the corresponding array index. If grpClassOrIdList is a class name then textList is not needed (tooltip text is taken from the element's TITLE attribute).

Source

Default.

// xTooltipGroup r10, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL
function xTooltipGroup(grpClassOrIdList, tipClass, origin, xOffset, yOffset, hideDelay, sticky, textList)
{
  //// Properties

  this.c = tipClass;
  this.o = origin;
  this.x = xOffset;
  this.y = yOffset;
  this.s = sticky;
  this.hd = hideDelay || 0;

  //// Constructor Code

  var i, tips;
  if (xStr(grpClassOrIdList)) {
    tips = xGetElementsByClassName(grpClassOrIdList);
    for (i = 0; i < tips.length; ++i) {
      tips[i].xTooltip = this;
      tips[i].xTooltipText = tips[i].title; // r10
      tips[i].title = '';                   // r10
    }
  }
  else {
    tips = new Array();
    for (i = 0; i < grpClassOrIdList.length; ++i) {
      tips[i] = xGetElementById(grpClassOrIdList[i]);
      if (!tips[i]) {
        alert('Element not found for id = ' + grpClassOrIdList[i]);
      }  
      else {
        tips[i].xTooltip = this;
        tips[i].xTooltipText = textList[i];
      }
    }
  }
  if (!xTooltipGroup.tipEle) { // only execute once
    var te = document.createElement("div");
    if (te) {
      te.id = 'xTooltipElement';
      xTooltipGroup.tipEle = te = document.body.appendChild(te);
      xAddEventListener(document, 'mousemove', xTooltipGroup.docOnMousemove, false);
    }
  }
} // end xTooltipGroup ctor

//// Static Properties

xTooltipGroup.tmr = null; // timer
xTooltipGroup.trgEle = null; // currently active trigger
xTooltipGroup.tipEle = null; // the tooltip element (all groups use the same element)

//// Static Methods

xTooltipGroup.docOnMousemove = function(oEvent)
{
  var t = null, e = new xEvent(oEvent);
  if (e.target) {
    t = e.target;
    while (t && !t.xTooltip) {
      t = t.offsetParent;
    }
    if (t) {
      t.xTooltip.show(t, e.pageX, e.pageY);
    }
    else if (xTooltipGroup.trgEle) {
      t = xTooltipGroup.trgEle.xTooltip;
      if (t && !t.s && !xTooltipGroup.tmr) {
        xTooltipGroup.tHide();
      }
    }
  }
};

xTooltipGroup.teOnClick = function()
{
  xTooltipGroup.hide();
};

xTooltipGroup.tHide = function()
{
  xTooltipGroup.tmr = setTimeout("xTooltipGroup.hide()", xTooltipGroup.trgEle.xTooltip.hd);
};

xTooltipGroup.hide = function()
{
  xMoveTo(xTooltipGroup.tipEle, -1000, -1000);
  xTooltipGroup.trgEle = null;
};

//// xTooltipGroup Public Method

xTooltipGroup.prototype.show = function(trigEle, mx, my)
{
  if (xTooltipGroup.tmr) {
    clearTimeout(xTooltipGroup.tmr);
    xTooltipGroup.tmr = null;
  }
  if (xTooltipGroup.trgEle != trigEle) { // if not active or moved to an adjacent trigger
    xTooltipGroup.tipEle.className = trigEle.xTooltip.c;
    xTooltipGroup.tipEle.innerHTML = trigEle.xTooltipText; // r10
//r9:    xTooltipGroup.tipEle.innerHTML = trigEle.xTooltipText ? trigEle.xTooltipText : trigEle.title;
    xTooltipGroup.trgEle = trigEle;
  }  
  if (this.s) {
    xTooltipGroup.tipEle.title = 'Click To Close';
    xTooltipGroup.tipEle.onclick = xTooltipGroup.teOnClick;
  }
  var x, y, tipW, trgW, trgX;
  tipW = xWidth(xTooltipGroup.tipEle);
  trgW = xWidth(trigEle);
  trgX = xPageX(trigEle);
  switch(this.o) {
    case 'right':
      if (trgX + this.x + trgW + tipW < xClientWidth()) { x = trgX + this.x + trgW; }
      else { x = trgX - tipW - this.x; }
      y = xPageY(trigEle) + this.y;
      break;
    case 'top':
      x = trgX + this.x;
      y = xPageY(trigEle) - xHeight(trigEle) + this.y;
      break;
    case 'mouse':
      if (mx + this.x + tipW < xClientWidth()) { x = mx + this.x; }
      else { x = mx - tipW - this.x; }
      y = my + this.y;
      break;
  }
  xMoveTo(xTooltipGroup.tipEle, x, y);
  xTooltipGroup.tipEle.style.visibility = 'visible';
};

Dependencies

xStr, xGetElementsByClassName, xGetElementById, xAddEventListener, xPageX, xWidth, xPageY, xHeight, xMoveTo, xEvent, xClientWidth

Demos

tooltips3.html - tooltips demo

Revisions

11: 5Jun07Removed use of xParent and xShow.
10: 23Apr07I've made a change based on an awesome 'tip' ;-) from Michael Hodgins. If grpClassOrIdList is a class then all trigger elements' titles are saved in the element's xTooltipText property. The element's title attribute is then set to "" so it will not cause a system tooltip. Thanks, Michael!
9: 17Feb07Re-implemented docOnMousemove so that a trigger's child elements do not cause the tip to close. Also, not using 'setAttribute' after creating the tooltip element - just assign an ID and rely on css. Also added sticky and hideDelay features.
8: 1Nov06It now uses createElement to create the tooltip element.
7: 29Oct06Fawn found a major bug. this.t should have been static. Thanks, Fawn!
6: 17May04removed closures
5: 31Mar04put in it's own file for use with XC
4: 1Mar04Now works in IE 4 and 5. Used document.write instead of document.createElement.
3: 13Dec03Almost completely rewritten. Now supports html for tooltip text instead of using the title attribute.
2: 12Dec03Correction for when the mouse moves directly from one trigger element to another.
1: 11Dec03Initial release.

License

By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.

Tech Support

Forum support is available at the X Library Support Forums.

About Cross-Browser.com

Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.

Search

Cross-Browser.com

World Wide Web

User Projects

If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.