Skip to content

Instantly share code, notes, and snippets.

@cange
Created December 13, 2009 12:50
Show Gist options
  • Save cange/255403 to your computer and use it in GitHub Desktop.
Save cange/255403 to your computer and use it in GitHub Desktop.
Mootools extension
/** Define primitives type for better compression */
var FALSE = false,
TRUE = true,
NULL = null,
window = self,
undefined;
/**
* Extension of Array Mootools class
*/
/**
* Prototypejs method
*
* Enumerable#pluck(property) -> Array
* - property (String): The name of the property to fetch.
*
* Pre-baked implementation for a common use-case of [[Enumerable#collect]]
* and [[Enumerable#each]]: fetching the same property for all of the
* elements. Returns an array of the property values.
*
* <h5>Example</h5>
*
* ['hello', 'world', 'this', 'is', 'nice'].pluck('length');
* // -> [5, 5, 4, 2, 4]
**/
Array.implement({
pluck: function (property){
var results = [];
this.each(function(value) {
results.push(value[property]);
});
return results;
}
});
/**
* Extension of Element Mootools class
*/
Element.implement({
show: function() {
this.setStyle('display','');
},
hide: function() {
this.setStyle('display','none');
},
isVisible: function() {
return this.getStyle('display') != 'none';
},
isEmpty: function() {
return this.innerHTML.blank();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment