dom/tests/mochitest/ajax/scriptaculous/src/builder.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/ajax/scriptaculous/src/builder.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     1.4 +// script.aculo.us builder.js v1.7.1_beta2, Tue May 15 15:15:45 EDT 2007
     1.5 +
     1.6 +// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
     1.7 +//
     1.8 +// script.aculo.us is freely distributable under the terms of an MIT-style license.
     1.9 +// For details, see the script.aculo.us web site: http://script.aculo.us/
    1.10 +
    1.11 +var Builder = {
    1.12 +  NODEMAP: {
    1.13 +    AREA: 'map',
    1.14 +    CAPTION: 'table',
    1.15 +    COL: 'table',
    1.16 +    COLGROUP: 'table',
    1.17 +    LEGEND: 'fieldset',
    1.18 +    OPTGROUP: 'select',
    1.19 +    OPTION: 'select',
    1.20 +    PARAM: 'object',
    1.21 +    TBODY: 'table',
    1.22 +    TD: 'table',
    1.23 +    TFOOT: 'table',
    1.24 +    TH: 'table',
    1.25 +    THEAD: 'table',
    1.26 +    TR: 'table'
    1.27 +  },
    1.28 +  // note: For Firefox < 1.5, OPTION and OPTGROUP tags are currently broken,
    1.29 +  //       due to a Firefox bug
    1.30 +  node: function(elementName) {
    1.31 +    elementName = elementName.toUpperCase();
    1.32 +    
    1.33 +    // try innerHTML approach
    1.34 +    var parentTag = this.NODEMAP[elementName] || 'div';
    1.35 +    var parentElement = document.createElement(parentTag);
    1.36 +    try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
    1.37 +      parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
    1.38 +    } catch(e) {}
    1.39 +    var element = parentElement.firstChild || null;
    1.40 +      
    1.41 +    // see if browser added wrapping tags
    1.42 +    if(element && (element.tagName.toUpperCase() != elementName))
    1.43 +      element = element.getElementsByTagName(elementName)[0];
    1.44 +    
    1.45 +    // fallback to createElement approach
    1.46 +    if(!element) element = document.createElement(elementName);
    1.47 +    
    1.48 +    // abort if nothing could be created
    1.49 +    if(!element) return;
    1.50 +
    1.51 +    // attributes (or text)
    1.52 +    if(arguments[1])
    1.53 +      if(this._isStringOrNumber(arguments[1]) ||
    1.54 +        (arguments[1] instanceof Array) ||
    1.55 +        arguments[1].tagName) {
    1.56 +          this._children(element, arguments[1]);
    1.57 +        } else {
    1.58 +          var attrs = this._attributes(arguments[1]);
    1.59 +          if(attrs.length) {
    1.60 +            try { // prevent IE "feature": http://dev.rubyonrails.org/ticket/2707
    1.61 +              parentElement.innerHTML = "<" +elementName + " " +
    1.62 +                attrs + "></" + elementName + ">";
    1.63 +            } catch(e) {}
    1.64 +            element = parentElement.firstChild || null;
    1.65 +            // workaround firefox 1.0.X bug
    1.66 +            if(!element) {
    1.67 +              element = document.createElement(elementName);
    1.68 +              for(attr in arguments[1]) 
    1.69 +                element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
    1.70 +            }
    1.71 +            if(element.tagName.toUpperCase() != elementName)
    1.72 +              element = parentElement.getElementsByTagName(elementName)[0];
    1.73 +          }
    1.74 +        } 
    1.75 +
    1.76 +    // text, or array of children
    1.77 +    if(arguments[2])
    1.78 +      this._children(element, arguments[2]);
    1.79 +
    1.80 +     return element;
    1.81 +  },
    1.82 +  _text: function(text) {
    1.83 +     return document.createTextNode(text);
    1.84 +  },
    1.85 +
    1.86 +  ATTR_MAP: {
    1.87 +    'className': 'class',
    1.88 +    'htmlFor': 'for'
    1.89 +  },
    1.90 +
    1.91 +  _attributes: function(attributes) {
    1.92 +    var attrs = [];
    1.93 +    for(attribute in attributes)
    1.94 +      attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) +
    1.95 +          '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'&quot;') + '"');
    1.96 +    return attrs.join(" ");
    1.97 +  },
    1.98 +  _children: function(element, children) {
    1.99 +    if(children.tagName) {
   1.100 +      element.appendChild(children);
   1.101 +      return;
   1.102 +    }
   1.103 +    if(typeof children=='object') { // array can hold nodes and text
   1.104 +      children.flatten().each( function(e) {
   1.105 +        if(typeof e=='object')
   1.106 +          element.appendChild(e)
   1.107 +        else
   1.108 +          if(Builder._isStringOrNumber(e))
   1.109 +            element.appendChild(Builder._text(e));
   1.110 +      });
   1.111 +    } else
   1.112 +      if(Builder._isStringOrNumber(children))
   1.113 +        element.appendChild(Builder._text(children));
   1.114 +  },
   1.115 +  _isStringOrNumber: function(param) {
   1.116 +    return(typeof param=='string' || typeof param=='number');
   1.117 +  },
   1.118 +  build: function(html) {
   1.119 +    var element = this.node('div');
   1.120 +    $(element).update(html.strip());
   1.121 +    return element.down();
   1.122 +  },
   1.123 +  dump: function(scope) { 
   1.124 +    if(typeof scope != 'object' && typeof scope != 'function') scope = window; //global scope 
   1.125 +  
   1.126 +    var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
   1.127 +      "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
   1.128 +      "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
   1.129 +      "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
   1.130 +      "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
   1.131 +      "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);
   1.132 +  
   1.133 +    tags.each( function(tag){ 
   1.134 +      scope[tag] = function() { 
   1.135 +        return Builder.node.apply(Builder, [tag].concat($A(arguments)));  
   1.136 +      } 
   1.137 +    });
   1.138 +  }
   1.139 +}

mercurial