Global functions: Bicycle Core
Bicycle Core is the main collection of 3rd party functions. Credits go to (see source code for details):
- Embimedia
- Svend Tofte
- Ben Nadel
- Mootools
- Nomadic Functions
- Mega69
- Robert Nyman
- http://programming.arantius.com/dollar-e
- http://www.thescripts.com/forum/thread596105.html
Note: All of these functions are available in the Bicycle Chain wrapper, anyway this package is mantained for compatibility reasons and for those developers not needing chainability.
| Field Attributes | Field Name and Description |
|---|---|
| <static> |
Custom events object requires Bicycle Chain |
|
ff js API (c) 2005 by Sven Helmberger ( sven dot helmberger at gmx dot de )
project homepage: http://fforw.de/post/ff_javascript_library/
available under a revised BSD-like library |
| Method Attributes | Method Name and Description |
|---|---|
| DOM | |
|
$getEls(multiple)
Gets multiple elements by id. |
|
getElements(tagName, opt)
Collects elements with options |
|
$TN(tag, index, parent)
Shortcut to extract the first or the last element of an "elementsByTagName()" array. Returns the first (if index is not defined) or last (if index is "last") element in the array of elements found inside the parent node. |
|
$EN(name, index, parent)
Shortcut to extract the first or the last element of an "elementsByName()" array.
Returns the first (if index is not defined) or last (if index is "last") element with given name attribute inside the parent node. |
|
getNext(node)
Returns the next non-text element relative to the node element. |
|
getPrev(node)
Returns the previous non-text element relative to the node element. |
|
getText(el)
Gets the text inside a given element with no regards to childrens. |
|
getElementsByClassName(className, tag, elm)
Gets an elements collection filtered by class name |
|
| Styles /Attributes | |
$S(el)
Shortcut to the .style of an element. |
|
getStyle(element, property)
Returns the value of a specific style of an element. |
|
getDimension(element)
Gets Element Dimensions. |
|
getPosition(element, top, scrolling)
Returns an object with the position in px of an element relative to an ancestor. |
|
getMousePosition(e, element)
Returns the position of your cursor, relative to an element. |
|
changeDisplay(element)
Toggles element visibility (CSS display) |
|
uniqueId(prefix)
Gets a unique id string for an element. |
|
| <static> | ff.dom.setAttribute(e, a, v)
Crossbrowser method to set the value of the attribute of the given element. If element is a string it points to a defined element ID |
| <static> | ff.dom.getAttribute(e, a)
Crossbrowser method which returns the value of the attribute of the given element. If element is a string it points to a defined element ID |
| DOM Manipulation | |
$E(data)
document.createElement convenience wrapper
The data parameter is an object that must have the "tag" key, containing
a string with the tagname of the element to create. |
|
addDIV(id, parent, text)
Creates a new DIV element with given ID and appends it to the given AppendElement. |
|
| <static> | ff.dom.clear(elem)
Removes all children from the given DOMElement |
| <static> | ff.dom.replace(elem, newChildren)
Replaces the current children of the DOM element with the given child(ren) |
| <static> | ff.dom.append(elem, c)
Appends the given child(ren) to the children of the given DOM element |
insertAfter(parent, node, referenceNode)
Inserts the node element inside the parent node and after a reference node. |
|
| Events Handling | |
addHandler(element, types, handler)
Attaches specified event(s) function to passed in element(s) |
|
removeHandler(element, types, handler)
Removes an event handler. |
|
| Utilities: Strings | |
camelCase(string)
Converts a hyphenate string to camelcase. |
|
| Utilities: Array | |
isArray(object)
Checks if the passed in object is an Array. |
|
| Utilities: Object | |
extendObject(destination, source)
Extends the destination Object with passed in source Object. |
|
|
getLength(object)
Gets the number of an Object's properties. |
|
$merge(obj)
Merges a number of objects recursively without referencing them or their sub-objects. requires Bicycle Chain |
|
| Utilities: General | |
|
Browser sniffer. |
|
|
$defined(obj)
Checks if the passed in value/object is defined requires Bicycle Chain |
|
|
$type(obj)
Returns the type of object that matches the element passed in. requires Bicycle Chain |
|
ff js API (c) 2005 by Sven Helmberger ( sven dot helmberger at gmx dot de )
project homepage: http://fforw.de/post/ff_javascript_library/ available under a revised BSD-like library
Author: Sven Helmberger ( sven dot helmberger at gmx dot de ).
<div id="myDiv"></div>
<div id="my2ndDiv"></div>
$getEls("myDiv"); //returns a reference to myDiv
$getEls("myDiv",DOMElementReference); // returns [myDiv,DOMElementReference]
- Parameters:
- {String[]|DOMElement[]} multiple
- elements id or element reference
- Returns:
- {DOMElement|Array} Returns an element reference if a single argument is passed else an Array of elements references
- See:
- liberty - Basic JavaScript Library 0.1
Author: Marco Solazzi, inspired by Liberty getElements.
// Get a list of all links, with class myClass.
var elements = getElements('a',{'class':'myClass'});
// Get a list of all links, which have class myClass and a url that contains 'google'.
var elements2 = getElements('a',{'class':'myClass', 'href':/google/});
// Get a list of all links, which have class myClass inside the element with id myId.
var elements2 = getElements('a',{'class':'myClass', parent:$getEls('myId')});
- Parameters:
- {String} tagName
- Tag name to collect or '*' for all tags
- {Object} opt Optional
- attributes filter, specify html attribute and value as string or regular expression. Use '*' to just check attribute presence; You can pass a parent element by adding property 'parent' : DOMElement
- Returns:
- {Array} Returns an array of matched Elements
elementsByTagName()" array.Returns the first (if
index is not defined) or last (if index is "last") element in the array of elements found inside the parent node. If
parent is not defined defaults to whole document. - Parameters:
- {String} tag
- Name of tags to collect
- {String} index Optional
- if "last" returns the last element of the array
- {DOMElement} parent Optional
- Parent element
- Returns:
- {DOMElement} Returns the first (if
indexis not defined) or last (ifindexis "last") element in the array
elementsByName()" array.Returns the first (if
index is not defined) or last (if index is "last") element in the array of elements found inside the parent node. If
parent is not defined defaults to whole document. - Parameters:
- {String} name
- Name of elements to collect
- {String} index Optional
- if "last" returns the last element of the array
- {DOMElement} parent Optional
- Parent element
- Returns:
- Returns the first (if
indexis not defined) or last (ifindexis "last") element in the array
node element. Author: Ben Nadel.
- Parameters:
- {DOMElement} node
- The reference node
- Returns:
- {DOMElement} The next non-text element relative to the
nodeelement
node element. Author: Ben Nadel.
- Parameters:
- {DOMElement} node
- The reference node
- Returns:
- {DOMElement} The previous non-text element relative to the
nodeelement
- Parameters:
- {DOMElement} el
- Element containing the text
- Returns:
- {String} The text inside a given element with no regards to childrens
Author: Robert Nyman, http://www.robertnyman.com.
- Parameters:
- {String} className
- The class name
- {String} tag Optional
- Tag name
- {DOMElement} elm Optional
- Parent element
.style of an element.Note that, differently from
GetStyle(), CSS properties use Javascript names: http://codepunk.hardwar.org.uk/css2js.htm
//Set the backgrond color of an element with ID “myId” to “#FFFF00”
$S(“myId”).backgroundColor = “#FFFF00”;
- Parameters:
- {DOMElement|String} el
- Element reference or ID string
//Get the backgrond color of an element with ID "myId"
getStyle("myId", "background-color");
- Parameters:
- {DOMElement|String} element
- Could be an element reference or a ID string
- {String} property
- The name of the CSS property
- Returns:
- {String} The CSS style value
- See:
- liberty - Basic JavaScript Library 0.1
//Get dimensions of element with id 'what'
var dim = getDimension('what');
alert('Dimensions:'+dim.width+' x '+dim.height);
- Parameters:
- {DOMElement|String} element
- An element reference or a id String
- Returns:
- {Object} Returns an object with real width and height of a HTML element in px.
- See:
- liberty - Basic JavaScript Library 0.1
var position = getPosition('elementId', $('anchestorId'));
alert('Position: '+position.x+', '+position.y);
- Parameters:
- {DOMElement|String} element
- Element Reference or ID string
- {DOMElement|String} top Optional, Default: "document.body"
- Ancestor of passed in element. If not defined defaults to
- {Bool} scrolling Optional
- Defines if the scrolling inside of elements should be subtracted (default: true - better for absolute positioning).
- Returns:
- {Object} Object with x and y keys
- See:
- liberty - Basic JavaScript Library 0.1
// alert mouse position when clicking on a specified element
addHandler($('elementId'),'click',function (e) {
var position = getMousePosition(e,this);
alert('Mouse Position: '+position.x+', '+position.y);
});
- Parameters:
- {Object} e
- Event reference
- {DOMElement|String} element Optional
- A reference element, either DOM element or ID string
- Returns:
- {Object} Object with x and y keys
- See:
- liberty - Basic JavaScript Library 0.1
display property ) - Parameters:
- {DOMElement|String} element
- Element to show or hide
- Returns:
- {String} CSS display property value
- See:
- liberty - Basic JavaScript Library 0.1
- Parameters:
- {String} prefix
- Prefix for the id
- Returns:
- {String} Returns a unique string formed by prefix+number (starting from 0), prefix defaults to “id”.
- See:
- liberty - Basic JavaScript Library 0.1
a,v) for a given element (e). If element is a string it points to a defined element ID
- Parameters:
- {String|DOMEelent} e
- Element reference or ID string
- {String} a
- Attribute to set
- {String} v
- Attribute value
- See:
- ff javascript library 1.11
a) from an element (e).If element is a string it points to a defined element ID
- See:
- ff javascript library 1.11
document.createElement convenience wrapper.
The data parameter is an object that must have the "tag" key, containing
a string with the tag's name of the element to create.
It can optionally have
a "children" key which can be:
- a string,
- another "
data" object, - an array of "
data" objects to append to this element as children.
Any other key is taken as an
attribute to be applied to this tag.
var element=$E({
tag:'div',
className:'toolGroup',
id:'toolGroup_1',
children:{
tag:'div',
className:'roundBarTop',
children:[{
tag:'div',
className:'leftEdge'
},{
tag:'div',
className:'rightEdge'
},{
tag:'div',
className:'heading',
children:[{
tag:'a',
className:'collapser'
},
'Group Heading'
]
}]
}
});
- Parameters:
- {Object} data
- The data representing the element to create
- Returns:
- {Element} The element created.
- See:
- http://programming.arantius.com/dollar-e
DIV element with given ID and appends it to the given parent.
addDIV('child','parentEl','this is a test');
// returns this is a test
- Parameters:
- {String} id
- The ID of the new DIV
- {DOMElement|String} parent Optional
- Parent container Element, either an element reference or ID string
- {String} text Optional
- Text to insert in the new DIV
- Returns:
- {DOMElement} the new DIV element
- Parameters:
- {DOMElement} elem
- The DOM element
- See:
- ff javascript library 1.11
- Parameters:
- {DOMElement} elem
- The DOM element
- {DOMElement|Array} newChildren
- The new child/children
- See:
- ff javascript library 1.11
- Parameters:
- {DOMElement} elem
- The DOM element
- {DOMElement|Array} e
- The child/children elements
- See:
- ff javascript library 1.11
node element inside the parent node and after a reference node. - Parameters:
- {DOMElement} parent
- The parent node
- {DOMElement} node
- The Element to insert inside the parent
- {DOMElement} referenceNode Optional
- The node after which insert passed in node
- See:
- http://www.dustindiaz.com/top-ten-javascript/
// Fire the function “tryMe()” when clicking on the element with ID “myId”
addHandler('myId', 'click', tryMe);
// Set the links title attribute of the document to show the query of each Google link
var elements = getElements('a',{'href':/google/i});
//now add an event handler function to those elements
// - for the events 'mouseover' and 'mouseout'
var changeTitle = function(event) {
if (event.type == 'mouseover') {
document._title = document.title;
document.title = this.href;
}
else if (event.type == 'mouseout') {
document.title = document._title;
}
}
addHandler(elements, ['mouseover', 'mouseout'], changeTitle);
- Parameters:
- {Array|DOMElement|String} element
- ID string reference, or DOM element reference. Either single or as array
- {String|Array} types
- Event type(s) without "on" prefix. Either single or as array
- {Function} handler
- Function to bind to element(s) on specified event(s)
- Returns:
- {Bool} Returns true if handler is a function
- See:
- liberty - Basic JavaScript Library 0.1
handler undefined, all handlers for the specified event types are removed. //Remove all link handlers from link elements:
removeHandler(getElements('a'), ['mouseover', 'mouseout']);
- Parameters:
- {Array|DOMElement|String} element
- ID string reference, or DOM element reference. Either single or as array
- {String|Array} types
- Event type(s) without "on" prefix. Either single or as array
- {Function} handler Optional
- Function to bind to element(s) on specified event(s)
- Returns:
- {Bool} Returns true if handler is specified and is a function
- See:
- liberty - Basic JavaScript Library 0.1
Author: Valerio Proietti.
camelCase("just-simple-test"); //returns justSimpleTest
- Parameters:
- {String} string
- The string to convert
- Returns:
- {String} The converted string
- See:
- Mootools 1.0
var myArray = ['apple', 'lemon', 'orange', 'banana']; alert(isArray(myArray));
// will alert "true"
- Parameters:
- {Object} object
- The object to check
- Returns:
- {Bool} Returns true if object is an array
- See:
- liberty - Basic JavaScript Library 0.1
extendObject(String.prototype, {
escapeXML: function() {
// function code ...
},
unescapeXML: function() {
// function code ...
}
});
- Parameters:
- {Object} destination
- The object to extend
- {Object} source
- The object to use for extension
- Returns:
- {Object} The Extended object
- See:
- liberty - Basic JavaScript Library 0.1
- Parameters:
- {Object} object
- The passed in object
- Returns:
- {Number} Returns the number of an Object's properties
- See:
- liberty - Basic JavaScript Library 0.1
Author: Valerio Proietti (from MooTools 1.11).
- Parameters:
- {Object} obj
- Any number of objects
- Returns:
- {Object} Merged object
Browser sniffer.
Possible browser match:
- $browser.ie // Internet Explorer
- $browser.ie6 // Internet Explorer 6
- $browser.ie7 // Internet Explorer 7
- $browser.ff // Firefox
- $browser.moz // Mozilla
- $browser.ns // Netscape
- $browser.op // Opera
- $browser.saf // Safari
- $browser.kq // Konqueror
Author: Mega69 - ExtendDOM 0.8.
- Returns:
- {Bool} Returns true if browser matches.
- See:
- http://www.sitomega.net/projects/extendDOM/main.php
Author: Valerio Proietti (from MooTools 1.11).
- Parameters:
- {Object} obj
- Any type of variable to check
- Returns:
- {Bool} Returns true if the passed in value/object is defined, that means is not null or undefined.
Author: Valerio Proietti (from MooTools 1.11).
var myString = 'hello';
$type(myString); //returns "string"
- Parameters:
- {Object} obj
- Any type of variable
- Returns:
- {String|Bool}
- 'element' - if obj is a DOM element node
- 'textnode' - if obj is a DOM text node
- 'whitespace' - if obj is a DOM whitespace node
- 'arguments' - if obj is an arguments object
- 'object' - if obj is an object
- 'string' - if obj is a string
- 'number' - if obj is a number
- 'boolean' - if obj is a boolean
- 'function' - if obj is a function
- 'regexp' - if obj is a regular expression
- 'class' - if obj is a Class. (created with new Class, or the extend of another class).
- 'collection' - if obj is a native htmlelements collection, such as childNodes, getElementsByTagName .. etc.
- false - (boolean) if the object is not defined or none of the above.