Javascript helper functions for overriding default field styles
////////////////////// Configurable variables /////////////////////////////
var imgRoot = '../customer/svg/';
var searchBtn = imgRoot + 'search.svg';
var dateBtn = imgRoot + 'calendar.svg';
////////////////////// Helpful functions //////////////////////////////////
// function to replace a class name for specified elements
replaceClass = function(els, oldClass, newClass)
{
while (els.length > 0)
{
els[0].className = els[0].className.replace(new RegExp('(?:^|\\s)'+
oldClass + '(?:\\s|$)'), newClass);
}
};
// sets a specific attribute for all elements in a collection
setAttributeOnAll = function(els, attrName, attrVal)
{
for (var i=0; i < els.length; i++)
els[i].setAttribute(attrName,attrVal);
};
// appends a value to an attribute for all elements in a collection
// can be used to append class name
appendAttributeOnAll = function(els, attrName, attrVal)
{
for (var i=0; i < els.length; i++)
{
var curr = els[i].getAttribute(attrName);
els[i].setAttribute(attrName, curr + ' ' + attrVal);
}
};
// get element associated with an item property's "button"
getItemFieldButton = function(field)
{
var itms = document.getElementsByClassName(field);
return itms[0].getElementsByClassName("sys_f_input_image");
};
// replace icon on an item property's "button"
updateItemFieldIcon = function(field,icon)
{
var btn = getItemFieldButton(field);
setAttributeOnAll(btn,'src',icon);
return btn;
};