web/wp-includes/js/scriptaculous/builder.js
changeset 194 32102edaa81b
parent 136 bde1974c263b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 // script.aculo.us builder.js v1.8.0, Tue Nov 06 15:01:40 +0300 2007
     1 // script.aculo.us builder.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
     2 
     2 
     3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     3 // Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     4 //
     4 //
     5 // script.aculo.us is freely distributable under the terms of an MIT-style license.
     5 // script.aculo.us is freely distributable under the terms of an MIT-style license.
     6 // For details, see the script.aculo.us web site: http://script.aculo.us/
     6 // For details, see the script.aculo.us web site: http://script.aculo.us/
     7 
     7 
     8 var Builder = {
     8 var Builder = {
    24   },
    24   },
    25   // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
    25   // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
    26   //       due to a Firefox bug
    26   //       due to a Firefox bug
    27   node: function(elementName) {
    27   node: function(elementName) {
    28     elementName = elementName.toUpperCase();
    28     elementName = elementName.toUpperCase();
    29     
    29 
    30     // try innerHTML approach
    30     // try innerHTML approach
    31     var parentTag = this.NODEMAP[elementName] || 'div';
    31     var parentTag = this.NODEMAP[elementName] || 'div';
    32     var parentElement = document.createElement(parentTag);
    32     var parentElement = document.createElement(parentTag);
    33     try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
    33     try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
    34       parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
    34       parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
    35     } catch(e) {}
    35     } catch(e) {}
    36     var element = parentElement.firstChild || null;
    36     var element = parentElement.firstChild || null;
    37       
    37 
    38     // see if browser added wrapping tags
    38     // see if browser added wrapping tags
    39     if(element && (element.tagName.toUpperCase() != elementName))
    39     if(element && (element.tagName.toUpperCase() != elementName))
    40       element = element.getElementsByTagName(elementName)[0];
    40       element = element.getElementsByTagName(elementName)[0];
    41     
    41 
    42     // fallback to createElement approach
    42     // fallback to createElement approach
    43     if(!element) element = document.createElement(elementName);
    43     if(!element) element = document.createElement(elementName);
    44     
    44 
    45     // abort if nothing could be created
    45     // abort if nothing could be created
    46     if(!element) return;
    46     if(!element) return;
    47 
    47 
    48     // attributes (or text)
    48     // attributes (or text)
    49     if(arguments[1])
    49     if(arguments[1])
    60             } catch(e) {}
    60             } catch(e) {}
    61             element = parentElement.firstChild || null;
    61             element = parentElement.firstChild || null;
    62             // workaround firefox 1.0.X bug
    62             // workaround firefox 1.0.X bug
    63             if(!element) {
    63             if(!element) {
    64               element = document.createElement(elementName);
    64               element = document.createElement(elementName);
    65               for(attr in arguments[1]) 
    65               for(attr in arguments[1])
    66                 element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
    66                 element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
    67             }
    67             }
    68             if(element.tagName.toUpperCase() != elementName)
    68             if(element.tagName.toUpperCase() != elementName)
    69               element = parentElement.getElementsByTagName(elementName)[0];
    69               element = parentElement.getElementsByTagName(elementName)[0];
    70           }
    70           }
    71         } 
    71         }
    72 
    72 
    73     // text, or array of children
    73     // text, or array of children
    74     if(arguments[2])
    74     if(arguments[2])
    75       this._children(element, arguments[2]);
    75       this._children(element, arguments[2]);
    76 
    76 
    77      return element;
    77      return $(element);
    78   },
    78   },
    79   _text: function(text) {
    79   _text: function(text) {
    80      return document.createTextNode(text);
    80      return document.createTextNode(text);
    81   },
    81   },
    82 
    82 
    98       return;
    98       return;
    99     }
    99     }
   100     if(typeof children=='object') { // array can hold nodes and text
   100     if(typeof children=='object') { // array can hold nodes and text
   101       children.flatten().each( function(e) {
   101       children.flatten().each( function(e) {
   102         if(typeof e=='object')
   102         if(typeof e=='object')
   103           element.appendChild(e)
   103           element.appendChild(e);
   104         else
   104         else
   105           if(Builder._isStringOrNumber(e))
   105           if(Builder._isStringOrNumber(e))
   106             element.appendChild(Builder._text(e));
   106             element.appendChild(Builder._text(e));
   107       });
   107       });
   108     } else
   108     } else
   115   build: function(html) {
   115   build: function(html) {
   116     var element = this.node('div');
   116     var element = this.node('div');
   117     $(element).update(html.strip());
   117     $(element).update(html.strip());
   118     return element.down();
   118     return element.down();
   119   },
   119   },
   120   dump: function(scope) { 
   120   dump: function(scope) {
   121     if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope 
   121     if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope
   122   
   122 
   123     var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
   123     var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
   124       "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
   124       "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
   125       "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
   125       "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
   126       "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
   126       "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
   127       "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
   127       "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
   128       "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
   128       "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
   129   
   129 
   130     tags.each( function(tag){ 
   130     tags.each( function(tag){
   131       scope[tag] = function() { 
   131       scope[tag] = function() {
   132         return Builder.node.apply(Builder, [tag].concat($A(arguments)));  
   132         return Builder.node.apply(Builder, [tag].concat($A(arguments)));
   133       } 
   133       };
   134     });
   134     });
   135   }
   135   }
   136 }
   136 };