Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | MochiKit.Base.update(MochiKit.DOM, { |
michael@0 | 3 | /** @id MochiKit.DOM.makeClipping */ |
michael@0 | 4 | makeClipping: function (element) { |
michael@0 | 5 | element = MochiKit.DOM.getElement(element); |
michael@0 | 6 | var oldOverflow = element.style.overflow; |
michael@0 | 7 | if ((MochiKit.Style.getStyle(element, 'overflow') || 'visible') != 'hidden') { |
michael@0 | 8 | element.style.overflow = 'hidden'; |
michael@0 | 9 | } |
michael@0 | 10 | return oldOverflow; |
michael@0 | 11 | }, |
michael@0 | 12 | |
michael@0 | 13 | /** @id MochiKit.DOM.undoClipping */ |
michael@0 | 14 | undoClipping: function (element, overflow) { |
michael@0 | 15 | element = MochiKit.DOM.getElement(element); |
michael@0 | 16 | if (!overflow) { |
michael@0 | 17 | return; |
michael@0 | 18 | } |
michael@0 | 19 | element.style.overflow = overflow; |
michael@0 | 20 | }, |
michael@0 | 21 | |
michael@0 | 22 | /** @id MochiKit.DOM.makePositioned */ |
michael@0 | 23 | makePositioned: function (element) { |
michael@0 | 24 | element = MochiKit.DOM.getElement(element); |
michael@0 | 25 | var pos = MochiKit.Style.getStyle(element, 'position'); |
michael@0 | 26 | if (pos == 'static' || !pos) { |
michael@0 | 27 | element.style.position = 'relative'; |
michael@0 | 28 | // Opera returns the offset relative to the positioning context, |
michael@0 | 29 | // when an element is position relative but top and left have |
michael@0 | 30 | // not been defined |
michael@0 | 31 | if (/Opera/.test(navigator.userAgent)) { |
michael@0 | 32 | element.style.top = 0; |
michael@0 | 33 | element.style.left = 0; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | }, |
michael@0 | 37 | |
michael@0 | 38 | /** @id MochiKit.DOM.undoPositioned */ |
michael@0 | 39 | undoPositioned: function (element) { |
michael@0 | 40 | element = MochiKit.DOM.getElement(element); |
michael@0 | 41 | if (element.style.position == 'relative') { |
michael@0 | 42 | element.style.position = element.style.top = element.style.left = element.style.bottom = element.style.right = ''; |
michael@0 | 43 | } |
michael@0 | 44 | }, |
michael@0 | 45 | |
michael@0 | 46 | /** @id MochiKit.DOM.getFirstElementByTagAndClassName */ |
michael@0 | 47 | getFirstElementByTagAndClassName: function (tagName, className, |
michael@0 | 48 | /* optional */parent) { |
michael@0 | 49 | var self = MochiKit.DOM; |
michael@0 | 50 | if (typeof(tagName) == 'undefined' || tagName === null) { |
michael@0 | 51 | tagName = '*'; |
michael@0 | 52 | } |
michael@0 | 53 | if (typeof(parent) == 'undefined' || parent === null) { |
michael@0 | 54 | parent = self._document; |
michael@0 | 55 | } |
michael@0 | 56 | parent = self.getElement(parent); |
michael@0 | 57 | var children = (parent.getElementsByTagName(tagName) |
michael@0 | 58 | || self._document.all); |
michael@0 | 59 | if (typeof(className) == 'undefined' || className === null) { |
michael@0 | 60 | return children[0]; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | for (var i = 0; i < children.length; i++) { |
michael@0 | 64 | var child = children[i]; |
michael@0 | 65 | var classNames = child.className.split(' '); |
michael@0 | 66 | for (var j = 0; j < classNames.length; j++) { |
michael@0 | 67 | if (classNames[j] == className) { |
michael@0 | 68 | return child; |
michael@0 | 69 | } |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | }, |
michael@0 | 73 | |
michael@0 | 74 | /** @id MochiKit.DOM.isParent */ |
michael@0 | 75 | isParent: function (child, element) { |
michael@0 | 76 | if (!child.parentNode || child == element) { |
michael@0 | 77 | return false; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | if (child.parentNode == element) { |
michael@0 | 81 | return true; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | return MochiKit.DOM.isParent(child.parentNode, element); |
michael@0 | 85 | } |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | MochiKit.Position = { |
michael@0 | 89 | // set to true if needed, warning: firefox performance problems |
michael@0 | 90 | // NOT neeeded for page scrolling, only if draggable contained in |
michael@0 | 91 | // scrollable elements |
michael@0 | 92 | includeScrollOffsets: false, |
michael@0 | 93 | |
michael@0 | 94 | /** @id MochiKit.Position.prepare */ |
michael@0 | 95 | prepare: function () { |
michael@0 | 96 | var deltaX = window.pageXOffset |
michael@0 | 97 | || document.documentElement.scrollLeft |
michael@0 | 98 | || document.body.scrollLeft |
michael@0 | 99 | || 0; |
michael@0 | 100 | var deltaY = window.pageYOffset |
michael@0 | 101 | || document.documentElement.scrollTop |
michael@0 | 102 | || document.body.scrollTop |
michael@0 | 103 | || 0; |
michael@0 | 104 | this.windowOffset = new MochiKit.Style.Coordinates(deltaX, deltaY); |
michael@0 | 105 | }, |
michael@0 | 106 | |
michael@0 | 107 | /** @id MochiKit.Position.cumulativeOffset */ |
michael@0 | 108 | cumulativeOffset: function (element) { |
michael@0 | 109 | var valueT = 0; |
michael@0 | 110 | var valueL = 0; |
michael@0 | 111 | do { |
michael@0 | 112 | valueT += element.offsetTop || 0; |
michael@0 | 113 | valueL += element.offsetLeft || 0; |
michael@0 | 114 | element = element.offsetParent; |
michael@0 | 115 | } while (element); |
michael@0 | 116 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 117 | }, |
michael@0 | 118 | |
michael@0 | 119 | /** @id MochiKit.Position.realOffset */ |
michael@0 | 120 | realOffset: function (element) { |
michael@0 | 121 | var valueT = 0; |
michael@0 | 122 | var valueL = 0; |
michael@0 | 123 | do { |
michael@0 | 124 | valueT += element.scrollTop || 0; |
michael@0 | 125 | valueL += element.scrollLeft || 0; |
michael@0 | 126 | element = element.parentNode; |
michael@0 | 127 | } while (element); |
michael@0 | 128 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 129 | }, |
michael@0 | 130 | |
michael@0 | 131 | /** @id MochiKit.Position.within */ |
michael@0 | 132 | within: function (element, x, y) { |
michael@0 | 133 | if (this.includeScrollOffsets) { |
michael@0 | 134 | return this.withinIncludingScrolloffsets(element, x, y); |
michael@0 | 135 | } |
michael@0 | 136 | this.xcomp = x; |
michael@0 | 137 | this.ycomp = y; |
michael@0 | 138 | this.offset = this.cumulativeOffset(element); |
michael@0 | 139 | if (element.style.position == "fixed") { |
michael@0 | 140 | this.offset.x += this.windowOffset.x; |
michael@0 | 141 | this.offset.y += this.windowOffset.y; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | return (y >= this.offset.y && |
michael@0 | 145 | y < this.offset.y + element.offsetHeight && |
michael@0 | 146 | x >= this.offset.x && |
michael@0 | 147 | x < this.offset.x + element.offsetWidth); |
michael@0 | 148 | }, |
michael@0 | 149 | |
michael@0 | 150 | /** @id MochiKit.Position.withinIncludingScrolloffsets */ |
michael@0 | 151 | withinIncludingScrolloffsets: function (element, x, y) { |
michael@0 | 152 | var offsetcache = this.realOffset(element); |
michael@0 | 153 | |
michael@0 | 154 | this.xcomp = x + offsetcache.x - this.windowOffset.x; |
michael@0 | 155 | this.ycomp = y + offsetcache.y - this.windowOffset.y; |
michael@0 | 156 | this.offset = this.cumulativeOffset(element); |
michael@0 | 157 | |
michael@0 | 158 | return (this.ycomp >= this.offset.y && |
michael@0 | 159 | this.ycomp < this.offset.y + element.offsetHeight && |
michael@0 | 160 | this.xcomp >= this.offset.x && |
michael@0 | 161 | this.xcomp < this.offset.x + element.offsetWidth); |
michael@0 | 162 | }, |
michael@0 | 163 | |
michael@0 | 164 | // within must be called directly before |
michael@0 | 165 | /** @id MochiKit.Position.overlap */ |
michael@0 | 166 | overlap: function (mode, element) { |
michael@0 | 167 | if (!mode) { |
michael@0 | 168 | return 0; |
michael@0 | 169 | } |
michael@0 | 170 | if (mode == 'vertical') { |
michael@0 | 171 | return ((this.offset.y + element.offsetHeight) - this.ycomp) / |
michael@0 | 172 | element.offsetHeight; |
michael@0 | 173 | } |
michael@0 | 174 | if (mode == 'horizontal') { |
michael@0 | 175 | return ((this.offset.x + element.offsetWidth) - this.xcomp) / |
michael@0 | 176 | element.offsetWidth; |
michael@0 | 177 | } |
michael@0 | 178 | }, |
michael@0 | 179 | |
michael@0 | 180 | /** @id MochiKit.Position.absolutize */ |
michael@0 | 181 | absolutize: function (element) { |
michael@0 | 182 | element = MochiKit.DOM.getElement(element); |
michael@0 | 183 | if (element.style.position == 'absolute') { |
michael@0 | 184 | return; |
michael@0 | 185 | } |
michael@0 | 186 | MochiKit.Position.prepare(); |
michael@0 | 187 | |
michael@0 | 188 | var offsets = MochiKit.Position.positionedOffset(element); |
michael@0 | 189 | var width = element.clientWidth; |
michael@0 | 190 | var height = element.clientHeight; |
michael@0 | 191 | |
michael@0 | 192 | var oldStyle = { |
michael@0 | 193 | 'position': element.style.position, |
michael@0 | 194 | 'left': offsets.x - parseFloat(element.style.left || 0), |
michael@0 | 195 | 'top': offsets.y - parseFloat(element.style.top || 0), |
michael@0 | 196 | 'width': element.style.width, |
michael@0 | 197 | 'height': element.style.height |
michael@0 | 198 | }; |
michael@0 | 199 | |
michael@0 | 200 | element.style.position = 'absolute'; |
michael@0 | 201 | element.style.top = offsets.y + 'px'; |
michael@0 | 202 | element.style.left = offsets.x + 'px'; |
michael@0 | 203 | element.style.width = width + 'px'; |
michael@0 | 204 | element.style.height = height + 'px'; |
michael@0 | 205 | |
michael@0 | 206 | return oldStyle; |
michael@0 | 207 | }, |
michael@0 | 208 | |
michael@0 | 209 | /** @id MochiKit.Position.positionedOffset */ |
michael@0 | 210 | positionedOffset: function (element) { |
michael@0 | 211 | var valueT = 0, valueL = 0; |
michael@0 | 212 | do { |
michael@0 | 213 | valueT += element.offsetTop || 0; |
michael@0 | 214 | valueL += element.offsetLeft || 0; |
michael@0 | 215 | element = element.offsetParent; |
michael@0 | 216 | if (element) { |
michael@0 | 217 | p = MochiKit.Style.getStyle(element, 'position'); |
michael@0 | 218 | if (p == 'relative' || p == 'absolute') { |
michael@0 | 219 | break; |
michael@0 | 220 | } |
michael@0 | 221 | } |
michael@0 | 222 | } while (element); |
michael@0 | 223 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 224 | }, |
michael@0 | 225 | |
michael@0 | 226 | /** @id MochiKit.Position.relativize */ |
michael@0 | 227 | relativize: function (element, oldPos) { |
michael@0 | 228 | element = MochiKit.DOM.getElement(element); |
michael@0 | 229 | if (element.style.position == 'relative') { |
michael@0 | 230 | return; |
michael@0 | 231 | } |
michael@0 | 232 | MochiKit.Position.prepare(); |
michael@0 | 233 | |
michael@0 | 234 | var top = parseFloat(element.style.top || 0) - |
michael@0 | 235 | (oldPos['top'] || 0); |
michael@0 | 236 | var left = parseFloat(element.style.left || 0) - |
michael@0 | 237 | (oldPos['left'] || 0); |
michael@0 | 238 | |
michael@0 | 239 | element.style.position = oldPos['position']; |
michael@0 | 240 | element.style.top = top + 'px'; |
michael@0 | 241 | element.style.left = left + 'px'; |
michael@0 | 242 | element.style.width = oldPos['width']; |
michael@0 | 243 | element.style.height = oldPos['height']; |
michael@0 | 244 | }, |
michael@0 | 245 | |
michael@0 | 246 | /** @id MochiKit.Position.clone */ |
michael@0 | 247 | clone: function (source, target) { |
michael@0 | 248 | source = MochiKit.DOM.getElement(source); |
michael@0 | 249 | target = MochiKit.DOM.getElement(target); |
michael@0 | 250 | target.style.position = 'absolute'; |
michael@0 | 251 | var offsets = this.cumulativeOffset(source); |
michael@0 | 252 | target.style.top = offsets.y + 'px'; |
michael@0 | 253 | target.style.left = offsets.x + 'px'; |
michael@0 | 254 | target.style.width = source.offsetWidth + 'px'; |
michael@0 | 255 | target.style.height = source.offsetHeight + 'px'; |
michael@0 | 256 | }, |
michael@0 | 257 | |
michael@0 | 258 | /** @id MochiKit.Position.page */ |
michael@0 | 259 | page: function (forElement) { |
michael@0 | 260 | var valueT = 0; |
michael@0 | 261 | var valueL = 0; |
michael@0 | 262 | |
michael@0 | 263 | var element = forElement; |
michael@0 | 264 | do { |
michael@0 | 265 | valueT += element.offsetTop || 0; |
michael@0 | 266 | valueL += element.offsetLeft || 0; |
michael@0 | 267 | |
michael@0 | 268 | // Safari fix |
michael@0 | 269 | if (element.offsetParent == document.body && MochiKit.Style.getStyle(element, 'position') == 'absolute') { |
michael@0 | 270 | break; |
michael@0 | 271 | } |
michael@0 | 272 | } while (element = element.offsetParent); |
michael@0 | 273 | |
michael@0 | 274 | element = forElement; |
michael@0 | 275 | do { |
michael@0 | 276 | valueT -= element.scrollTop || 0; |
michael@0 | 277 | valueL -= element.scrollLeft || 0; |
michael@0 | 278 | } while (element = element.parentNode); |
michael@0 | 279 | |
michael@0 | 280 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 281 | } |
michael@0 | 282 | }; |
michael@0 | 283 |