@cnbritain/merlin-www-js-utils

<dl> <dt><a href="#module_detect">detect</a></dt> <dd></dd> <dt><a href="#module_functions">functions</a></dt> <dd></dd> </dl>

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@cnbritain/merlin-www-js-utils
3.0.13 years ago7 years agoMinified + gzip package size for @cnbritain/merlin-www-js-utils in KB

Readme

Modules

detect
functions

detect

* [.getUserAgent](#module_detect.getUserAgent) ⇒ <code>Object</code>
* [.hasHistory](#module_detect.hasHistory) : <code>Boolean</code>
* [.hasTouch](#module_detect.hasTouch) : <code>Boolean</code>
* [.isAndroid](#module_detect.isAndroid) : <code>Boolean</code>
* [.isIOS](#module_detect.isIOS) : <code>Boolean</code>
* [.isLinux](#module_detect.isLinux) : <code>Boolean</code>
* [.isMac](#module_detect.isMac) : <code>Boolean</code>
* [.isWindows](#module_detect.isWindows) : <code>Boolean</code>
* [.supportBoxModel](#module_detect.supportBoxModel) ⇒ <code>Boolean</code>
* [.supportsHTML5Video](#module_detect.supportsHTML5Video) ⇒ <code>Boolean</code>

detect.getUserAgent ⇒ Object

Creates an object with user agent information
Kind: static property of detect
Url: http://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser

detect.hasHistory : Boolean

window.history support
Kind: static property of detect

detect.hasTouch : Boolean

Touch support
Kind: static property of detect

detect.isAndroid : Boolean

Android useragent sniff
Kind: static property of detect

detect.isIOS : Boolean

iOS useragent sniff
Kind: static property of detect

detect.isLinux : Boolean

Linux useragent sniff
Kind: static property of detect

detect.isMac : Boolean

Macintoch useragent sniff
Kind: static property of detect

detect.isWindows : Boolean

Windows useragent sniff
Kind: static property of detect

detect.supportBoxModel ⇒ Boolean

Box model support
Kind: static property of detect

detect.supportsHTML5Video ⇒ Boolean

HTML5 video support
Kind: static property of detect

functions

* [.addClass(el, cls)](#module_functions.addClass)
* [.addEvent(el, type, fn)](#module_functions.addEvent)
* [.addEventOnce(el, type, fn)](#module_functions.addEventOnce)
* [.addHtml(node)](#module_functions.addHtml)
* [.ajax(options)](#module_functions.ajax) ⇒ <code>Promise</code>
* [.assign(target, ...source)](#module_functions.assign) ⇒ <code>Object</code>
* [.clamp(min, max, value1)](#module_functions.clamp) ⇒ <code>Number/Function</code>
* [.cloneArray(src)](#module_functions.cloneArray) ⇒ <code>Array</code>
* [.cloneArrayDeep(src)](#module_functions.cloneArrayDeep) ⇒ <code>Array</code>
* [.cloneObject(src)](#module_functions.cloneObject) ⇒ <code>Object</code>
* [.cloneObjectDeep(src)](#module_functions.cloneObjectDeep) ⇒ <code>Object</code>
* [.createEventTemplate(type, target, eventData)](#module_functions.createEventTemplate) ⇒ <code>Object</code>
* [.debounce(fn, wait, scope, immediate)](#module_functions.debounce) ⇒ <code>function</code>
* [.delegate(selector, fn, ctx)](#module_functions.delegate) ⇒ <code>function</code>
* [.exitFullscreen(el)](#module_functions.exitFullscreen)
* [.fireEvent(el, type, bubble, cancelable)](#module_functions.fireEvent) ⇒ <code>Boolean</code>
* [.forEachShift(collection, fn)](#module_functions.forEachShift)
* [.getElementOffset(el)](#module_functions.getElementOffset) ⇒ <code>Object</code>
* [.getEventTarget(e)](#module_functions.getEventTarget) ⇒ <code>\*</code>
* [.getIframeFromWindow(window)](#module_functions.getIframeFromWindow) ⇒ <code>HTMLNode/Boolean</code>
* [.getObjectValues(obj, keys)](#module_functions.getObjectValues) ⇒ <code>Array.<\*></code>
* [.getParent(el, selector)](#module_functions.getParent) ⇒ <code>HTMLNode/Boolean</code>
* [.getPrevious(el, selector)](#module_functions.getPrevious) ⇒ <code>HTMLElement/Boolean</code>
* [.getParentUntil(el, selector)](#module_functions.getParentUntil) ⇒ <code>Object</code>
* [.getPreviousElementUntil(el, selector)](#module_functions.getPreviousElementUntil) ⇒ <code>Object</code>
* [.getScrollLeft(el)](#module_functions.getScrollLeft) ⇒ <code>Number</code>
* [.getScrollTop(el)](#module_functions.getScrollTop) ⇒ <code>Number</code>
* [.getNamespaceKey(abbr)](#module_functions.getNamespaceKey) ⇒ <code>String</code>
* [.getWindowScrollLeft()](#module_functions.getWindowScrollLeft) ⇒ <code>Number</code>
* [.getWindowScrollTop()](#module_functions.getWindowScrollTop) ⇒ <code>Number</code>
* [.hasClass(el, cls)](#module_functions.hasClass) ⇒ <code>Boolean</code>
* [.hasOwnProperty(obj, key)](#module_functions.hasOwnProperty) ⇒ <code>Boolean</code>
* [.inherit(src, props)](#module_functions.inherit) ⇒ <code>Object</code>
* [.insertBefore(child, ref)](#module_functions.insertBefore) ⇒ <code>HTMLElement</code>
* [.isArray(src)](#module_functions.isArray) ⇒ <code>Boolean</code>
* [.isArticleAdSlot(placement)](#module_functions.isArticleAdSlot) ⇒ <code>Boolean</code>
* [.isDefined(value)](#module_functions.isDefined) ⇒ <code>Boolean</code>
* [.isEmptyString(value)](#module_functions.isEmptyString) ⇒ <code>Boolean</code>
* [.isElement(value)](#module_functions.isElement) ⇒ <code>Boolean</code>
* [.isHeaderAdSlot(placement)](#module_functions.isHeaderAdSlot) ⇒ <code>Boolean</code>
* [.isObject(src)](#module_functions.isObject) ⇒ <code>Boolean</code>
* [.isSplashAdSlot(placement)](#module_functions.isSplashAdSlot) ⇒ <code>Boolean</code>
* [.isWindow(win)](#module_functions.isWindow) ⇒ <code>Boolean</code>
* [.loadScript(url, options)](#module_functions.loadScript) ⇒ <code>Promise</code>
* [.loadSocialScripts()](#module_functions.loadSocialScripts) ⇒ <code>Promise</code>
* [.not(value)](#module_functions.not) ⇒ <code>Boolean</code>
* [.onPageLoad(loadFn)](#module_functions.onPageLoad)
* [.onPageReady(readyFn)](#module_functions.onPageReady)
* [.padValue(value, width, chr)](#module_functions.padValue) ⇒ <code>String</code>
* [.randomUUID()](#module_functions.randomUUID) ⇒ <code>String</code>
* [.removeClass(el, cls)](#module_functions.removeClass)
* [.removeElement(el)](#module_functions.removeElement)
* [.removeEvent(el, type, fn)](#module_functions.removeEvent)
* [.throttle(fn, threshhold, scope)](#module_functions.throttle) ⇒ <code>function</code>
* [.toBoolean(value)](#module_functions.toBoolean) ⇒ <code>Boolean</code>
* [.toggleClass(el, cls)](#module_functions.toggleClass)
* [.unescapeJinjaValue(value)](#module_functions.unescapeJinjaValue) ⇒ <code>\*</code>

functions.addClass(el, cls)

Adds a class to an element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | cls | String |

functions.addEvent(el, type, fn)

Adds an event to an element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | type | String | | fn | function |

functions.addEventOnce(el, type, fn)

Adds an event that will fire once and then remove itself
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | type | String | | fn | function |

functions.addHtml(node)

Adds html to a node
Kind: static method of functions
| Param | Type | | --- | --- | | node | HTMLElement |

functions.ajax(options) ⇒ Promise

Basic ajax function
Kind: static method of functions
| Param | Type | | --- | --- | | options | Object |

functions.assign(target, ...source) ⇒ Object

Assigns the values of the other sources to the target
Kind: static method of functions
| Param | Type | | --- | --- | | target | Object | | ...source | Object |

functions.clamp(min, max, value1) ⇒ Number/Function

Clamps a value to the min and max. Also set up to allow currying.
Kind: static method of functions
| Param | Type | | --- | --- | | min | Number | | max | Number | | value1 | Number |

functions.cloneArray(src) ⇒ Array

Clones an array
Kind: static method of functions
| Param | Type | | --- | --- | | src | Array |

functions.cloneArrayDeep(src) ⇒ Array

Clones an array while recursively cloning the items inside
Kind: static method of functions
| Param | Type | | --- | --- | | src | Array |

functions.cloneObject(src) ⇒ Object

Clones an object
Kind: static method of functions
| Param | Type | | --- | --- | | src | Object |

functions.cloneObjectDeep(src) ⇒ Object

Clones an object whilst recursively cloning the descendants
Kind: static method of functions
| Param | Type | | --- | --- | | src | Object |

functions.createEventTemplate(type, target, eventData) ⇒ Object

Creates an object for events
Kind: static method of functions
| Param | Type | Description | | --- | --- | --- | | type | String | The type of event | | target | Object | The thing that emitted the event | | eventData | Object | Some data |

functions.debounce(fn, wait, scope, immediate) ⇒ function

Debounce function, allows one function to be ran wait milliseconds after.
Kind: static method of functions
| Param | Type | Description | | --- | --- | --- | | fn | function | | | wait | Number | Number of milliseconds | | scope | Object | | | immediate | Boolean | |

functions.delegate(selector, fn, ctx) ⇒ function

Creates a function that will delegate events to a selector
Kind: static method of functions
| Param | Type | | --- | --- | | selector | String | | fn | function | | ctx | \* |

functions.exitFullscreen(el)

Exits fullscreen mode for the element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode |

functions.fireEvent(el, type, bubble, cancelable) ⇒ Boolean

Fires an event on an element
Kind: static method of functions
Returns: Boolean - Was the event cancelled?
| Param | Type | Description | | --- | --- | --- | | el | HTMLElement | | | type | String | The type of event | | bubble | Boolean | Should the event bubble? | | cancelable | Boolean | Should the event be cancelable? |

functions.forEachShift(collection, fn)

Loop over a collection and shift the item from the collection
Kind: static method of functions
| Param | Type | | --- | --- | | collection | Array | | fn | function |

functions.getElementOffset(el) ⇒ Object

Gets the elements offset. Based off of jquerys implementation
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode |

functions.getEventTarget(e) ⇒ \*

Gets the event target
Kind: static method of functions
Returns: \* - The target of the event
| Param | Type | Description | | --- | --- | --- | | e | Object | The event information |

functions.getIframeFromWindow(window) ⇒ HTMLNode/Boolean

Gets the iframe element based on the window
Kind: static method of functions
| Param | Type | | --- | --- | | window | Window |

functions.getObjectValues(obj, keys) ⇒ Array.<\*>

Gets the values from an object. If keys are specified, it will only get the values of those keys.
Kind: static method of functions
| Param | Type | Description | | --- | --- | --- | | obj | Object | Source object | | keys | Array.<String> | |

functions.getParent(el, selector) ⇒ HTMLNode/Boolean

Gets the parent element matching the selector. If it doesn't match, returns nothing
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | selector | String |

functions.getPrevious(el, selector) ⇒ HTMLElement/Boolean

Gets the previous element matching the selector. If it doesn't match, returns false
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLElement | | selector | String |

functions.getParentUntil(el, selector) ⇒ Object

Gets the parent till the selector or the root.
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | selector | String |

functions.getPreviousElementUntil(el, selector) ⇒ Object

Gets the previous element till the selector or the root
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | selector | String |

functions.getScrollLeft(el) ⇒ Number

Gets the scroll left of the element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode/Window |

functions.getScrollTop(el) ⇒ Number

Gets the scroll top of the element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode/Window |

functions.getNamespaceKey(abbr) ⇒ String

Creates a key based on the brand abbreviation
Kind: static method of functions
| Param | Type | | --- | --- | | abbr | String |

functions.getWindowScrollLeft() ⇒ Number

Gets the scrollleft of the window
Kind: static method of functions

functions.getWindowScrollTop() ⇒ Number

Gets the scrolltop of the window
Kind: static method of functions

functions.hasClass(el, cls) ⇒ Boolean

Checks if the element has a class
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | cls | String |

functions.hasOwnProperty(obj, key) ⇒ Boolean

hasOwnProperty that prevents contamination from the object being tested
Kind: static method of functions
| Param | Type | | --- | --- | | obj | Object | | key | String |

functions.inherit(src, props) ⇒ Object

Creates a new object based from src. Then copies over any properties.
Kind: static method of functions
| Param | Type | | --- | --- | | src | Object | | props | Object | Undefined |

functions.insertBefore(child, ref) ⇒ HTMLElement

Inserts the child element before the reference
Kind: static method of functions
Returns: HTMLElement - The child
| Param | Type | | --- | --- | | child | HTMLElement | | ref | HTMLElement |

functions.isArray(src) ⇒ Boolean

Checks if the src is an array
Kind: static method of functions
| Param | Type | | --- | --- | | src | \* |

functions.isArticleAdSlot(placement) ⇒ Boolean

Checks if the placement is in an article slot
Kind: static method of functions
| Param | Type | | --- | --- | | placement | String |

functions.isDefined(value) ⇒ Boolean

Checks if a value is defined
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |

functions.isEmptyString(value) ⇒ Boolean

Checks if the value is an empty string
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |

functions.isElement(value) ⇒ Boolean

Checks if the value is an element
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |

functions.isHeaderAdSlot(placement) ⇒ Boolean

Checks if the placement is a header slot
Kind: static method of functions
| Param | Type | | --- | --- | | placement | String |

functions.isObject(src) ⇒ Boolean

Checks if the src is an object
Kind: static method of functions
| Param | Type | | --- | --- | | src | \* |

functions.isSplashAdSlot(placement) ⇒ Boolean

Checks if the placement is a splash slot
Kind: static method of functions
| Param | Type | | --- | --- | | placement | String |

functions.isWindow(win) ⇒ Boolean

Checks if win is a window element
Kind: static method of functions
| Param | Type | | --- | --- | | win | \* |

functions.loadScript(url, options) ⇒ Promise

Loads a script file into the page
Kind: static method of functions
| Param | Type | | --- | --- | | url | String | | options | Object |

functions.loadSocialScripts() ⇒ Promise

Loads any social scripts. Includes twitter, facebook, vine, instagram and imgur
Kind: static method of functions

functions.not(value) ⇒ Boolean

Inverts the value
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |

functions.onPageLoad(loadFn)

Runs loadFn once the page has loaded
Kind: static method of functions
| Param | Type | | --- | --- | | loadFn | function |

functions.onPageReady(readyFn)

Runs readyFn once the page is ready
Kind: static method of functions
| Param | Type | | --- | --- | | readyFn | function |

functions.padValue(value, width, chr) ⇒ String

Pads a number
Kind: static method of functions
| Param | Type | | --- | --- | | value | Number | | width | Number | | chr | String |

functions.randomUUID() ⇒ String

Generates a random id
Kind: static method of functions

functions.removeClass(el, cls)

Removes a class from an element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | cls | String |

functions.removeElement(el)

Removes the element from the tree
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLElement |

functions.removeEvent(el, type, fn)

Removes an event from an element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | type | String | | fn | function |

functions.throttle(fn, threshhold, scope) ⇒ function

Throttles an event being fired by the threshold
Kind: static method of functions
| Param | Type | Description | | --- | --- | --- | | fn | function | | | threshhold | Number | Milliseconds to throttle by | | scope | Object | |

functions.toBoolean(value) ⇒ Boolean

Converts a value to a boolean
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |

functions.toggleClass(el, cls)

Toggles a class on an element
Kind: static method of functions
| Param | Type | | --- | --- | | el | HTMLNode | | cls | String |

functions.unescapeJinjaValue(value) ⇒ \*

Unescapes a value from jinja
Kind: static method of functions
| Param | Type | | --- | --- | | value | \* |