Skip to content

Instantly share code, notes, and snippets.

View bloodyowl's full-sized avatar
🦉

Matthias Le Brun bloodyowl

🦉
View GitHub Profile
@bloodyowl
bloodyowl / JSONP.js
Last active December 10, 2015 01:09
JSONP draft (Craft.js)
;(function(window, document){
function getJSONP(url, done){
var callback = "request" + (+new Date())
, script = Element.make("script", {
type : "text/javascript",
src: url + (!!~url.indexOf("?") ? "&" : "?") + "callback=" + callback
})
window[callback] = function(object){
@bloodyowl
bloodyowl / gist:4357050
Created December 22, 2012 02:10
Craft.js next update

Craft.js next update

  • Event delegation included in the core
  • JSONP requests
  • Defer
var clickEvent = "createTouch" in document ? "touchend" : "click"
// $(myElement).on(clickEvent, ...)
// myElement.addEventListener(clickEvent, ...)
@bloodyowl
bloodyowl / README.md
Last active December 10, 2015 19:08
WTFJS

WTFJS

WTF?

Rules

A WTF expression :

  • is wrapped inside ()
  • starts with ([] + []) to define a new String
@bloodyowl
bloodyowl / gist:4665523
Created January 29, 2013 16:25
getElementStyle
function getElementStyle(element, property) {
var style = "getComputedStyle" in window ? getComputedStyle(element, null) : element.currentStyle
if(!property) return style
property = property.replace(/-\D/g, function(a, i){return i !== 0 ? a.charAt(1).toUpperCase() : a.charAt(1)})
return style[property]
}
@bloodyowl
bloodyowl / whosmad.js
Created February 1, 2013 14:58
Whosmad
javascript:
[].forEach.call(
document.querySelectorAll("*")
, function(a){
setTimeout(function(){
a.style.border = a.style.border == ""
? "" + Math.floor(Math.random()*6) + "px solid " + ["red", "blue", "green", "yellow", "purple"][Math.floor(Math.random()*6)]
: ""
setTimeout(arguments.callee, 300)
}, 300)
@bloodyowl
bloodyowl / gist:4750934
Last active December 12, 2015 09:19
getScripts
function getScripts(string){
var regExp = /<script[^>]*>([\s\S]*?)<\/script>/g
, match = string.match(regExp)
, i = 0, l, result = [], item
if(!match) return function(){}
l = match.length
for(;i < l; i++) if(item = match[i].replace(regExp, "$1")) result.push(item)
if(result) return new Function(result.join(";"))
}
@bloodyowl
bloodyowl / gist:4751722
Last active December 12, 2015 09:29
getByClass
function toArray(arrayLike){
var l = arrayLike.length
, a = Array(l)
for(;l--;) a[l] = arrayLike[l]
return a
}
function getByClass(className, context){
context = context || document
if("getElementsByClassName" in context) return toArray(context.getElementsByClassName(className))
@bloodyowl
bloodyowl / gist:4955668
Last active December 13, 2015 18:28
getCookie
function getCookie(){
var cookie = document.cookie
, regExp = /\s*([\w\-]+?)\s*=\s*([^;]*?)\s*(?:;|$)\s*/g
, obj = {}
cookie.replace(regExp, function(match, name, value){obj[name] = value})
return obj
}
@bloodyowl
bloodyowl / gist:4973275
Created February 17, 2013 20:26
document.ready
;(function(){
function ready(fn){
if (ready.status) window.setTimeout(fn, 0)
else ready.stack.push(fn)
}
function updateStatus(){
var i = 0
if(!/in/.test(document.readyState) && document.body) {