Skip to content

Instantly share code, notes, and snippets.

View lazd's full-sized avatar

Larry Davis lazd

View GitHub Profile
function delegate(el, type, selector, callback) {
el = typeof el === 'string' ? document.querySelector(el) : el;
if (!el) return;
el.addEventListener(type, function(event) {
var node = event.target;
while (node && node !== el) {
if (node.matches(selector))
callback.call(node, event);
node = node.parentNode;
}
@lazd
lazd / Names.md
Last active August 29, 2015 13:56
A sample of template markup from a new, as yet unnamed, template system

Potential names:

  • domly - like Dolly the sheep, DOMly uses cloneNode and createElement to be fast (via Aysegul Yonet). 🐑
  • dolly - like Dolly the sheep, the language clones HTML" (via Aysegul Yonet)
  • doml - dom language
  • domtl - dom template language
  • domtml - dom template markup language
  • tmul - "template mark-up language" (via Parag Tope)
    • Also stands for "The Milwaukee Urban League" and a problem code from SPOJ
  • templet - "root word of template, petite version of template" (via Parag Tope)
@lazd
lazd / domly-example.html
Created February 25, 2014 06:42
DOMly Example
<div>
<h1>Category: {{data.category}}</h1>
<if data.items.length>
<ul>
<foreach data.items>
<li>
<h2>{{parent.category}}: {{data.name}}</h2>
<h3 if-data.sale='class="sale"'>{{data.rice}}</h3>
<h3>{{formatCount(data.stockCount)}} in stock</h3>
<button unless-data.stockCount='disabled="disabled"'>Buy now</button>
@lazd
lazd / mixin.js
Last active August 29, 2015 14:01
Mixin Question
// Define a class
var A = Class({
toString: 'A',
// Define a method
method: function() {
return 'ClassA';
}
});
var boxMaterial = new THREE.LineBasicMaterial({
color: new THREE.Color('red')
});
// Create the lines for the "2D box"
var boxGeometry = new THREE.Geometry();
boxGeometry.vertices.push(new THREE.Vector3(-1, 0, 0));
boxGeometry.vertices.push(new THREE.Vector3( 0, 1, 0));
boxGeometry.vertices.push(new THREE.Vector3( 1, 0, 0));
boxGeometry.vertices.push(new THREE.Vector3( 0, -1, 0));
@lazd
lazd / shader.c
Created November 26, 2014 02:11
shader
uniform vec3 glowColor;
uniform float coeficient;
uniform float cutoff;
uniform float power;
varying vec3 vVertexNormal;
varying vec3 vVertexWorldPosition;
void main(){
vec3 worldCameraToVertex = vVertexWorldPosition - cameraPosition;
@lazd
lazd / Backbone.SuperRouter.js
Created February 17, 2015 06:21
A super-charged Backbone router
Backbone.SuperRouter = Backbone.Router.extend({
// The name of the application (used when setting title)
appName: 'MyApp',
// The default route
homeRoute: '/',
// List of URLs to avoid tracking
noTrack: [],
@lazd
lazd / master.js
Created March 3, 2015 21:21
DOMly Issue #22: master
this["templates"] = {};
this["templates"]["Advanced"] = (function anonymous(data_0) {
var data = data_0;
var el0 = document.createElement("div");
el0.className = "person";
var el2 = document.createElement("h1");
el2.className = "name";
el2.textContent = data_0["name"];
el0.appendChild(el2);
var el4 = document.createElement("h2");
@lazd
lazd / templates.js
Created March 3, 2015 21:22
DOMly Issue #22: issue/22
this["templates"] = {};
this["templates"]["Advanced"] = (function anonymous(data_0) {
var data = data_0;
var el0 = document.createElement("div");
el0.className = "person";
var el2 = document.createElement("h1");
el2.className = "name";
el2.textContent = data_0["name"];
el0.appendChild(el2);
var el4 = document.createElement("h2");
@lazd
lazd / templates.js
Created March 3, 2015 21:23
DOMly Issue #22: issue/22-no-vars
this["templates"] = {};
this["templates"]["Advanced"] = (function anonymous(data_in) {
var data;
var stack = [data_in];
var el0 = document.createElement("div");
el0.className = "person";
var el2 = document.createElement("h1");
el2.className = "name";
el2.textContent = stack[0]["name"];
el0.appendChild(el2);