|
35 | 35 | },
|
36 | 36 | position: {
|
37 | 37 | getTop: function($elem) { return parseInt($elem.css('top'), 10) * -1; },
|
38 |
| - setTop: function($elem, val) { $elem.css('top', val); }, |
39 |
| - |
40 |
| - getLeft: function($elem) { return parseInt($elem.css('left'), 10) * -1; }, |
41 |
| - setLeft: function($elem, val) { $elem.css('left', val); } |
| 38 | + getLeft: function($elem) { return parseInt($elem.css('left'), 10) * -1; } |
42 | 39 | },
|
43 | 40 | margin: {
|
44 | 41 | getTop: function($elem) { return parseInt($elem.css('margin-top'), 10) * -1; },
|
45 |
| - setTop: function($elem, val) { $elem.css('margin-top', val); }, |
46 |
| - |
47 |
| - getLeft: function($elem) { return parseInt($elem.css('margin-left'), 10) * -1; }, |
48 |
| - setLeft: function($elem, val) { $elem.css('margin-left', val); } |
| 42 | + getLeft: function($elem) { return parseInt($elem.css('margin-left'), 10) * -1; } |
49 | 43 | },
|
50 | 44 | transform: {
|
51 |
| - getTop: function($elem) { return (getComputedStyle($elem[0])[transform] !== 'none' ? parseInt(getComputedStyle($elem[0])[transform].match(/(-?[0-9]+)/g)[5], 10) * -1 : 0); }, |
52 |
| - setTop: function($elem, val) { setTransform($elem, val, 'Y'); }, |
53 |
| - |
54 |
| - getLeft: function($elem) { return (getComputedStyle($elem[0])[transform] !== 'none' ? parseInt(getComputedStyle($elem[0])[transform].match(/(-?[0-9]+)/g)[4], 10) * -1 : 0); }, |
55 |
| - setLeft: function($elem, val) { setTransform($elem, val, 'X'); } |
| 45 | + getTop: function($elem) { |
| 46 | + var computedTransform = getComputedStyle($elem[0])[transform]; |
| 47 | + return computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[5], 10) * -1 : 0; |
| 48 | + }, |
| 49 | + getLeft: function($elem) { |
| 50 | + var computedTransform = getComputedStyle($elem[0])[transform]; |
| 51 | + return computedTransform !== 'none' ? parseInt(computedTransform.match(/(-?[0-9]+)/g)[4], 10) * -1 : 0; |
| 52 | + } |
56 | 53 | }
|
57 | 54 | },
|
58 | 55 |
|
|
119 | 116 | };
|
120 | 117 | }()),
|
121 | 118 |
|
122 |
| - setTransform = function($elem, val, dimension /* 'X' or 'Y' */) { |
123 |
| - var currentTransform = getComputedStyle($elem[0])[transform]; |
124 |
| - |
125 |
| - if (currentTransform === 'none') { |
126 |
| - $elem[0].style[transform] = 'translate' + dimension + '(' + val + 'px)'; |
127 |
| - } else { |
128 |
| - $elem[0].style[transform] = replaceNthOccurence(currentTransform, /(-?[0-9]+[.]?[0-9]*)/g, (dimension === 'X' ? 5 : 6), val); |
129 |
| - } |
130 |
| - }, |
131 |
| - |
132 |
| - replaceNthOccurence = function(original, pattern, n, replace) { |
133 |
| - var parts, |
134 |
| - tempParts, |
135 |
| - indexOfNthMatch; |
136 |
| - |
137 |
| - if (original.search(pattern) === -1) { |
138 |
| - return original; |
139 |
| - } |
140 |
| - |
141 |
| - parts = original.split(pattern); |
142 |
| - |
143 |
| - indexOfNthMatch = n * 2 - 1; |
144 |
| - |
145 |
| - if (parts[indexOfNthMatch] === undefined) { |
146 |
| - return original; |
147 |
| - } |
148 |
| - |
149 |
| - parts[indexOfNthMatch] = replace; |
150 |
| - |
151 |
| - return parts.join(''); |
152 |
| - }, |
153 |
| - |
154 | 119 | requestAnimFrame = (function(){
|
155 | 120 | return window.requestAnimationFrame ||
|
156 | 121 | window.webkitRequestAnimationFrame ||
|
|
209 | 174 | },
|
210 | 175 | _defineSetters: function() {
|
211 | 176 | var self = this,
|
212 |
| - positionPropertyAdapter = positionProperty[self.options.positionProperty]; |
| 177 | + scrollPropertyAdapter = scrollProperty[self.options.scrollProperty], |
| 178 | + positionPropertyAdapter = positionProperty[self.options.positionProperty], |
| 179 | + setScrollLeft = scrollPropertyAdapter.setLeft, |
| 180 | + setScrollTop = scrollPropertyAdapter.setTop; |
213 | 181 |
|
214 |
| - this._setScrollLeft = function(val) { |
215 |
| - scrollProperty[self.options.scrollProperty].setLeft(self.$scrollElement, val); |
216 |
| - }; |
| 182 | + this._setScrollLeft = typeof setScrollLeft === 'function' ? function(val) { |
| 183 | + setScrollLeft(self.$scrollElement, val); |
| 184 | + } : $.noop; |
217 | 185 |
|
218 |
| - this._setScrollTop = function(val) { |
219 |
| - scrollProperty[self.options.scrollProperty].setTop(self.$scrollElement, val); |
220 |
| - }; |
| 186 | + this._setScrollTop = typeof setScrollTop === 'function' ? function(val) { |
| 187 | + setScrollTop(self.$scrollElement, val); |
| 188 | + } : $.noop; |
221 | 189 |
|
222 | 190 | this._setPosition = positionPropertyAdapter.setPosition ||
|
223 | 191 | function($elem, left, startingLeft, top, startingTop) {
|
|
274 | 242 | });
|
275 | 243 | }
|
276 | 244 |
|
277 |
| - self._setScrollLeft(oldLeft); |
278 |
| - self._setScrollTop(oldTop); |
| 245 | + this._setScrollLeft(oldLeft); |
| 246 | + this._setScrollTop(oldTop); |
279 | 247 | },
|
280 | 248 | _detectViewport: function() {
|
281 | 249 | var viewportOffsets = this.$viewportElement.offset(),
|
|
0 commit comments