scripts/utopia.js
function() {
			var options;

			if(_.type(arguments[0]) === 'string') {
				if(_.type(arguments[1]) === 'object') {
					// Utopia.element.create('div', { ... });
					options = arguments[1];
					options.tag = arguments[0];
				}
				else {
					// Utopia.element.create('div', ...);
					options = {
						tag: arguments[0]
					};
					
					// Utopia.element.create('div', [contents]);
					if(_.type(arguments[1]) === 'array') {
						options.contents = arguments[1];
					}
					// Utopia.element.create('div', 'Text contents');
					else if(_.type(arguments[1]) === 'string' || _.type(arguments[1]) === 'number') {
						options.contents = ['' + arguments[1]];
					}
				}
			}
			else {
				options = arguments[0];
			}
			
			var namespace = options.namespace || '', element;
			
			if(namespace) {
				element = document.createElementNS(namespace, options.tag);
			}
			else {
				element = document.createElement(options.tag);
			}
			
			if (options.className || options.id) {
				options.properties = options.properties || {};
				options.properties.className = options.className;
				options.properties.id = options.id;
			}
			
			// Set properties, attributes and contents
			_.element.set(element, options);
			
			// Place the element in the DOM (inside, before or after an existing element)
			// This could be a selector
			if(options.before) {
				var before = $(options.before);
				
				if (before && before.parentNode) {
					before.parentNode.insertBefore(element, before);
				}
			}
			
			if (options.after && element.parentNode === null) {
				var after = $(options.after);
				
				if (after && after.parentNode) {
					after.parentNode.insertBefore(element, after.nextSibling)
				}
			}
			
			if (options.inside && element.parentNode === null) {
				$(options.inside).appendChild(element);
			}
			
			return element;
		}
function() {
			var options;

			if(_.type(arguments[0]) === 'string') {
				if(_.type(arguments[1]) === 'object') {
					// Utopia.element.create('div', { ... });
					options = arguments[1];
					options.tag = arguments[0];
				}
				else {
					// Utopia.element.create('div', ...);
					options = {
						tag: arguments[0]
					};
					
					// Utopia.element.create('div', [contents]);
					if(_.type(arguments[1]) === 'array') {
						options.contents = arguments[1];
					}
					// Utopia.element.create('div', 'Text contents');
					else if(_.type(arguments[1]) === 'string' || _.type(arguments[1]) === 'number') {
						options.contents = ['' + arguments[1]];
					}
				}
			}
			else {
				options = arguments[0];
			}
			
			var namespace = options.namespace || '', element;
			
			if(namespace) {
				element = document.createElementNS(namespace, options.tag);
			}
			else {
				element = document.createElement(options.tag);
			}
			
			if (options.className || options.id) {
				options.properties = options.properties || {};
				options.properties.className = options.className;
				options.properties.id = options.id;
			}
			
			// Set properties, attributes and contents
			_.element.set(element, options);
			
			// Place the element in the DOM (inside, before or after an existing element)
			// This could be a selector
			if(options.before) {
				var before = $(options.before);
				
				if (before && before.parentNode) {
					before.parentNode.insertBefore(element, before);
				}
			}
			
			if (options.after && element.parentNode === null) {
				var after = $(options.after);
				
				if (after && after.parentNode) {
					after.parentNode.insertBefore(element, after.nextSibling)
				}
			}
			
			if (options.inside && element.parentNode === null) {
				$(options.inside).appendChild(element);
			}
			
			return element;
		}
function ( ) { var options ; if ( _ . type ( arguments [ 0 ] ) === 'string' ) { if ( _ . type ( arguments [ 1 ] ) === 'object' ) { // Utopia.element.create('div', { ... }); options = arguments [ 1 ] ; options . tag = arguments [ 0 ] ; } else { // Utopia.element.create('div', ...); options = { tag : arguments [ 0 ] } ; // Utopia.element.create('div', [contents]); if ( _ . type ( arguments [ 1 ] ) === 'array' ) { options . contents = arguments [ 1 ] ; } // Utopia.element.create('div', 'Text contents'); else if ( _ . type ( arguments [ 1 ] ) === 'string' || _ . type ( arguments [ 1 ] ) === 'number' ) { options . contents = [ '' + arguments [ 1 ] ] ; } } } else { options = arguments [ 0 ] ; } var namespace = options . namespace || '' , element ; if ( namespace ) { element = document . createElementNS ( namespace , options . tag ) ; } else { element = document . createElement ( options . tag ) ; } if ( options . className || options . id ) { options . properties = options . properties || { } ; options . properties . className = options . className ; options . properties . id = options . id ; } // Set properties, attributes and contents _ . element . set ( element , options ) ; // Place the element in the DOM (inside, before or after an existing element) // This could be a selector if ( options . before ) { var before = $ ( options . before ) ; if ( before && before . parentNode ) { before . parentNode . insertBefore ( element , before ) ; } } if ( options . after && element . parentNode === null ) { var after = $ ( options . after ) ; if ( after && after . parentNode ) { after . parentNode . insertBefore ( element , after . nextSibling ) } } if ( options . inside && element . parentNode === null ) { $ ( options . inside ) . appendChild ( element ) ; } return element ; }
Creates a new DOM element
@param options {Object} A set of key/value pairs for attributes, properties, contents, placement in the DOM etc
@return The new DOM element
Creates a new DOM element