Permalink
Browse files

update $e

  • Loading branch information...
1 parent 45febfd commit 24f1bb51a6ef0f97d3b4fbafa1b377f81947ead5 @reednj committed Apr 8, 2013
Showing with 45 additions and 39 deletions.
  1. +45 −39 Source/jsTable.js
View
@@ -349,45 +349,51 @@ var jsTable = new Class({
// License: MIT-Style License
// Nathan Reed (c) 2010
//
-function $e(tag, props) {
- tag = tag || 'div';
-
- if(!$defined(props)) {
- return new Element(tag);
- }
-
- // normalize the properties element for the
- // mootools element constructor
- if($type(props) == 'string') {
- props = {'text': props};
- } else if($type(props) == 'element') {
- props = {'children': props};
- }
-
- // remove the children property from the array, we don't want it in there.
- // because when we pass these properties to the mootools element function it
- // might get confused.
- var children = props.children;
- props.children = null;
-
- var new_element = new Element(tag, props);
-
- if($defined(children)) {
-
- if($type(children) == 'element') {
- // if they have just passed through one child, then
- // normalize it by turning it into an array with one element.
- children = [children];
- }
-
- // add the children to the new element one by one
- children.each(function(item) {
- new_element.grab(item);
- });
-
- }
-
- return new_element
+if(typeof $e == 'undefined') {
+ var $e = function(tag, options) {
+ tag = tag || 'div';
+
+ if(!options) {
+ return new Element(tag);
+ }
+
+ // normalize the properties element for the
+ // mootools element constructor
+ if(typeOf(options) == 'string') {
+ options = {'text': options};
+ } else if(typeOf(options) == 'element') {
+ options = {'children': [options]};
+ } else if(typeOf(options) == 'array') {
+ options = {'children': options};
+ }
+
+ // remove the children property from the array, we don't want it in there.
+ // because when we pass these properties to the mootools element function it
+ // might get confused.
+ var children = options.children;
+ options.children = null;
+
+ var newElement = new Element(tag, options);
+
+ if(children) {
+
+ if(typeOf(children) == 'element') {
+ // if they have just passed through one child, then
+ // normalize it by turning it into an array with one element.
+ children = [children];
+ }
+
+ // add the children to the new element one by one
+ children.each(function(elem) {
+ if(typeOf(elem) == 'element') {
+ newElement.grab(elem);
+ }
+ });
+
+ }
+
+ return newElement
+ }
}
// this is now implemented in mootool.more (finally!)

0 comments on commit 24f1bb5

Please sign in to comment.