The Pageflakes framework provides a set of functions that have been designed to work across all the major browsers, such that concise, platform independent code can be used to build flakes.
All the functions shown below are members of the PF object. They can be accessed by calling PF.functionName().
$(id) |
Shortcut for Use:
var e = PF.$('mytextbox');
var i = PF.$('myradiobutton');
|
$$(tagName, id, className, text)
|
Shortcut for document.createElement. The |
|
Removes the element from the parent node. |
removeAll(el) |
Removes all child elements from the element. It recursively traverses all children and calls remove on them. |
This example demonstrates how to perform some simple DOM manipulations, including assigning an element to a variable and removing an element using the PF.Remove method.
|
Instead of:
Use any of the following:
PF.nodisplay(e);
PF.nodisplay('mydiv');
PF.ND(‘mydiv’);
|
|
Instead of: if (mz) e.textContent = text; else e.innerText = text; Use either of the following: PF.T('mydiv', 'text to set');
PF.T(e, 'text to set');
|
|
Instead of: Use any of the following:
PF.display(e);
PF.display('mydiv');
PF.D(‘mydiv’);
|
|
Returns true if the element is visible; false otherwise. |
clearDisplay(el) |
Clears the e.style.display property and reverts to what is defined in CSS. |
hide(el)
|
Sets visibility style to hidden. |
visible(el)
|
Sets visibility style to visible. |
toggleDisplay(el) |
Toggles display attribute to show/hide element. |
switch(display, nodisplay)
|
Displays the first item and hides the second item. |
toggleVisibility(name) |
Toggle display style between “none” and “block”. |
canYouSeeMe(target) |
Returns true if the item isvisible on the screen, or false if it is notvisible. It does so by walking through the ancestors and checking whether any of them has the display attribute set to none or the visibility attribute set to hidden. |
|
|
Sets focus to the element. |
|
|
Disables an element. No mouse events will be captured. Or: |
|
|
Enables the element that had been disabled. For example:
PF.enabled('mybutton');
PF.enabled(e);
|
|
|
Disables all frames and IFRAMEs on the page by setting |
|
|
Adds hover behavior to an element. When the mouse hovers over the item, the specified class is added to the element. When the mouse leaves, the specified class is removed. |
|
|
Adds a CSS class to an element. Previous classes are preserved. |
|
|
Removes a particular CSS class from element. |
|
|
When a series of elements exist where only one can be selected at a time (e.g. tabs or radio buttons), this function can be used to apply a class to the selected item and clear that class from unselected items.
|
|
|
Apply a class to child elements of a node based on some expression. Consider the following example:
Now, to modify the class of a particular tab, the following can be used: This example assigns the In general, the specified class is assigned to the all elements where the specified function evaluates to true. |
centerDiv(div) |
Position an absolute div at the center of the visible area. |
changeParent(id, newParentId) |
Move an element from its current parent to the new parent. |
makeOnTop(el) |
Position the absolute element on top of any other absolute element. |
getPosition(obj) |
Get the bounds of the specified element as an array. For example:
|
setBusy() |
Change the cursor to hourglass. |
setIdle() |
Set cursor to the default arrow. |
showProgress() |
Display the progress bar. |
hideProgress() |
Hide the progress bar. |
setOpacity(id,val) |
Set the opacity of an element. |
changeOpacity(opacity, id) |
Changes the opacity of any given element by 'opacity'. |
clearOpacity(id) |
Makes an element 100% opaque. |
opacity(el, startOpacity, endOpacity, millisecond, callback)
|
Change the opacity from a given value to new value within a fixed time defined in milliseconds. When execution is complete, the callback is invoked. |
shiftOpacity(id, milliseconds) |
Toggles the opacity from 0 to 100 of a given element in the specified time period. |
currentOpacity (id,opacEnd,millisec) |
Change the opacity from the current value to the specified ending value within the given time (specified in milliseconds). |
createCookie(name, value, day) |
Creates a cookie with the given name, value, and expiration (in days). |
readCookie(name) |
Returns the value of the cookie |
cloneObject(ob) |
Makes a clone of an object by copying all of its properties and functions.
|
|
|
Adds a script tag in the |
|
|
HTML encodes a string by replacing special characters with |
|
|
Returns the value of the query string parameter. For example, if the current URL is: http://example.com/default.aspx?id=123 Then to get the “123” value the following can be used: |
|
|
Used to handle exceptions produced form server side calls. Whenever you call a server side method, the 3rd argument is an exception callback. For example:
|
|
|
Returns true if a Flash player is installed, false |
|
|
Get the error message from the exception. |
|
|
Executes any JavaScript code passed as parameter. |
|
|
Removes all HTML tags from the provided string and returns the result as a string. |
|
|
Format the supplied text by replacing line breaks with |
|
|
This function grays out the specified text box, filling it in with the text specified. This can be used to provide help text on how the text box should be filled in. When the user selects the text box, the box clears the text and restores the normal background color. |
|
|
Returns a delegate reference that fires the function on the context of the passed object. |
|
|
Adds an event handler to an element. This is a cross-browser solution for subscribing events on UI elements. The following way of hooking into events should not be used: This leaks memory in Internet Explorer 6 if not used carefully. Moreover, it removes any existing event handler on the same event. Instead, do it this way: And define the callback function outside the scope: The benefit of this type of event handler is that the event parameter is passed in the callback in a cross-browser implementation. This |
removeEvent(e, eventName, handler) |
Removes an event handler from an element. However, only event handlers that were subscribed by calling addEvent can be removed. This function ensures that event handlers are released properly to prevent IE 6 from leaking memory. Event handlers should be removed as soon as they are no longer required. |
|
|
Clears all event handlers from an element. This ensures that the DOM element is ready to be released and solves a memory leak problem in Internet Explorer 6. |
|
|
IE treats events differently that other browsers. IE uses window.Event which Firefox doesn't support. Moreover, most browsers pass the event as an argument to the event callback function, which IE does not. In order to avoid such problems, all event handlers can be declared by giving them an argument for getting the event, and inside the event, the fix function can be invoked to ensure that the event parameter has the right value. For example:
It is also possible to use the Callback function, described below. |
|
|
This method provides a browser independent method of invoking event callbacks (for additional information see also the fix() function above). Specifically, it takes care of the difference between Internet Explorer, and all other browsers in passing the event data to the event handler. For example: The code is evaluated only when the event fires. The function is defined as: PF.Callback = function(code)
{
return function(event)
{
event = PF.fix(event);
eval(code);
}
}
|
|
|
Prevents the event from bubbling up to the parent element. |
|
|
Calls the specified function in a timer with near zero delay. In Firefox, if the innerHTML of an element is set and the child nodes are accessed immediately, the operation will sometimes fail since the DOM elements are not immediately available. As a workaround, the following code can be used to complete the code execution and access the elements with a delay:
|
scrollTop()
|
Scrolls to top of the page. |
scrollBottom()
|
Scrolls to bottom of the page. |
getContentHeight()
|
Returns the height of the document. |
getViewportWidth()
|
Returns the width of the window. |
getViewportHeight()
|
Returns the height of window. |
getViewportScrollX()
|
Returns the horizontal scrollbar position |
getViewportScrollY()
|
Returns the vertical scrollbar position |
getXmlDoc(xmlString) |
Returns an XML DOM object from an XML string. |
getFirstNode(xmlDoc, pattern) |
Returns the first XML node from the provided XML document that matches the provided pattern. For example: To find an element by specifying multiple node names, use a pattern like this: |
getNodes(xmlDoc, pattern) |
Returns and array of XML nodes (JavaScript To find elements by specifying multiple node names, use a pattern like this: |
blockUI(msg) |
Dims the whole page, such that a popup or other overlay can be displayed. If the |
unblockUI() |
Returns the page to its normal state. |