Skip to content

Instantly share code, notes, and snippets.

View assertchris's full-sized avatar
💭
I may be slow to respond.

Christopher Pitt assertchris

💭
I may be slow to respond.
View GitHub Profile
@assertchris
assertchris / gist:420871
Created June 1, 2010 12:19
MooTools when method
Function.implement({
'when': function(check, interval, bind)
{
var bind = bind || this,
timer = setInterval(function() {
if (check.apply(bind))
{
clearInterval(timer);
this.apply(bind);
}
@assertchris
assertchris / gist:420885
Created June 1, 2010 12:26
JavaScript Function.prototype.when method
Function.prototype.when = function(check, interval, bind)
{
var bind = bind || this,
timer = setInterval(function() {
if (check.apply(bind))
{
clearInterval(timer);
this.apply(bind);
}
}, (interval || 100));
@assertchris
assertchris / gist:420913
Created June 1, 2010 12:53
PHP object->array method
function toArray($result)
{
$array = array();
foreach ($result as $key => $value)
{
if (is_object($value))
{
$array[$key] = toArray($value);
}
else if (is_array($value))
@assertchris
assertchris / gist:422120
Created June 2, 2010 08:43
jQuery when method
jQuery.when = function(fn, check, interval, bind)
{
var bind = bind || this,
timer = setInterval(function() {
if (check.apply(bind))
{
clearInterval(timer);
fn.apply(bind);
}
}, (interval || 100));
@assertchris
assertchris / gist:422472
Created June 2, 2010 15:02
Optimized JavaScript string trim
function trim(str)
{
// immediate return!
if(!str)return '';
// markers
var modified = false, start = -1, end = str.length;
// traverse from beginning and from end for markers...
while(str.charCodeAt(--end) < 33 || str.charCodeAt(end) == 65279) modified = true;
@assertchris
assertchris / html5-data-namespaces.js
Created January 3, 2011 13:10
JavaScript/HTML5 data-* namespaces
/*
<div id="foo" data-timepicker-pad="true" data-timepicker-labels-hours="HR" data-modal-color="#333"></div>
http://www.jsfiddle.net/sixtyseconds/bxcLj/3/
*/
function _walk(parts, value, stack) {
var part = parts.shift();
@assertchris
assertchris / gist:785949
Created January 19, 2011 10:10
Delegation-powered expand/collapse
window.addEvent('domready', function() {
// expand/collapse (with delegation)
var accordion = document.getElement('.zoopy-content-left-accordion'),
groups = accordion.getElements('.zoopy-content-left-accordion-group');
function toggle() {
var content = this.getElement('.zoopy-content-left-accordion-group-content');
@assertchris
assertchris / gist:838470
Created February 22, 2011 10:20
Modified Options mutator methods (MooTools Class.Extras)
Orignal:
setOptions: function(){
var options = this.options = Object.merge.apply(null, [{}, this.options].append(arguments));
if (!this.addEvent) return this;
for (var option in options){
if (typeOf(options[option]) != 'function' || !(/^on[A-Z]/).test(option)) continue;
this.addEvent(option, options[option]);
delete options[option];
}
@assertchris
assertchris / Request.RSS.js
Created March 4, 2011 14:10
MooTools Request.RSS class
/*
---
license: MIT-style
authors: [Christopher Pitt]
...
*/
(function(){
var template =
'<div class="item">'+
@assertchris
assertchris / Classes.js
Created March 23, 2011 11:09
JavaScript Object.combine method
Object.combine = function (keys, values) {
if (!keys.length || !values.length || keys.length != values.length) {
return null;
}
var index = null,
length = keys.length,
results = {};
for (index = 0; index < length; index++) {