Skip to content

Instantly share code, notes, and snippets.

@roundcorners
roundcorners / namespace-check.js
Created February 1, 2012 18:24
Checking properties before assignment
// These checks ensure the namespace is only created if it doesn't already exist.
var myNamespace = myNamespace || {},
// A check is required for each subsequent property of the namespace
application = myNamespace.application || {},
myFunc = myNamespace.application.anotherProperty.myFunc || function () {
// function definition...
};
@roundcorners
roundcorners / namespace-method.js
Created January 24, 2012 21:19
Namespacing method
/**
* @name: [namespace] adds properties to the current namespace object.
* @argument[0] [name_str] {String} the propert(y/ies) we want to add.
* @returns {Object} the augmented namespace.
*/
// Check for the namespace, create it if not already defined
(MyNamespace || MyNamespace = {}).namespace = function(name_str) {
// Split the name string into an array of parts
var parts = name_str.split('.'),
part, i, len,
@roundcorners
roundcorners / simple-nameapce-pattern.js
Created January 24, 2012 21:06
Namespacing with a object literal
// Top-level namespace
var MyNamespace = {};
// Adding properties to my namespace
MyNamespace.application = {};
// OR
MyNamespace.['application'] = {};
@roundcorners
roundcorners / gradient-button.css
Created November 21, 2011 14:22
Button gradient style
.button {
padding:5px 0;
}
.button a {
background-color: #ffce00;
border: 1px solid #aaa;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
@roundcorners
roundcorners / Popouts.js
Created November 4, 2011 15:41
Class that adds functionality to help nodes
sky.home_move.Popouts = function(pod) {
sky.home_move.Popouts.pods.push(pod);
this.pod = $(pod);
this.helpBtn = this.pod.find('a.help').eq(0);
this.inputs = this.pod.find(':input:not(:image, :radio)');
this.radios = this.pod.find('input[type="radio"]');
this.setupEventListeners();
@roundcorners
roundcorners / no-legend.html
Created November 4, 2011 13:27
A simple XHTML document where a fieldset has no legend element
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<fieldset>
</fieldset>
@roundcorners
roundcorners / debug.js
Created November 4, 2011 11:46
Check for console support
var debug = function(text) {
( (window.console && console.log) || window.alert).call(this, text);
}
@roundcorners
roundcorners / admin.py
Created November 3, 2011 17:03
Working admin.py
class PostAdmin:
...
...
// CommonMedia defined as a subclass of PostAdmin
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
'/appmedia/admin/js/editor.js',
)
css = {
@roundcorners
roundcorners / orig-admin.py
Created November 3, 2011 16:21
The original admin.py with CommonMedia class
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
'/appmedia/admin/js/editor.js',
)
css = {
'all': ('/appmedia/admin/css/editor.css',),
}
// Register new class
@roundcorners
roundcorners / editor.css
Created November 3, 2011 16:16
Styles for dijit.editor
/* Import standard Dojo CSS files */
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dijit/themes/claro/claro.css";
/* Import custom style sheets for plugins */
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/FindReplace.css";
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/ShowBlockNodes.css";
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/InsertEntity.css";
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/CollapsibleToolbar.css";
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/Blockquote.css";
@import "https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojox/editor/plugins/resources/css/PasteFromWord.css";