Main Page | Modules | Directories | File List | File Members

utils.js File Reference

Go to the source code of this file.

Functions

 if (typeof Zapatec== 'undefined')
 setInterval ( 'var newScrollY=Zapatec.Utils.getPageScrollY(); '+ 'if(newScrollY!=oldScrollY){ '+ 'Zapatec.ScrollWithWindow.handler(newScrollY); '+ '}', 50)
 if (!Function.prototype.call)
 if (!Array.prototype.pop)

Variables

Zapatec Utils = {}
 define the Utils namespace
Zapatec Utils getAbsolutePos
Zapatec Utils fixBoxPosition
Zapatec Utils isRelated
Zapatec Utils removeClass
Zapatec Utils addClass
Zapatec Utils getElement
Zapatec Utils getTargetElement
Zapatec Utils stopEvent
Zapatec Utils addEvent
Zapatec Utils removeEvent
Zapatec Utils createElement
Zapatec Utils writeCookie
Zapatec Utils getCookie
Zapatec Utils makePref
Zapatec Utils loadPref
Zapatec Utils mergeObjects
Zapatec Utils __wch_id = 0
Zapatec Utils createWCH
Zapatec Utils setupWCH_el
Zapatec Utils setupWCH
Zapatec Utils hideWCH
Zapatec Utils getPageScrollY
Zapatec ScrollWithWindow = {}
Zapatec ScrollWithWindow list = []
Zapatec ScrollWithWindow stickiness = 0.25
Zapatec ScrollWithWindow register
Zapatec ScrollWithWindow unregister
Zapatec ScrollWithWindow handler
var oldScrollY = Zapatec.Utils.getPageScrollY()
Zapatec Utils destroy
Zapatec Utils newCenteredWindow
Zapatec Utils getWindowSize
Zapatec Utils selectOption
Zapatec Utils getNextSibling
Zapatec Utils getFirstChild
Zapatec Utils getChildText
Zapatec Utils insertAfter
Zapatec Utils generateID
Zapatec Utils addTooltip
Zapatec isLite = true
Zapatec Utils checkActivation
Zapatec is_ie = ( /msie/i.test(navigator.userAgent) && !Zapatec.is_opera )
 detect a special case of "web browser"
Zapatec is_ie5 = ( Zapatec.is_ie && /msie 5\.0/i.test(navigator.userAgent) )
 detect IE5.0/Win
Zapatec is_mac_ie = ( /msie.*mac/i.test(navigator.userAgent) && !Zapatec.is_opera )
 detect IE for Macintosh
Zapatec is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent)
 detect KHTML-based browsers
Zapatec is_konqueror = /Konqueror/i.test(navigator.userAgent)
 detect Konqueror
Zapatec is_gecko = /Gecko/i.test(navigator.userAgent)
 detect Gecko
Zapatec Log
Zapatec Utils Array = {}
 Zapatec.Utils.Array object which contains additional for arrays method.


Function Documentation

if typeof  Zapatec = = 'undefined'  ) 
 

define the global Zapatec namespace

Definition at line 16 of file utils.js.

if !Function.prototype.  call  ) 
 

Simulation of Function call() method that is missing in IE 5.0.

Definition at line 901 of file utils.js.

References Array.

if !Array.prototype.  splice  ) 
 

Simulation of Array pop() method that is missing in IE 5.0.

Definition at line 918 of file utils.js.

References Array.


Variable Documentation

Zapatec Utils = {}
 

define the Utils namespace

Definition at line 22 of file utils.js.

Zapatec Utils getAbsolutePos
  Retrieves the absolute position (relative to <body>) of a given element.

If it doesn't work in IE 6, try this:

    setTimeout(function() {
      var objPos = Zapatec.Utils.getAbsolutePos(objElement);
      do something with objPos
    }, 0);

Parameters:
el [HTMLElement] reference to the element.
Returns:
[object] { x, y } containing the position.

Definition at line 36 of file utils.js.

Zapatec Utils fixBoxPosition
  Modify the position of a box to fit in browser's view. This function will modify the passed object itself, so it doesn't need to return a value.

Parameters:
[object] box { x, y, width, height } specifying the area.

Definition at line 56 of file utils.js.

Zapatec Utils isRelated
  Determines if an event is related to a certain element. This is a poor substitute for some events that are missing from DOM since forever (like onenter, onleave, which MSIE provides). Basically onmouseover and onmouseout are fired even if the mouse was already in the element but moved from text to a blank area, so in order not to close a popup element when onmouseout occurs in this situation, one would need to first check if the event is not related to that popup element:

         function handler_onMouseOut(event) {
            if (!Zapatec.Utils.isRelated(this, event)) {
               this.style.display = "none";
            }
         }

