Skip to content

Latest commit

 

History

History
962 lines (353 loc) · 14.2 KB

API.md

File metadata and controls

962 lines (353 loc) · 14.2 KB

gaspard 0.0.0-development

Lightweight DOM helpers

src/attributes.js

hasClass(element, className)

Determine whether the element is assigned the given class.

Parameters
Name Type Description
element Element A DOM node  
className string The class name to search for  
Returns
  • boolean Result

addClass(element, classNames)

Adds the specified class(es) to element.

Parameters
Name Type Description
element Element A DOM node  
classNames string One or more space-separated classes to be added to the class attribute  
Returns
  • Void

removeClass(element, classNames)

Remove a single class, multiple classes, or all classes from each element in the set of matched elements.

Parameters
Name Type Description
element Element A DOM node  
classNames string One or more space-separated classes to be removed to the class attribute  
Returns
  • Void

toggleClass(element, classNames, state)

Add or remove one or more classes from element, depending on either the class's presence or the value of the state argument.

Parameters
Name Type Description
element Element A DOM node  
classNames string One or more class names (separated by spaces) to be toggled for each element in the matched set  
state boolean A Boolean value to determine whether the class should be added or removed  
Returns
  • Void

attr(element, attribute[, value])

Set the value of an attribute for the element.

Parameters
Name Type Description
element Element A DOM node  
attribute string The name of the attribute to set  
value string A value to set for the attribute. If null, the specified attribute will be removed Optional
Returns
  • Void

css(element, ruleName[, value])

Set a CSS property for the element.

Parameters
Name Type Description
element Element A DOM node  
ruleName string A CSS property  
value string A value to set for the property Optional
Returns
  • Void

src/content.js

parseHTML(htmlString)

Parses a string into an array of DOM nodes.

Parameters
Name Type Description
htmlString string HTML string to be parsed  
Returns
  • Array.<Element> DOM nodes

before(element, htmlString)

Insert content, specified by the second parameter, before the element.

Parameters
Name Type Description
element Element A DOM node  
htmlString string HTML string to insert  
Returns
  • Void

after(element, htmlString)

Insert content, specified by the second parameter, after the element.

Parameters
Name Type Description
element Element A DOM node  
htmlString string HTML string to insert  
Returns
  • Void

prepend(parent, element)

Insert an element, specified by the second parameter, to the beginning of the parent element.

Parameters
Name Type Description
parent Element Parent DOM element  
element Element DOM element to insert  
Returns
  • Void

append(parent, element)

Insert an element, specified by the second parameter, to the end of the parent element.

Parameters
Name Type Description
parent Element Parent DOM element  
element Element DOM element to insert  
Returns
  • Void

clone(element)

Create a deep copy of the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Element Cloned DOM Element

remove(element)

Remove the element from the DOM

Parameters
Name Type Description
element Element The element to remove  
Returns
  • Void

text(element, textString)

Set the content of the element to the specified text.

Parameters
Name Type Description
element Element A DOM node  
textString string The text to set as the content of the element. When Number or Boolean is supplied, it will be converted to a String representation.  
Returns
  • Void

html(element, htmlString)

Set the HTML contents of the element.

Parameters
Name Type Description
element Element A DOM node  
htmlString string A string of HTML to set as the content  
Returns
  • Void

replaceWith(element, htmlString)

Replace element with the provided new content.

Parameters
Name Type Description
element Element A DOM node  
htmlString string The HTML string content to insert  
Returns
  • Void

src/effects.js

fade(element[, duration=400], isFadeIn) private method

Fade in or out the element.

Parameters
Name Type Description
element Element A DOM node  
duration=400 number A number determining how long the animation will run Optional
isFadeIn boolean Determine fadeIn or fadeOut  
Returns
  • Void

fadeIn(element[, duration=400])

Display the elements by fading them to opaque.

Parameters
Name Type Description
element Element A DOM node  
duration=400 number A number determining how long the animation will run Optional
Returns
  • Void

fadeOut(element[, duration=400])

Hide the element by fading them to transparent.

Parameters
Name Type Description
element Element A DOM node  
duration=400 number A number determining how long the animation will run Optional
Returns
  • Void

hide(element)

Hide the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Void

show(element)

Show the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Void

src/events.js

off(element, eventName, eventHandler)

Remove an event handler.

Parameters
Name Type Description
element Element A DOM node  
eventName string An event type  
eventHandler Function A handler function previously attached for the event  
Returns
  • Void

on(element, eventName, eventHandler)

Attach an event handler function for the element.

Parameters
Name Type Description
element Element A DOM node  
eventName string An event type  
eventHandler Function A function to execute when the event is triggered  
Returns
  • Void

trigger(element, eventName[, data={}])

Execute all handlers and behaviors attached to the element for the given event type.

Parameters
Name Type Description
element Element A DOM node  
eventName string An event type  
data={} Object Additional parameters to pass along to the event handler. Optional
Returns
  • Void

documentReady(callback)

Specify a function to execute when the DOM is fully loaded.

Parameters
Name Type Description
callback Function A function to execute after the DOM is ready.  
Returns
  • Void

src/positions.js

viewportPosition(element)

Get the size of the element and its position relative to the viewport.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Object Object with properties: left, top, right, bottom, x, y, width, height

offset(element)

Get the current coordinates of the element, relative to the document.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Object Contain the properties top and left

position(element)

Get the current coordinates of the element, relative to the offset parent.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Object Contain the properties top and left

outerHeight(element, withMargin)

Get the current computed outer height (including padding, border, and optionally margin) for the element.

Parameters
Name Type Description
element Element A DOM node  
withMargin boolean A Boolean indicating whether to include the element's margin in the calculation.  
Returns
  • number Height of the element, including top and bottom padding, border, and optionally margin, in pixels

outerWidth(element, withMargin)

Get the current computed outer width (including padding, border, and optionally margin) for the element.

Parameters
Name Type Description
element Element A DOM node  
withMargin boolean A Boolean indicating whether to include the element's margin in the calculation.  
Returns
  • number Width of the element, including left and right padding, border, and optionally margin, in pixels

src/selectors.js

find(selector[, context=document])

Returns a collection of matched elements either found in the DOM based on passed argument

Parameters
Name Type Description
selector string Accepts a string containing a CSS selector which is then used to match a set of elements  
context=document Document Element A DOM Element or Document Optional
Returns
  • Array A collection of DOM Elements

is(element, selectorOrElement)

Check the element against a selector or element, and returns true if the element match the given argument.

Parameters
Name Type Description
element Element A DOM node  
selectorOrElement string Element A string containing a selector expression or a DOM node  
Returns
  • boolean Is element match with selectorOrElement

contains(element, child)

Check to see if a DOM element is a descendant of another DOM element.

Parameters
Name Type Description
element Element A DOM node  
child Element A potential child DOM node  
Returns
  • boolean Is element has child as a descendant

prev(element)

Get the immediately preceding sibling of the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Element The previous DOM node

next(element)

Get the immediately following sibling of the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Element The following DOM node

siblings(element)

Get the siblings of the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Array Siblings DOM nodes

parent(element)

Get the parent of the element.

Parameters
Name Type Description
element Element A DOM node  
Returns
  • Element The parent DOM node

src/utils.js

toCamelCase(kebabCaseString)

Transform kebab case string into camel case strings array

Parameters
Name Type Description
kebabCaseString string The kebab case string  
Returns
  • string The camel case transformed string

getRealClassNamesArray([classNames=''])

Filter incorrect class names.

Parameters
Name Type Description
classNames='' string One or more space-separated classes to be filtered Optional
Returns
  • Array Valid class names array

Documentation generated with doxdox.