Skip to content

Instantly share code, notes, and snippets.

"app".foo(); // Fail. The method `foo` doesn't exist
require('commonjs_mod'); // Modifies the String native
"app".foo(); // no Fail. The method `foo` was added
@subtleGradient
subtleGradient / History.Routing.js
Created December 16, 2009 15:18
Harald Kirschner's (http://digitarald.de/) MooTools History (replaces HistoryManager)
/**
* History.Routing
*
* @version 2.0
*
* @license MIT License
* @author Harald Kirschner <mail [at] digitarald.de>
* @copyright 2008 Author
*/
var MyClass = new Class({
initialize: function(){
this.foo = /*<b compat=1.2>*/'123' && /*</b>*/'345';
/*<b compat=1.2>*/this.foo = '123';/*</b>*/
this.foo = '345';
},
//<b fix=ie6>
method: function(/*<b compat=1.2>*/arg12, /*</b>*/arg20){
(function(write, wrapper, slice, fragment){
document.write = function(){
var id = 'document_write' + $time().toString(36);
var html = slice.call(arguments).join('');
write.call(document, '<span id="' + id + '"></span>');
window.addEvent('domready', function(){
$A(wrapper.set('html', html).childNodes).filter(document.write.filter).each(function(node){
var btn = new Element('button',{html:'Run'}).addEvent('click', Context('dynamic').handleWith('handleClick'));
Ccontext(1).addHandler('handleClick', function(){alert(1);});
Ccontext(2).addHandler('handleClick', function(){alert(2);});
Context.set(1);
Context('dynamic') === Context(1);
btn.fireEvent('click'); // alert(1)
Context.set(2);
// # -- sequential speccing
var group1 = spec.group('description');
group1.add('some description', fn);
group1.add('some other description', fn);
var group2 = spec.group('description2');
group2.add('some description', fn);
group2.add('some other description', fn);
// 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){
var Dictionary = new Native({
name: 'Dictionary',
initialize: function(){
this.keys = [];
this.values = [];
}
});
@subtleGradient
subtleGradient / README.js
Created October 15, 2008 13:44
Event Delegation by Stedia and the MooTools Dev Team
// basic usage:
$('myParentElement').relayEvents({
'a.menuitem':{
'click': function(e){}
},
'input[name=phone]':{
'keydown': function(e){},
@subtleGradient
subtleGradient / Paste to Gist_GitHub Anonymously.tmCommand
Created July 28, 2008 19:13 — forked from pieter/gistie.rb
gistie.rb Paste code to gist.github.com from the shell!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>2E6B9F06-DDB6-4707-A2BB-8751CF1722A0</string>
<key>command</key>
<string>cat|gist -a "$TM_FILENAME"