Parameters:
el [HTMLElement] reference to the element to check the event against
evt [Event] reference to the Event object
Returns:
[boolean] true if the event is related to the element

Definition at line 101 of file utils.js.

Zapatec Utils removeClass
  Remove a certain [CSS] class from the given element.
Parameters:
el [HTMLElement] reference to the element.
className [string] the class to remove.

Definition at line 126 of file utils.js.

Zapatec Utils addClass
  Appends a certain [CSS] class to the given element.
Parameters:
el [HTMLElement] reference to the element.
className [string] the class to append.

Definition at line 143 of file utils.js.

Zapatec Utils getElement
  Retrieves the current target element for some event (useful when bubbling). This function is not actually very useful, but it's legacy from the old calendar code.
Parameters:
ev [Event] the event object.
Returns:
[HTMLElement] window.event.srcElement for MSIE, ev.currentTarget for other browsers.

Definition at line 152 of file utils.js.

Zapatec Utils getTargetElement
  Retrieves the target element for some event (useful when bubbling). This function is not actually very useful, but it's legacy from the old calendar code.
Parameters:
ev [Event] the event object.
Returns:
[HTMLElement] window.event.srcElement for MSIE, ev.target for other browsers.

Definition at line 164 of file utils.js.

Zapatec Utils stopEvent
  Stops bubbling and propagation of some event.
Parameters:
ev [Event] the event object
Returns:
false

Definition at line 175 of file utils.js.

Zapatec Utils addEvent
  Adds an event handler to a certain element. This function adds a handler using the DOM2 addEventListener (or attachEvent for MSIE). Doing this means that you can add multiple handlers for the same element and same event name, and they will be called in order.

WARNING: for really old browsers that don't support attachEvent nor addEventListener, it falls back to the default way: el.onclick = func. This means that you CANNOT add multiple handlers in those browsers, as a new one will override the old one.

Parameters:
el [HTMLElement] reference to the element.
evname [string] the event name, excluding the "on" prefix.
func event handler function.

Definition at line 202 of file utils.js.

Zapatec Utils removeEvent
  Removes an event handler added with Zapatec.Utils.removeEvent(). The prototype scheme is the same.

Definition at line 214 of file utils.js.

Zapatec Utils createElement
  Create an element of a certain type using document.createElement(). A function was needed in order to add some common attributes to all created elements, but also in order to be able to use it in XHTML too (Gecko and other W3C-compliant browsers).

This function will create an element of the given type and set certain properties to it: unselectable for IE, and the CSS "-moz-user-select" for Gecko, in order to make the element unselectable in these browsers. Optionally, if the second argument is passed, it will appendChild() the newly created element to its parent.

Parameters:
type [string] the tag name of the new element.
parent [HTMLElement, optional] a parent for the new element.
selectable [boolean] the flag to indicate wether element is selectable(rather usefull).
Returns:
[HTMLElement] reference to the new element.

Definition at line 239 of file utils.js.

Zapatec Utils writeCookie
  Sets a cooke given certain specifications. It overrides any existing cookie with the same name.

Parameters:
name [string] the cookie name.
value [string] the cookie value.
domain [string, optional] the cookie domain.
path [string, optional] the cookie path.
exp_days [number, optional] number of days of cookie validity.

Definition at line 268 of file utils.js.

Zapatec Utils getCookie
  Retrieves the value of a cookie.

Parameters:
name [string] the cookie name
Returns:
[string or null] a string with the cookie value, or null if it can't be found.

Definition at line 302 of file utils.js.

Zapatec Utils makePref
  Given an object, create a string suitable for saving the object in a cookie. This is similar to serialization. WARNING: it does not support nested objects.

Parameters:
obj [Object] reference to the object to serialize.
Returns:
[string] the serialized object.

Definition at line 330 of file utils.js.

Zapatec Utils loadPref
  The reverse of Zapatec.Utils.makePref(), this function unserializes the given string and creates an object from it.

Parameters:
txt [string] the serialized value.
Returns:
[Object] a new object if it was created successfully or null otherwise.

Definition at line 353 of file utils.js.

Zapatec Utils mergeObjects
  Merges the values of the source object into the destination object.

Parameters:
dest [Object] the destination object.
src [Object] the source object.

Definition at line 367 of file utils.js.

Zapatec Utils destroy
  Destroys the given element (remove it from the DOM tree) if it's not null and it's parent is not null.

Parameters:
el [HTMLElement] the element to destroy.

Definition at line 571 of file utils.js.

Zapatec Utils newCenteredWindow
  Opens a new window at a certain URL and having some properties.

