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