Skip to content

Instantly share code, notes, and snippets.

View khrome's full-sized avatar

Abbey Hawk Sparrow khrome

View GitHub Profile
@khrome
khrome / MooToolsEntityEncoding.js
Created December 19, 2011 07:38
MooTools Entity Encoding
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 December 19, 2011 07:21
Function.whenTrue polling a boolean function with geometric falloff
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 December 13, 2011 07:17
Grouping and aggregating elements in MooTools
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);