Two-way data-binding is sooo 2009.
Tripod includes several utility functions it uses internally that you can also take advantage of through the Tripod.util
object.
Tripod.util.isArray()
Tripod.util.isArray(someVar)
Returns boolean true
if the argument passed to it is an array.
Tripod.util.isNotBlank()
Tripod.util.isNotBlank(someVar)
Returns boolean true
if the argument passed to it is truthy or boolean false
.
Tripod.util.arrayMap()
Tripod.util.arrayMap(array, callbackFunction)
Iterates over the array passed and executes the passed function against every element of the array.
The array element is passed as the only argument to the function, and the function's return value is stored back in the array at the same index.
The resulting array is returned.
var myArray = ['a', 'b', 'c', 'd'];
var upCaseIt = function(s) {
return s.toUpperCase();
};
Tripod.util.arrayMap(myArray, upCaseIt); // returns ['A', 'B', 'C', 'D']
Tripod.util.trim()
Tripod.util.trim(string)
A simple, fast string trim implementation.
Tripod.util.cloneObject()
Tripod.util.cloneObject(object)
Performs a shallow copy of the passed object and returns the copy.
Tripod.util.toggleClass()
Tripod.util.toggleClass(domNode, className, addOrRemove)
Adds or removes a CSS class based on the third argument. If the third argument is truthy, the class is added. Otherwise it is removed.
Classes will not be added twice, and no error will occur if toggleClass
is asked to remove a class that isn't present.
Tripod.util.formatAsCurrency()
Tripod.util.formatAsCurrency(numberOrString[, currencySymbol])
Given a number or string containing a number, returns a currency formatted string.
currencySymbol
is optional and defaults to $
Tripod.util.formatAsCurrency(123456.7); // $123,456.70
Tripod.util.formatAsCurrency('123456'); // $123,456.00
Tripod.util.formatAsCurrency('hello123'); // $123.00
Tripod.util.formatAsCurrency(123.45, 'EUR'); // EUR123.45
Tripod.util.getNodeValue()
Tripod.util.getNodeValue(domNode)
The method Tripod uses to retrieve the "value" of a DOM node.
See Node Properties Used for Data Binding.
Tripod.util.setNodeValue()
Tripod.util.setNodeValue(domNode, value)
The method Tripod uses to set the "value" of a DOM node.
See Node Properties Used for Data Binding.
Tripod.util.getNodesByAttributeValue()
Tripod.util.getNodesByAttributeValue(attributeName, attributeValue[, parentNode])
The method Tripod uses to get DOM nodes based on their binding attributes. You can pass at HTML attribute name and value to grab matching DOM nodes.
In modern browsers,Tripod.util.getNodesByAttributeValue
returns aNodeList
. In older versions of IE, this method returns an array. It's safest (and fastest) to iterate over the returned object using a standardfor
loop.
Tripod.util.processTemplate()
Tripod.util.processTemplate(templateString, data)
A handlebars-ish templating engine. Tripod uses this for the template
binding modifier.
var templateString = "Hello, {name}!";
var data = { name: 'world' };
Tripod.util.processTemplate(templateString, data); // returns "Hello, world!"
Tripod.util.debounce
Tripod.util.debounce(uniqueId, callbackFunction, timeoutDelay)
debounce
is used to limit the rate at which a function can be called.
debounce
is used internally by Tripod when triggering the set
event. It's primary purpose is to
prevent Tripod from triggering an excessive number of events and bogging down the browser as a user types into the input field.
Essentially, debounce
introduces a small delay before executing the callback
function. If debounce is called
again before the delay timer runs out, the timer is reset and the waiting period begins again.
The timeoutDelay
argument is optional and defaults to 250
. timeoutDelay
is in milliseconds.