Skip to content

Instantly share code, notes, and snippets.

@kavanagh
kavanagh / namespace.js
Created June 2, 2012 11:00
Simple namespace function
(function(global){
global.namespace = function namespace(name, context) {
var names = name.split('.'), name;
context = context || global;
while (name = names.shift()) {
context = context[name] = context[name] || new function(){};
}
return context;
};
@kavanagh
kavanagh / AppendStylesheet.js
Created April 16, 2012 15:24
Append CSS Stylesheet to the head using jQuery
$.appendStylesheet = function appendStylesheet(url, callback) {
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.href = url;
link.rel = "stylesheet";
link.type = "text/css";
if (callback && $.isFunction(callback)) {