bnmr Library
$$(selector)
Description
Dynamic DOM element selector
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
Returns
Returns DOM node or NodeList if multiple exist.
Examples
$$('#container'); // => (element with container ID) $$('.link'); // => (all elements with link class) $$('.link:not(.grey), .text'); // => (all elements with link class but not grey class and all elements with text class)
$$(selector).on(event, callback)
Description
DOM event attacher with legacy and mobile support.
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
event
String
Name of event to listen for.
callback
Function
Function to execute on event occurrence.
Returns
Does not return any values.
Examples
$$('.btn').on('tap', (e) => { $$.log(e.target); }); $$('.slideshow').on('swipeleft', updateSlideshow.bind(null, 'forward'));
$$(selector).addClass(className[, delay])
Description
Adds class to DOM element(s).
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
className
String
Name of class to add to element(s).
delay
Number
Time of delay from function call to application of class in milliseconds.
Returns
Does not return any values.
Examples
$$('.btn').addClass('purple') // adds 'purple' class to any elements with 'btn' class; $$('#container').addClass('opac-1', 1000); // adds class 'opac-1' to element with 'container' ID after 1 second
$$(selector).removeClass(className[, delay])
Description
Removes class from DOM element(s).
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
className
String
Name of class to remove from element(s).
delay
Number
Time of delay from function call to removal of class in milliseconds.
Returns
Does not return any values.
Examples
$$('.btn').removeClass('purple') // removes 'purple' class from any elements with 'btn' class; $$('#container').removeClass('opac-0', 1000); // removes class 'opac-0' from element with 'container' ID after 1 second
$$(selector).replaceClass(fromClassName, toClassName[, delay])
Description
Replaces class on DOM element(s).
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
fromClassName
String
Name of class to remove from element(s).
toClassName
String
Name of class to add to element(s).
delay
Number
Time of delay from function call to replacement of class in milliseconds.
Returns
Does not return any values.
Examples
$$('.btn').replaceClass('purple', 'red') // replaces 'purple' class with 'red' class on any elements with 'btn' class; $$('#container').replaceClass('opac-0', 'fadeIn', 1000); // replaces class 'opac-0' with 'fadeIn' class on element with 'container' ID after 1 second
$$(selector).css(property, value[, delay])
Description
Applies an inline CSS rule to DOM element(s).
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
property
String
Any valid CSS property.
value
String
Any valid CSS property.
delay
Number
Time of delay from function call to application of CSS rule in milliseconds.
Returns
Does not return any values.
Examples
$$('.btn').css('background-color', 'purple'); // applies inline CSS rule of purple background color to any elements with the class names 'btn' $$('#container').css('opacity', '1', 500) // applies inline CSS rule of 1 for opacity after a half second to element with ID of 'container'
$$(selector).animate(properties, duration, delay, ease)
Description
Applies a CSS transitional animation to a DOM element(s).
Parameters
selector
String
Any valid CSS selector. Default: 'body'.
properties
Object
As an object, CSS property keys with valid property values to be applied.
duration
Number
Duration of animation in milliseconds. Default is 500.
delay
Number
Delay before animation in milliseconds. Default is 0.
ease
String
Any valid CSS value for timing function. Default is 'ease'.
Returns
Does not return any values.
Examples
$$('.btn').animate({ opacity: '1', '-webkit-transform': 'translateY(-10px)', transform: 'translateY(-10px)' }, 1000, 250, 'cubic-bezier(.68,-0.55,.27,1.55)'); // animates all elements with the class of 'btn' to have an opacity of 1 and up 10px over one second after delaying for a quarter second with a bounce effect
$$.ajax(options[, callback])
Description
Basic AJAX request utility
Parameters
options
Object
Configuration settings for the request.
options.type
String
Expected return type from request. Options are 'xml', 'json' or 'text'. Default is 'text'.
options.method
String
HTTP method for requesting data. Options are 'GET' or 'POST'. Default is 'GET'.
options.url
String
File path or absolute path to the request source. Default is './'.
options.async
Boolean
Whether the request should be asynchronous. Default is true.
options.params
FormData Object or String
Parameters to be passed to the request. String can be used for GET requests and an object for POST requests. Default is null.
options.progress
Function
Function to execute on progress event of request. Default is null.
callback
Function
Function to execute on successful return of request.
Returns
Does not return any values.
Examples
function onAjaxProgress = function (e) { if (e.lengthComputable) $$.log(e.loaded / e.total); }; var params = new FormData(); params.append('action', 'verify_user'); params.append('username', username); params.append('password', password); $$.ajax({ type: 'json', method: 'POST', url: './com/user_functions.php', isAsync: true, params: params, progress: onAjaxProgress }, function (response) { $$.log(response); });
$$.exists(value)
Description
Tests for the existence of a value.
Parameters
value
Mixed
Tests for a truthy value.
Returns
Returns true if truthy and false if not.
Examples
$$.exists(true) // => true $$.exists(null) // => false $$.exists("null") // => false $$.exists("") // => false
$$.getParam(key)
Description
Gets query string parameter value from window location.
Parameters
key
String
The key of the key/value pair to be returned.
Returns
Returns the value of the key passed or false if none is present.
Examples
window.location = 'https://www.path.to/url?param1=foo&param2=bar&param3=baz'; $$.getParam('param2') // => bar
$$.log(message[, style])
Description
Creates a console message with label and optional styling.
Parameters
message
Mixed
String or Object to be printed in the console.
style
Mixed
Either string of console type (built-in functions) or CSS styling, or object of CSS styling.
Returns
Does not return any values.
Examples
$$.log('hello, world.'); // -> library.js:1:1 -> hello, world. $$.log({foo: bar, baz: false}); // -> library.js:3:1 -> Object (link break, then directory of object) $$.log('Danger, Will Robinson!', 'error'); // -> library.js:5:1 -> Danger, Will Robinson! (as a console.error message) $$.log('hello, world', 'font-size: 16px; color: #f06;'); // -> library.js:7:1 -> hello, world. (styled) $$.log('hello, world', {'font-size': '16px', 'color': '#f06'}); // -> library.js:9:1 -> hello, world. (styled) $$.log({foo: bar, baz: false}, 'font-size: 16px; color: blueviolet;'); // -> library.js:11:1 -> Object (styled, then line break, then directory of object)
$$.preload(assets[, callback])
Description
Preloads one more image or video assets.
Parameters
assets
Mixed
String of file path or array of file paths.
callback
Function
Function to execute after all assets have loaded.
Returns
Does not return any values.
Examples
$$.preload('./path/to/file.jpg'); $$.preload('https://www.path.to/file.jpg', function () { $$.log('loaded'); }); $$.preload(['./path/to/file1.jpg', './path/to/file2.jpg'], initOnImgsLoad); // executes initOnImgsLoad function once both images have loaded
$$.rand([min, max, isFloat])
Description
Returns a random value between two given values. Alternatively, returns a randomization of a given array.
Parameters
min
Number [or Array]
Lowest number the returned value should be. Alternatively, an array to be randomized.
max
Number
Greatest number the returned value should be.
float
Boolean
Whether the returned value should have decimal places or not.
Returns
Returns a value between the two values given. Alternatively, returns a randomized version of given array.
Examples
$$.rand(1, 10) // => (a whole number between 1 and 10) $$.rand(0, 5, true) // => (a number between 0 and 5 to the 15th decimal place) $$.rand([0, 1, 2, 3, 4, 5]) // => (randomized version of array)