Skip to content

Instantly share code, notes, and snippets.

Avatar

Abbey Hawk Sparrow khrome

View GitHub Profile
@khrome
khrome / MooToolsEntityEncoding.js
Created Dec 19, 2011
MooTools Entity Encoding
View MooToolsEntityEncoding.js
if(!String.regexEncode){
String.regexChars = ['\\', '&','^', '$', '*', '+', '?', '.', '(', ')', '|', '{', '}', '[', ']'];
String.regexEncodeRegexObject = new RegExp('([\\'+String.regexChars.join('|\\')+'])', 'g');
String.implement({
regexEncode : function(){
return this.replace(String.regexEncodeRegexObject, '\\$1');
}
});
}
@khrome
khrome / Function.whenTrue.js
Created Dec 19, 2011
Function.whenTrue polling a boolean function with geometric falloff
View Function.whenTrue.js
if(!Function.actionTimeout) Function.actionTimeout = 16384;
if(!Function.whenTrue){
Function.implement({
whenTrue : function(actionFunction, args, delayFunction, timeoutFunction, timeout, counter){
if(!timeout) timeout = Function.actionTimeout;
if(!counter) counter = 0;
if(!timeoutFunction) timeoutFunction = function(event){
throw('Condition not met after '+event.time+'ms');
};
var result = this();
@khrome
khrome / element_style_aggregation.js
Created Dec 13, 2011
Grouping and aggregating elements in MooTools
View element_style_aggregation.js
if(!Element.siblingsBefore){
Element.implement({
siblingsBefore : function(){
var results = [];
var found = false;
this.getParent().getChildren().each(function(child){
if(this == child) found = true;
if(!found) results.push(child);
});
return new Elements(results);