Login   Register  
PHP Classes
elePHPant
Icontem

File: infobox.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Peter Klauer  >  Info Box  >  infobox.js  >  Download  
File: infobox.js
Role: Auxiliary data
Content type: text/plain
Description: Javascript file from http://www.knopper.net/knoppix/
Class: Info Box
Generate help tooltips for Web pages using DHTML
Author: By
Last change: Updated Javascript to work with the MSIE IFRAME-hack.
Date: 8 years ago
Size: 6,151 bytes
 

Contents

Class file image Download
//
// Bubblehelp infoboxes, (C) 2002 Klaus Knopper <infobox@knopper.net>
// You can copy/modify and distribute this code under the conditions
// of the GNU GENERAL PUBLIC LICENSE Version 2.
//
//
// Changes by Knito:
// 2005-10-15: Changed: maketip()
//             New: getScrollXY(), setCookie()
//
var IWIDTH=250  // Tip box width
var ns6         // Arw we using Netscape6? // Knito
var ns4         // Are we using Netscape4?
var ie4         // Are we using Internet Explorer Version 4?
var ie5         // Are we using Internet Explorer Version 5 and up?
var kon         // Are we using KDE Konqueror?
var opera       // Are we using Opera?

var x,y,winW,winH  // Current help position and main window size
var idiv=null   // Pointer to infodiv container
var idiv1=null  // helper for iframe-hack
var px="px"     // position suffix with "px" in some cases

function nsfix(){setTimeout("window.onresize = rebrowse", 2000);}

function rebrowse(){window.location.reload();}

function hascss(){ return gettip('infodiv')?true:false }

function infoinit(){
 ns6=(document.getElementById && !document.all)?true:false;
 ns4=(document.layers)?true:false;
 ie4=(document.all)?true:false;
 ie5=((ie4)&&((navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)))?true:false;
 kon=(navigator.userAgent.indexOf('konqueror')>0)?true:false;
 
 opera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; 
 
 x=0;y=0;winW=800;winH=600;
 idiv=null;
 document.onmousemove = mousemove;
 if(ns4&&document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
 // Workaround for just another netscape bug: Fix browser confusion on resize
 // obviously conqueror has a similar problem :-(
 if(ns4||kon||opera){ nsfix() }
 if(ns4) { px=""; }
}

function untip(){
 if(idiv) idiv.visibility=ns4?"hide":"hidden";
 idiv=null;

  // also hide the iframe underneath the <div>
  //
  idivif=document.getElementById('infodivif');
  if (idivif) {
    idivif.style.visibility = "hidden";
  }


}

function gettip(name){

	return ( document.layers&&document.layers[name])?document.layers[name]:(document.all&&document.all[name]&&document.all[name].style)?document.all[name].style:document[name]?document[name]:(document.getElementById(name)?document.getElementById(name).style:0);}

// Prepare tip boxes, but don't show them yet
function maketip(name,title,text)
{
  // this function replaces the original infobox.js::maketip()
 if(hascss()) document.write('<div id=\"'+name+'\" class=\"infobox\" name=\"'+name+'\" style=\"width:'+IWIDTH+px+'!important;\"><div class=\"infoboxcaption\">'+title+'<\/div><div class=\"infoboxbody\">'+text+'<\/div><\/div>');
 
}
		
function showtip(){
  // this function replaces the original infobox.js::showtip() which was loaded before
  // using getScrollXY() it is capable of respecting scrolled positions
  // knito - at - knito - dot - de 2005-03-03 http://www.ingoknito.de

  var xy;
  xy = getScrollXY();
  idiv.left=(((x+IWIDTH+20)<winW)?x+12:x-IWIDTH-5)+xy[0]+px;
  idiv.top=(((y+90)<winH)?y+12: y-90)+xy[1]+px;
  idiv.visibility=ns4?"show":"visible";
}

function tip(name){
 if(hascss()){
  if(idiv) untip();
  idiv=gettip(name);
  if(ie4 || ie5)
  {
    idiv1=document.getElementById(name);
  }
  if(idiv)
  {
   winW=(window.innerWidth)? window.innerWidth+window.pageXOffset-16:document.body.offsetWidth-20;
   winH=(window.innerHeight)?window.innerHeight+window.pageYOffset  :document.body.offsetHeight;
   if(x<=0||y<=0){ // konqueror can't get mouse position
    x=(winW-IWIDTH)/2+(window.pageXOffset?window.pageXOffset:0); y=(winH-50)/2+(window.pageYOffset?window.pageYOffset:0); // middle of window
   }
   showtip();
  }
 }
}

// getScrollXY() 
// found at http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=16 on 2005-03-02
// JavaScript tutorial 
// Part 16 of 29; Obtaining the browser window size

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( opera || typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = 0; // window.pageYOffset;
    scrOfX = 0; // window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement &&
      ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


function mousemove(e){
 if(e)   {x=e.pageX?e.pageX:e.clientX?e.clientX:0; y=e.pageY?e.pageY:e.clientY?e.clientY:0;}
 else if(event) {x=event.clientX; y=event.clientY;}
 else {x=0; y=0;}
 if((ie4||ie5) && document.documentElement) // Workaround for scroll offset of IE
  {
    x+=document.documentElement.scrollLeft;
    y+=document.documentElement.scrollTop;
  }
 if(idiv) showtip();
}

/**
 * Sets a Cookie with the given name and value.
 * found on 2005-03-11 at http://www.netspade.com/articles/javascript/cookies.xml		
 * Cookies in JavaScript / JavaScript Cookie Functions 
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
		

// Initialize after loading the page
window.onload=infoinit;

// EOF infobox.js