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 | |
michael@0 | 3 | MochiKit.Position 1.4.2 |
michael@0 | 4 | |
michael@0 | 5 | See <http://mochikit.com/> for documentation, downloads, license, etc. |
michael@0 | 6 | |
michael@0 | 7 | (c) 2005-2006 Bob Ippolito and others. All rights Reserved. |
michael@0 | 8 | |
michael@0 | 9 | ***/ |
michael@0 | 10 | |
michael@0 | 11 | MochiKit.Base._deps('Position', ['Base', 'DOM', 'Style']); |
michael@0 | 12 | |
michael@0 | 13 | MochiKit.Position.NAME = 'MochiKit.Position'; |
michael@0 | 14 | MochiKit.Position.VERSION = '1.4.2'; |
michael@0 | 15 | MochiKit.Position.__repr__ = function () { |
michael@0 | 16 | return '[' + this.NAME + ' ' + this.VERSION + ']'; |
michael@0 | 17 | }; |
michael@0 | 18 | MochiKit.Position.toString = function () { |
michael@0 | 19 | return this.__repr__(); |
michael@0 | 20 | }; |
michael@0 | 21 | |
michael@0 | 22 | MochiKit.Position.EXPORT_OK = []; |
michael@0 | 23 | |
michael@0 | 24 | MochiKit.Position.EXPORT = [ |
michael@0 | 25 | ]; |
michael@0 | 26 | |
michael@0 | 27 | |
michael@0 | 28 | MochiKit.Base.update(MochiKit.Position, { |
michael@0 | 29 | // set to true if needed, warning: firefox performance problems |
michael@0 | 30 | // NOT neeeded for page scrolling, only if draggable contained in |
michael@0 | 31 | // scrollable elements |
michael@0 | 32 | includeScrollOffsets: false, |
michael@0 | 33 | |
michael@0 | 34 | /** @id MochiKit.Position.prepare */ |
michael@0 | 35 | prepare: function () { |
michael@0 | 36 | var deltaX = window.pageXOffset |
michael@0 | 37 | || document.documentElement.scrollLeft |
michael@0 | 38 | || document.body.scrollLeft |
michael@0 | 39 | || 0; |
michael@0 | 40 | var deltaY = window.pageYOffset |
michael@0 | 41 | || document.documentElement.scrollTop |
michael@0 | 42 | || document.body.scrollTop |
michael@0 | 43 | || 0; |
michael@0 | 44 | this.windowOffset = new MochiKit.Style.Coordinates(deltaX, deltaY); |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | /** @id MochiKit.Position.cumulativeOffset */ |
michael@0 | 48 | cumulativeOffset: function (element) { |
michael@0 | 49 | var valueT = 0; |
michael@0 | 50 | var valueL = 0; |
michael@0 | 51 | do { |
michael@0 | 52 | valueT += element.offsetTop || 0; |
michael@0 | 53 | valueL += element.offsetLeft || 0; |
michael@0 | 54 | element = element.offsetParent; |
michael@0 | 55 | } while (element); |
michael@0 | 56 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | /** @id MochiKit.Position.realOffset */ |
michael@0 | 60 | realOffset: function (element) { |
michael@0 | 61 | var valueT = 0; |
michael@0 | 62 | var valueL = 0; |
michael@0 | 63 | do { |
michael@0 | 64 | valueT += element.scrollTop || 0; |
michael@0 | 65 | valueL += element.scrollLeft || 0; |
michael@0 | 66 | element = element.parentNode; |
michael@0 | 67 | } while (element); |
michael@0 | 68 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 69 | }, |
michael@0 | 70 | |
michael@0 | 71 | /** @id MochiKit.Position.within */ |
michael@0 | 72 | within: function (element, x, y) { |
michael@0 | 73 | if (this.includeScrollOffsets) { |
michael@0 | 74 | return this.withinIncludingScrolloffsets(element, x, y); |
michael@0 | 75 | } |
michael@0 | 76 | this.xcomp = x; |
michael@0 | 77 | this.ycomp = y; |
michael@0 | 78 | this.offset = this.cumulativeOffset(element); |
michael@0 | 79 | if (element.style.position == "fixed") { |
michael@0 | 80 | this.offset.x += this.windowOffset.x; |
michael@0 | 81 | this.offset.y += this.windowOffset.y; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | return (y >= this.offset.y && |
michael@0 | 85 | y < this.offset.y + element.offsetHeight && |
michael@0 | 86 | x >= this.offset.x && |
michael@0 | 87 | x < this.offset.x + element.offsetWidth); |
michael@0 | 88 | }, |
michael@0 | 89 | |
michael@0 | 90 | /** @id MochiKit.Position.withinIncludingScrolloffsets */ |
michael@0 | 91 | withinIncludingScrolloffsets: function (element, x, y) { |
michael@0 | 92 | var offsetcache = this.realOffset(element); |
michael@0 | 93 | |
michael@0 | 94 | this.xcomp = x + offsetcache.x - this.windowOffset.x; |
michael@0 | 95 | this.ycomp = y + offsetcache.y - this.windowOffset.y; |
michael@0 | 96 | this.offset = this.cumulativeOffset(element); |
michael@0 | 97 | |
michael@0 | 98 | return (this.ycomp >= this.offset.y && |
michael@0 | 99 | this.ycomp < this.offset.y + element.offsetHeight && |
michael@0 | 100 | this.xcomp >= this.offset.x && |
michael@0 | 101 | this.xcomp < this.offset.x + element.offsetWidth); |
michael@0 | 102 | }, |
michael@0 | 103 | |
michael@0 | 104 | // within must be called directly before |
michael@0 | 105 | /** @id MochiKit.Position.overlap */ |
michael@0 | 106 | overlap: function (mode, element) { |
michael@0 | 107 | if (!mode) { |
michael@0 | 108 | return 0; |
michael@0 | 109 | } |
michael@0 | 110 | if (mode == 'vertical') { |
michael@0 | 111 | return ((this.offset.y + element.offsetHeight) - this.ycomp) / |
michael@0 | 112 | element.offsetHeight; |
michael@0 | 113 | } |
michael@0 | 114 | if (mode == 'horizontal') { |
michael@0 | 115 | return ((this.offset.x + element.offsetWidth) - this.xcomp) / |
michael@0 | 116 | element.offsetWidth; |
michael@0 | 117 | } |
michael@0 | 118 | }, |
michael@0 | 119 | |
michael@0 | 120 | /** @id MochiKit.Position.absolutize */ |
michael@0 | 121 | absolutize: function (element) { |
michael@0 | 122 | element = MochiKit.DOM.getElement(element); |
michael@0 | 123 | if (element.style.position == 'absolute') { |
michael@0 | 124 | return; |
michael@0 | 125 | } |
michael@0 | 126 | MochiKit.Position.prepare(); |
michael@0 | 127 | |
michael@0 | 128 | var offsets = MochiKit.Position.positionedOffset(element); |
michael@0 | 129 | var width = element.clientWidth; |
michael@0 | 130 | var height = element.clientHeight; |
michael@0 | 131 | |
michael@0 | 132 | var oldStyle = { |
michael@0 | 133 | 'position': element.style.position, |
michael@0 | 134 | 'left': offsets.x - parseFloat(element.style.left || 0), |
michael@0 | 135 | 'top': offsets.y - parseFloat(element.style.top || 0), |
michael@0 | 136 | 'width': element.style.width, |
michael@0 | 137 | 'height': element.style.height |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | element.style.position = 'absolute'; |
michael@0 | 141 | element.style.top = offsets.y + 'px'; |
michael@0 | 142 | element.style.left = offsets.x + 'px'; |
michael@0 | 143 | element.style.width = width + 'px'; |
michael@0 | 144 | element.style.height = height + 'px'; |
michael@0 | 145 | |
michael@0 | 146 | return oldStyle; |
michael@0 | 147 | }, |
michael@0 | 148 | |
michael@0 | 149 | /** @id MochiKit.Position.positionedOffset */ |
michael@0 | 150 | positionedOffset: function (element) { |
michael@0 | 151 | var valueT = 0, valueL = 0; |
michael@0 | 152 | do { |
michael@0 | 153 | valueT += element.offsetTop || 0; |
michael@0 | 154 | valueL += element.offsetLeft || 0; |
michael@0 | 155 | element = element.offsetParent; |
michael@0 | 156 | if (element) { |
michael@0 | 157 | p = MochiKit.Style.getStyle(element, 'position'); |
michael@0 | 158 | if (p == 'relative' || p == 'absolute') { |
michael@0 | 159 | break; |
michael@0 | 160 | } |
michael@0 | 161 | } |
michael@0 | 162 | } while (element); |
michael@0 | 163 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 164 | }, |
michael@0 | 165 | |
michael@0 | 166 | /** @id MochiKit.Position.relativize */ |
michael@0 | 167 | relativize: function (element, oldPos) { |
michael@0 | 168 | element = MochiKit.DOM.getElement(element); |
michael@0 | 169 | if (element.style.position == 'relative') { |
michael@0 | 170 | return; |
michael@0 | 171 | } |
michael@0 | 172 | MochiKit.Position.prepare(); |
michael@0 | 173 | |
michael@0 | 174 | var top = parseFloat(element.style.top || 0) - |
michael@0 | 175 | (oldPos['top'] || 0); |
michael@0 | 176 | var left = parseFloat(element.style.left || 0) - |
michael@0 | 177 | (oldPos['left'] || 0); |
michael@0 | 178 | |
michael@0 | 179 | element.style.position = oldPos['position']; |
michael@0 | 180 | element.style.top = top + 'px'; |
michael@0 | 181 | element.style.left = left + 'px'; |
michael@0 | 182 | element.style.width = oldPos['width']; |
michael@0 | 183 | element.style.height = oldPos['height']; |
michael@0 | 184 | }, |
michael@0 | 185 | |
michael@0 | 186 | /** @id MochiKit.Position.clone */ |
michael@0 | 187 | clone: function (source, target) { |
michael@0 | 188 | source = MochiKit.DOM.getElement(source); |
michael@0 | 189 | target = MochiKit.DOM.getElement(target); |
michael@0 | 190 | target.style.position = 'absolute'; |
michael@0 | 191 | var offsets = this.cumulativeOffset(source); |
michael@0 | 192 | target.style.top = offsets.y + 'px'; |
michael@0 | 193 | target.style.left = offsets.x + 'px'; |
michael@0 | 194 | target.style.width = source.offsetWidth + 'px'; |
michael@0 | 195 | target.style.height = source.offsetHeight + 'px'; |
michael@0 | 196 | }, |
michael@0 | 197 | |
michael@0 | 198 | /** @id MochiKit.Position.page */ |
michael@0 | 199 | page: function (forElement) { |
michael@0 | 200 | var valueT = 0; |
michael@0 | 201 | var valueL = 0; |
michael@0 | 202 | |
michael@0 | 203 | var element = forElement; |
michael@0 | 204 | do { |
michael@0 | 205 | valueT += element.offsetTop || 0; |
michael@0 | 206 | valueL += element.offsetLeft || 0; |
michael@0 | 207 | |
michael@0 | 208 | // Safari fix |
michael@0 | 209 | if (element.offsetParent == document.body && MochiKit.Style.getStyle(element, 'position') == 'absolute') { |
michael@0 | 210 | break; |
michael@0 | 211 | } |
michael@0 | 212 | } while (element = element.offsetParent); |
michael@0 | 213 | |
michael@0 | 214 | element = forElement; |
michael@0 | 215 | do { |
michael@0 | 216 | valueT -= element.scrollTop || 0; |
michael@0 | 217 | valueL -= element.scrollLeft || 0; |
michael@0 | 218 | } while (element = element.parentNode); |
michael@0 | 219 | |
michael@0 | 220 | return new MochiKit.Style.Coordinates(valueL, valueT); |
michael@0 | 221 | } |
michael@0 | 222 | }); |
michael@0 | 223 | |
michael@0 | 224 | MochiKit.Position.__new__ = function (win) { |
michael@0 | 225 | var m = MochiKit.Base; |
michael@0 | 226 | this.EXPORT_TAGS = { |
michael@0 | 227 | ':common': this.EXPORT, |
michael@0 | 228 | ':all': m.concat(this.EXPORT, this.EXPORT_OK) |
michael@0 | 229 | }; |
michael@0 | 230 | |
michael@0 | 231 | m.nameFunctions(this); |
michael@0 | 232 | }; |
michael@0 | 233 | |
michael@0 | 234 | MochiKit.Position.__new__(this); |
michael@0 | 235 | |
michael@0 | 236 | MochiKit.Base._exportSymbols(this, MochiKit.Position); |