Permalink
Browse files

Maintain backward compatibility and fix misordered Element.undoAbsolu…

…tize & Element.undoRelativize calls.
  • Loading branch information...
1 parent c9a2d1a commit 0ae2caf56d44b6e2b7d1032c3d5d875f57551e9e @ZenCocoon committed Dec 17, 2010
Showing with 29 additions and 0 deletions.
  1. +11 −0 src/prototype/dom/layout.js
  2. +18 −0 test/unit/dom_test.js
View
11 src/prototype/dom/layout.js
@@ -1041,12 +1041,17 @@
* Turns `element` into an absolutely-positioned element _without_
* changing its position in the page layout.
*
+ * It also reverts back a previous [[Element.relativize]] call
+ * on this `element`.
+ *
* To revert back to `element`'s original position,
* use [[Element.undoAbsolutize]].
**/
function absolutize(element) {
element = $(element);
+ element.undoRelativize();
+
if (Element.getStyle(element, 'position') === 'absolute') {
return element;
}
@@ -1106,11 +1111,17 @@
* Turns `element` into a relatively-positioned element without changing
* its position in the page layout.
*
+ * It also reverts back a previous [[Element.absolutize]] call
+ * on this `element`.
+ *
* To revert back to `element`'s original position,
* use [[Element.undoRelativize]].
**/
function relativize(element) {
element = $(element);
+
+ element.undoAbsolutize();
+
if (Element.getStyle(element, 'position') === 'relative') {
return element;
}
View
18 test/unit/dom_test.js
@@ -1469,6 +1469,24 @@ new Test.Unit.Runner({
var element = $('position-untouched');
this.assertEqual(element, element.undoRelativize());
},
+
+ testAbsolutizeThenRelativize: function() {
+ var element = $('position-static');
+ element.absolutize();
+ element.relativize();
+ element.undoAbsolutize();
+ element.undoRelativize();
+ this.assertEqual('static', element.getStyle('position'));
+ },
+
+ testRelativizeThenAbsolutize: function() {
+ var element = $('position-static');
+ element.relativize();
+ element.absolutize();
+ element.undoRelativize();
+ element.undoAbsolutize();
+ this.assertEqual('static', element.getStyle('position'));
+ },
testViewportDimensions: function() {
preservingBrowserDimensions(function() {

0 comments on commit 0ae2caf

Please sign in to comment.