calculatePointerSpeed (event, previousEvent)
Calculates the velocity of the device pointer on the specified event.
<div class="area border-sm border-default width-xl height-lg" id="examplePointerSpeed"> </div>
webui.ready( () => { var previousEvent = null; var exampleArea = ui("#examplePointerSpeed"); exampleArea.mouseMove(function(e) { e.time = Date.now(); var result = ui.calculatePointerSpeed(e, previousEvent); previousEvent = e; exampleArea.text("velocity: " + result); }); });
convertToDate (dateTimeString, format)
Converts a datetime string value to a valid Date object using the specified format.
webui.ready( () => { var dt = ui.convertToDate("17/09/2018 12:00", "DD/MM/YYYY"); });
copyTextToClipboard (textToCopy)
Copies the specified string to the platform clipboard.
ui(".code-copy").click( function() { let el = ui(this).closest(".container").find("pre"); if (el && el.length) { ui.copyTextToClipboard(el.text()); } });
copyToClipboard (valueOrSelector) DEPRECATED
Copies the text content of a selector or string value to the platform clipboard.
<div class="area text-sm" id="exampleArea"> <button type="button" id="#clipboardExample" class="button button-success place-top-right">Copy</button> </div>
webui.ready( () => { ui.copyToClipboard(ui("#exampleArea")); });
elementHoverAt (x, y)
Gets the element being hovered over at the specified coordinates.
<div class="area text-sm" id="exampleArea"> <div class="flex-row gap-horizontal-sm"> <div class="width-lg height-lg control" id="exampleDiv"></div> </div> </div>
webui.ready( () => { ui("#exampleDiv").hoverIn(function(e) { var element = ui.elementHoverAt(e.clientX, e.clientY); console.log(element); }); });
extend (object, objects...)
Used to add to the property list or transpose properties of the object passed as the first argument with those of objects passed as additional aguments.
webui.ready( () => { let obj = new Object(); obj.firstName = "John"; obj.lastName = "Doe"; let newDataObj = function (firstName, lastName, addresses) { this.firstName = firstName; this.lastName = lastName; this.addresses = addresses; } let newData = new newDataObj("Adam", "Smith", [ { address: "Example address 1" }, { address: "Example address 2" } ]); let newObj = extend(obj, newData); console.log(newObj); });
getAccessibilityContrastColor (hexColor)
Converts a hexidecimal color string to a high contrast black or white alternative.
webui.ready( () => { var accessibilityColor = ui.getAccessibilityContrastColor("#854485"); });
getAvgHeight (elements)
Gets the average height in pixels of a set of HTML elements.
<div class="area text-sm" id="exampleArea"> <div class="flex-row gap-horizontal-sm"> <div class="width-lg height-sm control"></div> <div class="width-lg height-sm-md control"></div> <div class="width-lg height-md control"></div> </div> </div>
webui.ready( () => { var avgHeight = ui.getAvgHeight(ui(".area .flex-row div")); });
getAvgWidth (elements)
Gets the average width in pixels of a set of HTML elements.
<div class="area text-sm" id="exampleArea"> <div class="flex-row gap-horizontal-sm"> <div class="width-sm height-md control"></div> <div class="width-sm-md height-md control"></div> <div class="width-md height-md control"></div> </div> </div>
webui.ready( () => { var avgWidth = ui.getAvgWidth(ui(".area .flex-row div")); });
getColorShade (hexColor, rgbValue)
Gets a the shade for the specified hexidecimal color adjusted to the intensity specified by the RGB value.
<div class="area text-sm" id="exampleArea"> <div class="flex-row gap-horizontal-sm"> <div class="width-sm height-sm control" id="exampleDiv1"></div> <div class="width-sm height-sm control" id="exampleDiv2"></div> <div class="width-sm height-sm control" id="exampleDiv3"></div> <div class="width-sm height-sm control" id="exampleDiv4"></div> <div class="width-sm height-sm control" id="exampleDiv5"></div> <div class="width-sm height-sm control" id="exampleDiv6"></div> </div> </div>
webui.ready( () => { ui("#exampleDiv1").css("background", ui.getColorShade("#000000", 50)); ui("#exampleDiv2").css("background", ui.getColorShade("#000000", 75)); ui("#exampleDiv3").css("background", ui.getColorShade("#000000", 100)); ui("#exampleDiv4").css("background", ui.getColorShade("#000000", 125)); ui("#exampleDiv5").css("background", ui.getColorShade("#000000", 150)); ui("#exampleDiv6").css("background", ui.getColorShade("#000000", 175)); });
getElementViewportStatus (selector, requiredMargin)
Calculates whether any part of an element is positioned outside any of the 4 sides of the browser viewport, depending on the specified margin.
webui.ready( () => { var status = ui.getElementViewportStatus("#exampleElement", 50); });
getScrollbarWidth ()
Gets the browser scrollbar width in pixels.
webui.ready( () => { var scrollbarWidth = ui.getScrollbarWidth(); });
getTimeOffsetFromNow (dateTimeString, format)
Gets the time offset of the specified datetime string from now using the specified format.
webui.ready( () => { var dt = ui.getTimeOffsetFromNow("17/09/2018 12:00", "DD/MM/YYYY"); });
getUnitFromCssSize (cssSize)
Gets the unit part of size string returned from an element.css(ruleName, ruleValue) call.
webui.ready( () => { let unit = ui.getUnitFromCssSize("35rem"); // Returns: "rem"; });
getValueFromCssSize (cssSize)
Gets the value part of size string returned from an element.css(ruleName, ruleValue) call.
webui.ready( () => { let value = ui.getValueFromCssSize("35rem"); // Returns: 35; });
isWindowInBreakPointRange (breakPointRange)
Calculates whether the browser viewport is currently within the specified breakpoint range.
webui.ready( () => { var isInRange = ui.isWindowInBreakPointRange([1, 3]); });
pxToRem (pxValue)
Converts pixels to rems using the currently set browser font size.
webui.ready( () => { var rems = ui.pxToRem(300); });
remToPx (remValue)
Converts rems to pixels using the currently set browser font size.
webui.ready( () => { var rems = ui.remToPx(4); });
rgbStringToHex (rgb)
Converts a comma separated RGB string to a hexidecimal string equivalent.
webui.ready( () => { var hexColorString = ui.rgbStringToHex ("85, 145, 108"); });
rgbToHex (r, g, b)
Converts RGB values to a hexidecimal string equivalent.
webui.ready( () => { var hexColorString = ui.rgbToHex (85, 145, 108); });