namespace
SAPO.Dom.Css
requires if IE SAPO.Dom.Event
requires if method changeFontSize is used SAPO.Dom.Selector
Function Summary
add a class to a given element
adds or removes a class to the given element according to addRemState
Adds css style tags to the head section of a page
Adds a link tag for a stylesheet to the head section of a page
changes the font size of the elements which match the given CSS rule
For this function to work, the CSS file must be in the same domain than the host page, otherwise JS can't access it.
use this to obtain the value of a CSS property (searched from loaded CSS documents)
Gets the value for an element's style attribute
hide
(DOMElement|String
elm)
Hides an element
removes a class from a given element
Adds or removes a class name. Utility function, saves many if/elses.
sets the opacity of given client a given element
shows or hides according to param show
Shows or hides an element depending on current state
Function Details
function addClassName
addClassName(DOMElement|String
elm, String
class)
add a class to a given element
Parameters:
elm
- DOM element or element id
class
name function addRemoveClassName
addRemoveClassName(DOMElement|string
elm, string
className, boolean
addRemState)
adds or removes a class to the given element according to addRemState
Parameters:
elm
- DOM element or element id
className
- class name
addRemState
- which method to apply function appendStyleTag
Adds css style tags to the head section of a page
Parameters:
selector
- The css selector for the rule
style
- The content of the style rule
options
- Options for the tag -
String type
- file type -
Boolean force
- if true, style tag will be appended to end of head
function appendStylesheet
appendStylesheet(String
path, Object
options)
Adds a link tag for a stylesheet to the head section of a page
Parameters:
function changeFontSize
changes the font size of the elements which match the given CSS rule
For this function to work, the CSS file must be in the same domain than the host page, otherwise JS can't access it.
Parameters:
selector
CSS selector rule
delta
number of pixels to change on font-size
[op]
supported operations are '+' and '*'. defaults to '+'
[minVal]
if result gets smaller than minVal, change does not occurr
[maxVal]
if result gets bigger than maxVal, change does not occurr function decToHex
converts decimal to hexadecimal values, for use with colors
Parameters:
dec
- Either a single decimal value , an rgb(r, g, b) string
or an Object with r, g and b properties
Returns:
Hexadecimal value
function getPropertyFromStylesheet
use this to obtain the value of a CSS property (searched from loaded CSS documents)
Parameters:
selector
- a CSS rule. must be an exact match
property
- a CSS property
Returns:
{String} value of the found property, or null if it wasn't matched
function getStyle
Gets the value for an element's style attribute
Parameters:
elm
- DOM element or element id
style
- Which css attribute to fetch
Returns:
Style value
function hasClassName
Boolean
hasClassName(DOMElement|String
elm, String
class)
Parameters:
elm
- DOM element or element id
class
name
Returns:
true if a given class is applied to a given element
function hexToDec
Number
hexToDec(String
hex)
converts hexadecimal values to decimal, for use with colors
Parameters:
hex
- hexadecimal value with 6, 3, 2 or 1 characters
Returns:
Object with properties r, g, b if length of number is >= 3 or
decimal value instead.
function hide
hide(DOMElement|String
elm)
Hides an element
Parameters:
elm
- DOM element or element id function removeClassName
removeClassName(DOMElement|String
elm, String
class)
removes a class from a given element
Parameters:
elm
- DOM element or element id
class
name function setClassName
setClassName(DOMElement|String
elm, String
class, Boolean
true)
Adds or removes a class name. Utility function, saves many if/elses.
Parameters:
elm
- DOM element or element id
class
name
true
to add, false to remove function setOpacity
setOpacity(DOMElement|String
elm, Number
value)
sets the opacity of given client a given element
Parameters:
elm
- DOM element or element id
value
- allows 0 to 1(default mode decimal) or percentage (warning using 0 or 1 will reset to default mode) function setStyle
setStyle(DOMElement|String
elm, String
style)
Sets the value for an element's style attribute
Parameters:
elm
- DOM element or element id
style
- Which css attribute to set function show
show(DOMElement|String
elm, String
forceDisplayProperty)
Makes an element visible
Parameters:
elm
- DOM element or element id
forceDisplayProperty
- Css display property to apply on show function showHide
showHide(DOMElement|String
elm, boolean
show)
shows or hides according to param show
Parameters:
elm
- DOM element or element id
show
function toggle
toggle(DOMElement|String
elm, Boolean
forceShow)
Shows or hides an element depending on current state
Parameters:
elm
- DOM element or element id
forceShow
- Forces showing if element is hidden