Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
subtleGradient / document.write.moo.js
Created June 21, 2009 22:07
document.write replacement using MooTools
/*
---
source: http://gist.github.com/133677
provides: document.write
description: MooTools based document.write replacement
requires: MooTools
author: Thomas Aylott -- SubtleGradient.com
thanks: Daniel Steigerwald -- daniel.steigerwald.cz
@subtleGradient
subtleGradient / README.md
Created June 21, 2009 17:53
quick jekyll blog post script

The @ROOT path in this script is set to the present working directory. My personal version is set to the full path to my jekyll _posts directory.

I have it pushing the new blog post to an origin remote in the master branch. You might want to change that to a gh-pages branch instead.

{
"Function":"$",
"description":"The dollar function has a dual purpose: Getting the element by its id, and making an element in Internet Explorer \"grab\" all the Element methods.",
"Syntax":"var myElement = $(el);",
"Arguments": {
"el":["The Element to be extended.", {
"object":"If the object has a toElement method, toElement will be called to get the Element.",
"string":"A string containing the id of the DOM element desired.",
"element":"The element will be extended if it is not already."
// -*- Mode: MooTools Javascript; tab-width: 4; -*-
// Proposed syntax. Not fully functional atm.
/*
EG: a menu system
a menu is open while in the the menu-open state
when the menu-open state is removed, the menu should be closed
the menu-open state must be false 100 ms after the last mouseout even it fired
*/
String.prototype.toRegExp = function(){
var match = this.match(/^\/(.*)\/([gimsx]{0,5})$/);
console.log(match)
return (match) ? new RegExp(match[1], match[2]) : new RegExp(this);
}
document.write("/flarm/gim" === /flarm/mig.toString());document.write('\n');
document.write("/flarm/gim".toRegExp().toString() === /flarm/mig.toString());document.write('\n');
document.write("/fl\
// MooTools Method Wrappers
var MyClass = new Class({
Implements: Bind,
MethodMutators:true,
initilize: function(){
this.setBinds();
// inspired by jQuery watch: http://plugins.jquery.com/files/jquery-watch.js.txt
(function(){
var watch = Object.prototype.watch,
unwatch = Object.prototype.unwatch,
watched = [],
timer;
Object.watch = function(obj, prop, fn){
Function.prototype.remember = function remember(delay,maxConcurrentRuns){
maxConcurrentRuns = maxConcurrentRuns || 1;
var self = this, tim, result, block=0;
function resetBlock(){ block --; };
function rememberWrapper(){
if (block < maxConcurrentRuns) {
block ++;
result = self.apply(this,arguments);
if (delay) setTimeout(resetBlock, delay);
}
// -*- Mode: MooTools Javascript; tab-width: 4; -*-
// @require 'mootools'
var MyClass = new Class({
Implements: Events,
initialize: function(){
},
@subtleGradient
subtleGradient / HOWTO.js
Created May 3, 2009 16:58
A better Function binds idiom?
/*
How to bind a function to an object manually
*/
function myFunkyFunction(){
alert(this.innerHTML);
};
(function(){
var div1 = document.createElement('div'); document.body.appendChild(div1); div1.innerHTML = 'myDiv 1';