Skip to content

Commit

Permalink
Remove deprecated methods from Element.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Nov 8, 2011
1 parent 5db084a commit dd5d7c9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 117 deletions.
75 changes: 0 additions & 75 deletions lib/OpenLayers/BaseTypes/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,6 @@ OpenLayers.Element = {
}
},


/**
* APIFunction: hide
* *Deprecated*. Hide element(s) passed in
*
* Parameters:
* element - {DOMElement} Actually user can pass any number of elements
*/
hide: function() {
OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
newMethod: "element.style.display = 'none';"
}));

for (var i=0, len=arguments.length; i<len; i++) {
var element = OpenLayers.Util.getElement(arguments[i]);
if (element) {
element.style.display = 'none';
}
}
},

/**
* APIFunction: show
* *Deprecated*. Show element(s) passed in
*
* Parameters:
* element - {DOMElement} Actually user can pass any number of elements
*/
show: function() {
OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
newMethod: "element.style.display = '';"
}));

for (var i=0, len=arguments.length; i<len; i++) {
var element = OpenLayers.Util.getElement(arguments[i]);
if (element) {
element.style.display = '';
}
}
},

/**
* APIFunction: remove
* Remove the specified element from the DOM.
Expand All @@ -109,40 +68,6 @@ OpenLayers.Element = {
return element.offsetHeight;
},

/**
* APIFunction: getDimensions
* *Deprecated*. Returns dimensions of the element passed in.
*
* Parameters:
* element - {DOMElement}
*
* Returns:
* {Object} Object with 'width' and 'height' properties which are the
* dimensions of the element passed in.
*/
getDimensions: function(element) {
element = OpenLayers.Util.getElement(element);
if (OpenLayers.Element.getStyle(element, 'display') != 'none') {
return {width: element.offsetWidth, height: element.offsetHeight};
}

// All *Width and *Height properties give 0 on elements with display none,
// so enable the element temporarily
var els = element.style;
var originalVisibility = els.visibility;
var originalPosition = els.position;
var originalDisplay = els.display;
els.visibility = 'hidden';
els.position = 'absolute';
els.display = '';
var originalWidth = element.clientWidth;
var originalHeight = element.clientHeight;
els.display = originalDisplay;
els.position = originalPosition;
els.visibility = originalVisibility;
return {width: originalWidth, height: originalHeight};
},

/**
* Function: hasClass
* Tests if an element has the given CSS class name.
Expand Down
85 changes: 85 additions & 0 deletions lib/deprecated.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Namespace: OpenLayers.Class
*/

/**
* Property: isPrototype
* *Deprecated*. This is no longer needed and will be removed at 3.0.
Expand Down Expand Up @@ -681,3 +685,84 @@ OpenLayers.Ajax.serializeXMLToString = function(xmldom) {
var data = serializer.serializeToString(xmldom);
return data;
};

/**
* Namespace: OpenLayers.Element
*/
OpenLayers.Util.extend(OpenLayers.Element, {

/**
* APIFunction: hide
* *Deprecated*. Hide element(s) passed in
*
* Parameters:
* element - {DOMElement} Actually user can pass any number of elements
*/
hide: function() {
OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
newMethod: "element.style.display = 'none';"
}));

for (var i=0, len=arguments.length; i<len; i++) {
var element = OpenLayers.Util.getElement(arguments[i]);
if (element) {
element.style.display = 'none';
}
}
},

/**
* APIFunction: show
* *Deprecated*. Show element(s) passed in
*
* Parameters:
* element - {DOMElement} Actually user can pass any number of elements
*/
show: function() {
OpenLayers.Console.warn(OpenLayers.i18n("methodDeprecated", {
newMethod: "element.style.display = '';"
}));

for (var i=0, len=arguments.length; i<len; i++) {
var element = OpenLayers.Util.getElement(arguments[i]);
if (element) {
element.style.display = '';
}
}
},

/**
* APIFunction: getDimensions
* *Deprecated*. Returns dimensions of the element passed in.
*
* Parameters:
* element - {DOMElement}
*
* Returns:
* {Object} Object with 'width' and 'height' properties which are the
* dimensions of the element passed in.
*/
getDimensions: function(element) {
element = OpenLayers.Util.getElement(element);
if (OpenLayers.Element.getStyle(element, 'display') != 'none') {
return {width: element.offsetWidth, height: element.offsetHeight};
}

// All *Width and *Height properties give 0 on elements with display none,
// so enable the element temporarily
var els = element.style;
var originalVisibility = els.visibility;
var originalPosition = els.position;
var originalDisplay = els.display;
els.visibility = 'hidden';
els.position = 'absolute';
els.display = '';
var originalWidth = element.clientWidth;
var originalHeight = element.clientHeight;
els.display = originalDisplay;
els.position = originalPosition;
els.visibility = originalVisibility;
return {width: originalWidth, height: originalHeight};
}

});
42 changes: 0 additions & 42 deletions tests/BaseTypes/Element.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,6 @@
t.eq(elem2.style.display, "none", "shown element toggled to hidden");
}

function test_Element_hide(t) {
t.plan(2);

var elem1 = {
style: {
'display': "none"
}
};

var elem2 = {
style: {
'display': ""
}
};

OpenLayers.Element.hide(elem1, elem2, "do-not-exists");

t.eq(elem1.style.display, "none", "hidden element stays hidden");
t.eq(elem2.style.display, "none", "shown element hidden");
}

function test_Element_show(t) {
t.plan(2);

var elem1 = {
style: {
'display': "none"
}
};

var elem2 = {
style: {
'display': ""
}
};

OpenLayers.Element.show(elem1, "do-not-exists", elem2);

t.eq(elem1.style.display, "", "hidden element shown");
t.eq(elem2.style.display, "", "shown element stays shown");
}

function test_Element_remove(t) {
t.plan(1);

Expand Down
56 changes: 56 additions & 0 deletions tests/deprecated/BaseTypes/Element.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<html>
<head>
<script src="../../OLLoader.js"></script>
<script src="../../../lib/deprecated.js"></script>

<script type="text/javascript">

function test_Element_hide(t) {
t.plan(2);

var elem1 = {
style: {
'display': "none"
}
};

var elem2 = {
style: {
'display': ""
}
};

OpenLayers.Element.hide(elem1, elem2, "do-not-exists");

t.eq(elem1.style.display, "none", "hidden element stays hidden");
t.eq(elem2.style.display, "none", "shown element hidden");
}

function test_Element_show(t) {
t.plan(2);

var elem1 = {
style: {
'display': "none"
}
};

var elem2 = {
style: {
'display': ""
}
};

OpenLayers.Element.show(elem1, "do-not-exists", elem2);

t.eq(elem1.style.display, "", "hidden element shown");
t.eq(elem2.style.display, "", "shown element stays shown");
}

</script>
</head>
<body>
<div id="elemID" style="width:50px; height:100px; background-color:red">test</div>
</body>
</html>

2 changes: 2 additions & 0 deletions tests/list-tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,6 @@
<li>Util.html</li>
<li>deprecated/Ajax.html</li>
<li>deprecated/BaseTypes/Class.html</li>
<li>deprecated/BaseTypes/Class.html</li>
<li>deprecated/BaseTypes/Element.html</li>
</ul>

0 comments on commit dd5d7c9

Please sign in to comment.