function addClass(el, classNames)
{
if (!classNames) { return; }
if (!Object.prototype.toString.call(classNames) === "[object Array]")
{
classNames = classNames.split(' ');
}
var className = el.getAttribute("class") || "";
var i, classMap = {}, currentClasses = [], length;
if (className !== null)
{
currentClasses = className.split(" ");
length = currentClasses.length;
for (i = 0; i < length; i++)
{
if (currentClasses[i] !== "")
{
classMap[currentClasses[i]] = "";
}
}
}
var changed = false, trimmedName;
var newAdded = [];
length = classNames.length;
for (i = 0; i < length; i++)
{
trimmedName = classNames[i].trim();
if ((trimmedName.length > 0) && !(trimmedName in classMap))
{
currentClasses.push(trimmedName);
newAdded.push(trimmedName);
classMap[trimmedName] = "";
changed = true;
}
}
if (changed)
{
el.setAttribute("class", currentClasses.join(" ").trim());
}
return newAdded;
}