Table of contents

Functions

Metro UI implements several useful functions that are accessible through the special object.

About

All special utilities functions stored in Metro.utils or Metro.Utils object.

Function Desc
secondsToFormattedString(seconds) Return string "hh:mm:ss"
exec(f, args, context) Exec function or code with arguments and context
isOutsider(el) Check element to outside of the view
inViewport(el) Check element in viewport
objectLength(el) Return object length.
percent(a, b, r) Return percent value for b from a. If r is true, returned value is integer else - real
objectShift(obj) Return shifted object. Remove element with first key
objectDelete(obj, key) Delete key from object and return it
objectClone(obj) Copy object to clone and return it
arrayDelete(arr, val) Delete from array by value and return it
arrayDeleteByKey(arr, key) Delete key from array and return it
arrayDeleteByMultipleKeys(arr, keys_array) Delete key from array and return new array
nvl(data, other) Check data for null value and return other if null
github(repo, callback) Get information from github and put then in callback
detectIE() Detect if browser is Internet explorer or Edge
detectChrome() Detect if browser is Chrome
md5(str) Encode string with md5 algorithm
encodeUri(str) Fix to base eencodeUri function
pageHeight() Return real page height
cleanPreCode(selector) Remove white spaces from code
coords(el) Return element coordinates as object {top, left}
positionXY(event, type) Return position for type: screen, page, client
clientXY(event) Return position
pageXY(event) Return position
screenXY(event) Return position
isRightMouse(event) Check if user click on right mouse button
hiddenElementSize(el, includeMargin) Return element size as object {width, height}
getStyle(el, pseudo) Return element calculated styles
getStyleOne(el, property) Return element calculated styles for specified property
getTransformMatrix(el) Return element transform matrix
computedRgbToHex(rgb) Return hex value for computed element color.
computedRgbToHex(rgb) Return hex value for rgb string 'rgb(x, x, x)' => #xxxxxx
computedRgbToRgba(rgb, alpha) Return rgba string for rgb string 'rgb(x, x, x)' => 'rgba(x, x, x, a)'
computedRgbToArray(rgb) Return array for string 'rgb(x, x, x)' => [x, x, x]
hexColorToArray(c) Convert hex color value to array
hexColorToRgbA(c, a) Convert hex color value rgba string: '#xxxxxx' => 'rgba(x, x, x, a)'
getInlineStyles(el) Return element inline styles as array
updateURIParameter(uri, key, val) Update parameter in Uri
getURIParameter(uri, key) get parameter from Uri
getLocales() Get registered metro locales
addLocale(data) Register metro locale in runtime
aspectRatioH(width, ratio) Return height for specific ratio
aspectRatioW(height, ratio) Return width for specific ratio
valueInObject(obj, value) Check if value exist in object
keyInObject(obj, key) Check if key exist in object
newCssSheet(media) Create css sheet object
addCssRule(sheet, selector, rules, index) Add rule to css sheet object
media(query) Check media query
mediaModes() Get current media points
mediaExist(m) Return true if point exist in current medias
inMedia(m) Check if point is current media
isValue(val) Return true if val not in [undefined, null, ""]
isNegative(val) Return true if val less then 0
isPositive(val) Return true if val more then 0
isZero(val) Return true if val is 0 (int or float)
between(val, bottom, top, equals) Return true if val between bottom and top
parseMoney(val) Return numeric value from any money format. Ex: $5,640.63 -> 5640.63
func(string) Return function object
nearest(val, precision, down) search for the nearest integer, a multiple of required. Ex: Metro.utils.nearest(37, 5, false) -> 40, Metro.utils.nearest(37, 5, true) -> 35
copy(el) Copy element to clipboard
isLocalhost() Check if current location is localhost
getCursorPosition(element, event) Return mouse or pointer position as x, y
getCursorPositionX(element, event) Return mouse or pointer position x
getCursorPositionY(element, event) Return mouse or pointer position y