Parameters:
url [string] the URL to open a new window to.
windowName [string] the name of the new window (as for target attribute).
width [number] the width of the new window in pixels.
height [number] the height of the new window in pixels.
scrollbars [string] "yes" or "no" for scrollbars.
Returns:
[object] the new window

Definition at line 587 of file utils.js.

Zapatec Utils getWindowSize
  Finds the size of the current web page. This is the usable size and does not include the browser's menu and buttons.

Returns:
[object] dimension with the height and width of the window

Definition at line 611 of file utils.js.

Zapatec Utils selectOption
  Given a reference to a select element, this function will select the option having the given value and optionally will call the default handler for "onchange".

Parameters:
sel [HTMLSelectElement] reference to the SELECT element.
val [string] the value that we should select.
call_default [boolean] true if the default onchange should be called.

Definition at line 646 of file utils.js.

Zapatec Utils getNextSibling
  A more flexible way to get the "nextSibling" of a given element. If the "tag" argument is passed, then this function will return the next sibling that has a certain tag. Otherwise it will simply return el.nextSibling.

Parameters:
el [HTMLElement] reference to the anchor element.
tag [string] the tag name of the returned node.
alternateTag [string] the alternate tag name of the returned node.
Returns:
[HTMLElement or null] el.nextSibling if tag is not passed, or the first element after el having the specified tag. Null is returned if no element could be found.

Definition at line 674 of file utils.js.

Zapatec Utils getFirstChild
  Similar to Zapatec.Utils.getNextSibling(), this function will return the first child of the given element that has a specified tag.

Parameters:
el [HTMLElement] reference to the anchor element.
tag [string] the tag name of the returned node.
alternateTag [string] the alternate tag name of the returned node.
Returns:
[HTMLElement] reference to the found node, or null if none could be found.

Definition at line 702 of file utils.js.

Zapatec Utils getChildText
  Function that concatenates and returns all text child nodes of the specified node.

Parameters:
objNode [Node] -- reference to the node.
Returns:
[string] -- concatenated text child nodes

Definition at line 734 of file utils.js.

Zapatec Utils insertAfter
  Similar to the DOM's built in insertBefore. Insert a node after an existing node.

Parameters:
el [oldNode] The existing element
el [newNode] the new element to insert after the old one. [number, static] maintains a list of generated IDs

Definition at line 757 of file utils.js.

Zapatec Utils generateID
  Generates an unique ID, for a certain code (let's say "class"). If the optional "id" argument is passed, then it just returns the id for that code (no generation). This function is sometimes useful when we need to create elements and be able to access them later by ID.

Parameters:
code [string] the class of ids. User defined, can be anything.
id [string, optional] specify if the ID is already known.
Returns:
[string] the unique ID

Definition at line 778 of file utils.js.

Zapatec Utils addTooltip
  Add a tooltip to the specified element.

Function that adds a custom tooltip for an element. The "target" is the element to where the tooltip should be added to, and the "tooltip" is a DIV that contains the tooltip text. Optionally, the tooltip DIV can have the "title" attribute set; if so, its value will be displayed highlighted as the title of the tooltip.

Parameters:
target reference to or ID of the target element
tooltip reference to or ID of the tooltip content element

Definition at line 800 of file utils.js.

Zapatec isLite = true
 

Definition at line 804 of file utils.js.

Zapatec Utils checkActivation
 

Definition at line 806 of file utils.js.

Zapatec is_ie = ( /msie/i.test(navigator.userAgent) && !Zapatec.is_opera )
 

detect a special case of "web browser"

Definition at line 881 of file utils.js.

Zapatec is_ie5 = ( Zapatec.is_ie && /msie 5\.0/i.test(navigator.userAgent) )
 

detect IE5.0/Win

Definition at line 884 of file utils.js.

Zapatec is_mac_ie = ( /msie.*mac/i.test(navigator.userAgent) && !Zapatec.is_opera )
 

detect IE for Macintosh

Definition at line 887 of file utils.js.

Zapatec is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent)
 

detect KHTML-based browsers

Definition at line 890 of file utils.js.

Zapatec is_konqueror = /Konqueror/i.test(navigator.userAgent)
 

detect Konqueror

Definition at line 893 of file utils.js.

Zapatec is_gecko = /Gecko/i.test(navigator.userAgent)
 

detect Gecko

Definition at line 896 of file utils.js.

Zapatec Log
  Displays error message. Override this if needed.

Parameters:
objArgs [number] error object: { severity: [string, optional] error severity, description: [string] human readable error description }

Definition at line 1012 of file utils.js.

Zapatec Utils Array = {}
 

Zapatec.Utils.Array object which contains additional for arrays method.

Definition at line 1027 of file utils.js.

Referenced by if().