Super tiny JavaScript MVC framework
- Very Small
- Event emitter (bel.Emitter)
- bel object is aliased in $
- the bel() function is overloaded, is an alias to document.querySelector()
<!DOCTYPE html> | |
<html lang="en"> <!-- based on HTML5 Boilerplate and Twitter Bootstrap starter template --> | |
<head> | |
<!-- You should probably use a local version of html5shim here. --> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>Envy</title> |
var $ = function(s){ // Makes the main function (accepts one value) | |
var o = []// Makes an empty array | |
var sel = s.substring(1,s.length) // Get's the selector text minus the first character (like #) | |
switch (s.charAt(0)){ // Switch based on first chararcter | |
case '#': // If it's a #, do document.getElementById | |
o.push(document.getElementById(sel))// the element is pushed to o instead of the element being returned | |
break; | |
case '.': // If it's a ., get the element by class name | |
o.push(document.getElementsByClassName(sel)) | |
break; |
var $ = function(s){ // Makes the main function (accepts one value) | |
var sel = s.substring(1,s.length) // Get's the selector text minus the first character (like #) | |
switch (s.charAt(0)){ // Switch based on first chararcter | |
case '#': // If it's a #, do document.getElementById | |
return document.getElementById(sel) | |
break; | |
case '.': // If it's a ., get the element by class name | |
var allEls = document.getElementsByTagName('*') | |
for (var i = 0;i<allEls.length;i++){ | |
if (allEls[i].className === sel){ |
/* | |
lamb.js | |
4 lines to lambda | |
*/ | |
function lamb(s){ | |
args = s.split("->") | |
return new Function(args[0], "return "+args[1]) | |
} |
/* | |
Example | |
var test = require('./path/to/test'), | |
cake = require('..'), | |
assert = require("assert"); | |
test('eat cake', function(done){ | |
cake.eat(); | |
done(); |
/** | |
* wrap | |
* Usage | |
* var a = document.querySelector('#test'); | |
* wrap(a) | |
* | |
* or | |
* | |
* var a = wrap(document.querySelector('#test')); | |
* |
// not for POST/PUT requests | |
/** | |
* @function request | |
* @param {String} p The string to request (format "METHOD /path") | |
* @param {String} cb The callback. Takes 2 arguments, responseText and and XMLHttpReques object | |
*/ | |
function request(p, cb){ | |
var _p = p.split(' ' ), | |
method = _p[0], | |
path = _p[1], |
#!/bin/bash | |
# get_bootstrap | |
# Usage | |
# sh get_bootstrap.sh <dest> | |
# downloads twitter bootstrap to <dest> | |
echo Fetching files... | |
curl http://twitter.github.io/bootstrap/assets/bootstrap.zip > bootstrap.zip |