raw
mp-wp_genesis           1 // script.aculo.us builder.js v1.8.0, Tue Nov 06 15:01:40 +0300 2007
mp-wp_genesis 2
mp-wp_genesis 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
mp-wp_genesis 4 //
mp-wp_genesis 5 // script.aculo.us is freely distributable under the terms of an MIT-style license.
mp-wp_genesis 6 // For details, see the script.aculo.us web site: http://script.aculo.us/
mp-wp_genesis 7
mp-wp_genesis 8 var Builder = {
mp-wp_genesis 9 NODEMAP: {
mp-wp_genesis 10 AREA: 'map',
mp-wp_genesis 11 CAPTION: 'table',
mp-wp_genesis 12 COL: 'table',
mp-wp_genesis 13 COLGROUP: 'table',
mp-wp_genesis 14 LEGEND: 'fieldset',
mp-wp_genesis 15 OPTGROUP: 'select',
mp-wp_genesis 16 OPTION: 'select',
mp-wp_genesis 17 PARAM: 'object',
mp-wp_genesis 18 TBODY: 'table',
mp-wp_genesis 19 TD: 'table',
mp-wp_genesis 20 TFOOT: 'table',
mp-wp_genesis 21 TH: 'table',
mp-wp_genesis 22 THEAD: 'table',
mp-wp_genesis 23 TR: 'table'
mp-wp_genesis 24 },
mp-wp_genesis 25 // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
mp-wp_genesis 26 // due to a Firefox bug
mp-wp_genesis 27 node: function(elementName) {
mp-wp_genesis 28 elementName = elementName.toUpperCase();
mp-wp_genesis 29
mp-wp_genesis 30 // try innerHTML approach
mp-wp_genesis 31 var parentTag = this.NODEMAP[elementName] || 'div';
mp-wp_genesis 32 var parentElement = document.createElement(parentTag);
mp-wp_genesis 33 try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
mp-wp_genesis 34 parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
mp-wp_genesis 35 } catch(e) {}
mp-wp_genesis 36 var element = parentElement.firstChild || null;
mp-wp_genesis 37
mp-wp_genesis 38 // see if browser added wrapping tags
mp-wp_genesis 39 if(element && (element.tagName.toUpperCase() != elementName))
mp-wp_genesis 40 element = element.getElementsByTagName(elementName)[0];
mp-wp_genesis 41
mp-wp_genesis 42 // fallback to createElement approach
mp-wp_genesis 43 if(!element) element = document.createElement(elementName);
mp-wp_genesis 44
mp-wp_genesis 45 // abort if nothing could be created
mp-wp_genesis 46 if(!element) return;
mp-wp_genesis 47
mp-wp_genesis 48 // attributes (or text)
mp-wp_genesis 49 if(arguments[1])
mp-wp_genesis 50 if(this._isStringOrNumber(arguments[1]) ||
mp-wp_genesis 51 (arguments[1] instanceof Array) ||
mp-wp_genesis 52 arguments[1].tagName) {
mp-wp_genesis 53 this._children(element, arguments[1]);
mp-wp_genesis 54 } else {
mp-wp_genesis 55 var attrs = this._attributes(arguments[1]);
mp-wp_genesis 56 if(attrs.length) {
mp-wp_genesis 57 try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
mp-wp_genesis 58 parentElement.innerHTML = "<" +elementName + " " +
mp-wp_genesis 59 attrs + "></" + elementName + ">";
mp-wp_genesis 60 } catch(e) {}
mp-wp_genesis 61 element = parentElement.firstChild || null;
mp-wp_genesis 62 // workaround firefox 1.0.X bug
mp-wp_genesis 63 if(!element) {
mp-wp_genesis 64 element = document.createElement(elementName);
mp-wp_genesis 65 for(attr in arguments[1])
mp-wp_genesis 66 element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
mp-wp_genesis 67 }
mp-wp_genesis 68 if(element.tagName.toUpperCase() != elementName)
mp-wp_genesis 69 element = parentElement.getElementsByTagName(elementName)[0];
mp-wp_genesis 70 }
mp-wp_genesis 71 }
mp-wp_genesis 72
mp-wp_genesis 73 // text, or array of children
mp-wp_genesis 74 if(arguments[2])
mp-wp_genesis 75 this._children(element, arguments[2]);
mp-wp_genesis 76
mp-wp_genesis 77 return element;
mp-wp_genesis 78 },
mp-wp_genesis 79 _text: function(text) {
mp-wp_genesis 80 return document.createTextNode(text);
mp-wp_genesis 81 },
mp-wp_genesis 82
mp-wp_genesis 83 ATTR_MAP: {
mp-wp_genesis 84 'className': 'class',
mp-wp_genesis 85 'htmlFor': 'for'
mp-wp_genesis 86 },
mp-wp_genesis 87
mp-wp_genesis 88 _attributes: function(attributes) {
mp-wp_genesis 89 var attrs = [];
mp-wp_genesis 90 for(attribute in attributes)
mp-wp_genesis 91 attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
mp-wp_genesis 92 '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
mp-wp_genesis 93 return attrs.join(" ");
mp-wp_genesis 94 },
mp-wp_genesis 95 _children: function(element, children) {
mp-wp_genesis 96 if(children.tagName) {
mp-wp_genesis 97 element.appendChild(children);
mp-wp_genesis 98 return;
mp-wp_genesis 99 }
mp-wp_genesis 100 if(typeof children=='object') { // array can hold nodes and text
mp-wp_genesis 101 children.flatten().each( function(e) {
mp-wp_genesis 102 if(typeof e=='object')
mp-wp_genesis 103 element.appendChild(e)
mp-wp_genesis 104 else
mp-wp_genesis 105 if(Builder._isStringOrNumber(e))
mp-wp_genesis 106 element.appendChild(Builder._text(e));
mp-wp_genesis 107 });
mp-wp_genesis 108 } else
mp-wp_genesis 109 if(Builder._isStringOrNumber(children))
mp-wp_genesis 110 element.appendChild(Builder._text(children));
mp-wp_genesis 111 },
mp-wp_genesis 112 _isStringOrNumber: function(param) {
mp-wp_genesis 113 return(typeof param=='string' || typeof param=='number');
mp-wp_genesis 114 },
mp-wp_genesis 115 build: function(html) {
mp-wp_genesis 116 var element = this.node('div');
mp-wp_genesis 117 $(element).update(html.strip());
mp-wp_genesis 118 return element.down();
mp-wp_genesis 119 },
mp-wp_genesis 120 dump: function(scope) {
mp-wp_genesis 121 if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
mp-wp_genesis 122
mp-wp_genesis 123 var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
mp-wp_genesis 124 "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
mp-wp_genesis 125 "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
mp-wp_genesis 126 "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
mp-wp_genesis 127 "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
mp-wp_genesis 128 "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
mp-wp_genesis 129
mp-wp_genesis 130 tags.each( function(tag){
mp-wp_genesis 131 scope[tag] = function() {
mp-wp_genesis 132 return Builder.node.apply(Builder, [tag].concat($A(arguments)));
mp-wp_genesis 133 }
mp-wp_genesis 134 });
mp-wp_genesis 135 }
mp-wp_genesis 136 }