1 // script.aculo.us builder.js v1.6.4, Wed Sep 06 11:30:58 CEST 2006
3 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
5 // See scriptaculous.js for full license.
24 // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
25 // due to a Firefox bug
26 node: function(elementName) {
27 elementName = elementName.toUpperCase();
29 // try innerHTML approach
30 var parentTag = this.NODEMAP[elementName] || 'div';
31 var parentElement = document.createElement(parentTag);
32 try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
33 parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
35 var element = parentElement.firstChild || null;
37 // see if browser added wrapping tags
38 if(element && (element.tagName != elementName))
39 element = element.getElementsByTagName(elementName)[0];
41 // fallback to createElement approach
42 if(!element) element = document.createElement(elementName);
44 // abort if nothing could be created
47 // attributes (or text)
49 if(this._isStringOrNumber(arguments[1]) ||
50 (arguments[1] instanceof Array)) {
51 this._children(element, arguments[1]);
53 var attrs = this._attributes(arguments[1]);
55 try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
56 parentElement.innerHTML = "<" +elementName + " " +
57 attrs + "></" + elementName + ">";
59 element = parentElement.firstChild || null;
60 // workaround firefox 1.0.X bug
62 element = document.createElement(elementName);
63 for(attr in arguments[1])
64 element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
66 if(element.tagName != elementName)
67 element = parentElement.getElementsByTagName(elementName)[0];
71 // text, or array of children
73 this._children(element, arguments[2]);
77 _text: function(text) {
78 return document.createTextNode(text);
80 _attributes: function(attributes) {
82 for(attribute in attributes)
83 attrs.push((attribute=='className' ? 'class' : attribute) +
84 '="' + attributes[attribute].toString().escapeHTML() + '"');
85 return attrs.join(" ");
87 _children: function(element, children) {
88 if(typeof children=='object') { // array can hold nodes and text
89 children.flatten().each( function(e) {
90 if(typeof e=='object')
91 element.appendChild(e)
93 if(Builder._isStringOrNumber(e))
94 element.appendChild(Builder._text(e));
97 if(Builder._isStringOrNumber(children))
98 element.appendChild(Builder._text(children));
100 _isStringOrNumber: function(param) {
101 return(typeof param=='string' || typeof param=='number');
103 dump: function(scope) {
104 if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
106 var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
107 "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
108 "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
109 "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
110 "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
111 "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
113 tags.each( function(tag){
114 scope[tag] = function() {
115 return Builder.node.apply(Builder, [tag].concat($A(arguments)));