I modified some functions and extend some prototype classes. May be
they should be included to the core or just somebody may found them
usefull.
Object.extend(Enumerable,{
// more than one array can be passed
intersect: function(array) {
array = $A(arguments).flatten();
return this.toArray().uniq().findAll(function(item) {
return array.detect(function(value) {
return item === value
});
});
},
/**
* Computes the difference of arrays
* @param {Array} array
* @return {Array} returns an array containing all the values those
are not in array
*/
diff: function(array) {
array = $A(arguments).flatten();
return this.toArray().uniq().findAll(function(item) {
return !array.detect(function(value) {
return item === value
});
});
}
});
Object.extend(Element.ClassNames.prototype, {
/**
* Replace class with other class
*
* @return {Element.ClassNames}
*/
replace: function(findClass, replaceWithClass) {
this.remove(findClass).add(replaceWithClass);
return this;
},
/**
* In every function call the class
* is replaced by next class in the array parameter
*
* @param {Array} $classNames
* @return {Element.ClassNames}
*/
cycle: function(classNames) {
if (!Object.isArray(classNames) || classNames.uniq().length ==
0) {
return this;
}
classNames = classNames.uniq();
if (classNames.length == 1) {
this.element.toggleClassName(className.first());
return this;
}
includedClassName = this.intersect(classNames)[0]||false;
if (!includedClassName) {
this.add(classNames.first());
}else {
index = classNames.indexOf(includedClassName);
this.replace(includedClassName,
classNames[index+1]?classNames[index
+1]:classNames[0]);
}
return this;
},
/**
* Remove classname(s) from elements class list
* @param {Function} $super
* @param {Array} classNamesToRemove
*/
remove: function(classNamesToRemove) {
args = $A(arguments).flatten();
this.set(this.diff(args).join(' '));
return this;
}
});
And I also think that some functions those do not have return value
should return this object as you see in the examples
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---