Skip to content

Instantly share code, notes, and snippets.

View bloodyowl's full-sized avatar
🦉

Matthias Le Brun bloodyowl

🦉
View GitHub Profile
@bloodyowl
bloodyowl / LICENSE.txt
Created October 26, 2012 17:04 — forked from 140bytes/LICENSE.txt
HTML5forIE
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Matthias Le Brun http://mlb.li
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@bloodyowl
bloodyowl / Class.js
Created October 27, 2012 02:54
dead simple Class function
function Class(o){
var klass = function(){ return o.init.apply(this, arguments) },
parent = o.parent,
prototype = "prototype",
i;
if(parent) {
klass[prototype] = parent[prototype];
klass[prototype].parent = function(){parent.apply(this, arguments)};
}
for(i in o) if(o.hasOwnProperty(i)) klass[prototype][i] = o[i];
@bloodyowl
bloodyowl / gist:3987147
Created October 31, 2012 13:54
Date unificator
// var dateFormat -> something returning a date like "YYYY/MM/DD", "DD-MM-YYYY", "MM/DD/YYYY" ...
// Function#curry from Craft.js
// https://github.com/mlbli/Craft/
var convertDate = (function(string, date){
var year = string.indexOf("Y"),
month = string.indexOf("M"),
day = string.indexOf("D")
return [date.slice(year, year + 4), date.slice(month, month + 2), date.slice(day, day + 2)].join("-")
@bloodyowl
bloodyowl / README.md
Created November 1, 2012 18:05
Simple Template System JavaScript

Simple Template System

Uses Craft.js (API docs).

Constructor

var myTemplate = Template.create({
   template : "<p>#{foo}<p><i>#{bar.baz}</i>",
 pattern : /#\{([a-zA-Z0-9-_.]*)\}/g,
@bloodyowl
bloodyowl / README.md
Created November 2, 2012 13:12
JS Tip : safe constructor

JS Tip : safe constructor

To prevent context issues (understand this is not what you expected), you can make the new keyword optional with constructors.

In fact, if this isn't a object that was just created by the function, a recursion that corrects the way the function is called is made.

@bloodyowl
bloodyowl / gist:4009348
Created November 3, 2012 23:42
First Word Wrapper (Craft.js)
Craft.extend(DOM.prototype, {
wrapFirstWord : function(tag){
var element = this,
text = element.get("innerHTML");
return element.empty().insert(text.replace(/^([\w]*\s)/,"<" + tag + ">$1</" + tag + ">"))
}
})
@bloodyowl
bloodyowl / combined.js
Created November 4, 2012 01:21
betterScrollEvent
var root = DOM(window)
, isScrolling = false
, interval
function getScrollState() { // verifies if window is still scrolling
if(!isScrolling) isScrolling = true
}
function getScrollStart() { // targets scrollStart and stops immediately
root.stopListening("scroll", getScrollStart).listen("scroll", getScrollState)
@bloodyowl
bloodyowl / gist:4017901
Created November 5, 2012 15:48
Get your globals
/*
Runs on Craft.js
Inspired by Thomas Fuchs DomMonster (https://github.com/madrobby/dom-monster/blob/master/src/dommonster.js)
*/
Hash(window).keys().difference(Hash(Element.make("iframe").css({display:"none"}).appendTo(document.body).get("contentWindow")).keys())
@bloodyowl
bloodyowl / README.md
Created November 11, 2012 01:02
Craft.js Simple CSS-like selector

Simple CSS-Like selectors for Craft.js

Usage

Different queries separated by a comma. Only use #id, .class, tag (no pseudo selectors).

$$("#id .class tag, tag, #id tag")
@bloodyowl
bloodyowl / index.html
Created November 12, 2012 14:00
Todo List using Craft.js and localStorage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Todo List</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Todo List</h1>
<input type="text" value="" id="add" placeholder="Add a new item and hit enter" name="add">