remove useless or duplicate functions from Util.js -- no more: Array prepend() append() -- use push() and unshift(). clear() and indexOf() both removed as they are duplicated in Prototype.js -- all instances replaced and tests updated.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1136 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -163,7 +163,7 @@ OpenLayers.Control.LayerTabs.prototype =
|
|||||||
// add label to div
|
// add label to div
|
||||||
backdropLabelOuter.appendChild(backdropLabel);
|
backdropLabelOuter.appendChild(backdropLabel);
|
||||||
|
|
||||||
this.backdrops.append(backdropLabel);
|
this.backdrops.push(backdropLabel);
|
||||||
|
|
||||||
// add div to main LayerTabs Div
|
// add div to main LayerTabs Div
|
||||||
this.div.appendChild(backdropLabelOuter);
|
this.div.appendChild(backdropLabelOuter);
|
||||||
|
|||||||
@@ -154,11 +154,11 @@ OpenLayers.Control.MouseToolbar.prototype =
|
|||||||
this.measureBoxDistance.innerHTML = distance;
|
this.measureBoxDistance.innerHTML = distance;
|
||||||
this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
this.measureBoxDistance.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
||||||
this.map.layerContainerDiv.appendChild(this.measureBoxDistance);
|
this.map.layerContainerDiv.appendChild(this.measureBoxDistance);
|
||||||
this.measureDivs.append(this.measureBoxDistance);
|
this.measureDivs.push(this.measureBoxDistance);
|
||||||
}
|
}
|
||||||
this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
this.measureBox.style.zIndex = this.map.Z_INDEX_BASE["Popup"] - 1;
|
||||||
this.map.layerContainerDiv.appendChild(this.measureBox);
|
this.map.layerContainerDiv.appendChild(this.measureBox);
|
||||||
this.measureDivs.append(this.measureBox);
|
this.measureDivs.push(this.measureBox);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.map.div.style.cursor = "move";
|
this.map.div.style.cursor = "move";
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ OpenLayers.Layer.GeoRSS.prototype =
|
|||||||
//data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
|
//data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
|
||||||
}
|
}
|
||||||
var feature = new OpenLayers.Feature(this, location, data);
|
var feature = new OpenLayers.Feature(this, location, data);
|
||||||
this.features.append(feature);
|
this.features.push(feature);
|
||||||
var marker = feature.createMarker();
|
var marker = feature.createMarker();
|
||||||
marker.events.register('click', feature, this.markerClick);
|
marker.events.register('click', feature, this.markerClick);
|
||||||
this.addMarker(marker);
|
this.addMarker(marker);
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
var row = new Array();
|
var row = new Array();
|
||||||
this.grid.append(row);
|
this.grid.push(row);
|
||||||
tileoffsetlon = startLon;
|
tileoffsetlon = startLon;
|
||||||
tileoffsetx = startX;
|
tileoffsetx = startX;
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
var tile = this.addTile(tileBounds, px);
|
var tile = this.addTile(tileBounds, px);
|
||||||
|
|
||||||
tile.draw(this.alpha);
|
tile.draw(this.alpha);
|
||||||
row.append(tile);
|
row.push(tile);
|
||||||
|
|
||||||
tileoffsetlon += tilelon;
|
tileoffsetlon += tilelon;
|
||||||
tileoffsetx += this.tileSize.w;
|
tileoffsetx += this.tileSize.w;
|
||||||
@@ -395,14 +395,14 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
position.y = position.y + deltaY;
|
position.y = position.y + deltaY;
|
||||||
var newTile = this.addTile(bounds, position);
|
var newTile = this.addTile(bounds, position);
|
||||||
newTile.draw(this.alpha);
|
newTile.draw(this.alpha);
|
||||||
newRow.append(newTile);
|
newRow.push(newTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newRow.length>0){
|
if (newRow.length>0){
|
||||||
if (prepend) {
|
if (prepend) {
|
||||||
this.grid.prepend(newRow);
|
this.grid.unshift(newRow);
|
||||||
} else {
|
} else {
|
||||||
this.grid.append(newRow);
|
this.grid.push(newRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -433,9 +433,9 @@ OpenLayers.Layer.Grid.prototype =
|
|||||||
newTile.draw(this.alpha);
|
newTile.draw(this.alpha);
|
||||||
|
|
||||||
if (prepend) {
|
if (prepend) {
|
||||||
row = row.prepend(newTile);
|
row = row.unshift(newTile);
|
||||||
} else {
|
} else {
|
||||||
row = row.append(newTile);
|
row = row.push(newTile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ OpenLayers.Layer.KaMap.prototype =
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
var row = new Array();
|
var row = new Array();
|
||||||
this.grid.append(row);
|
this.grid.push(row);
|
||||||
tileoffsetlon = startLon;
|
tileoffsetlon = startLon;
|
||||||
tileoffsetx = startX;
|
tileoffsetx = startX;
|
||||||
do {
|
do {
|
||||||
@@ -113,7 +113,7 @@ OpenLayers.Layer.KaMap.prototype =
|
|||||||
tileoffsety - parseInt(this.map.layerContainerDiv.style.top))
|
tileoffsety - parseInt(this.map.layerContainerDiv.style.top))
|
||||||
);
|
);
|
||||||
tile.draw((this.alpha));
|
tile.draw((this.alpha));
|
||||||
row.append(tile);
|
row.push(tile);
|
||||||
|
|
||||||
tileoffsetlon += tilelon;
|
tileoffsetlon += tilelon;
|
||||||
tileoffsetx += this.tileSize.w;
|
tileoffsetx += this.tileSize.w;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ OpenLayers.Layer.Markers.prototype =
|
|||||||
* @param {OpenLayers.Marker} marker
|
* @param {OpenLayers.Marker} marker
|
||||||
*/
|
*/
|
||||||
addMarker: function(marker) {
|
addMarker: function(marker) {
|
||||||
this.markers.append(marker);
|
this.markers.push(marker);
|
||||||
if (this.map && this.map.getExtent()) {
|
if (this.map && this.map.getExtent()) {
|
||||||
marker.map = this.map;
|
marker.map = this.map;
|
||||||
this.drawMarker(marker);
|
this.drawMarker(marker);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ OpenLayers.Layer.Text.prototype =
|
|||||||
data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
|
data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
|
||||||
}
|
}
|
||||||
var feature = new OpenLayers.Feature(this, location, data);
|
var feature = new OpenLayers.Feature(this, location, data);
|
||||||
this.features.append(feature);
|
this.features.push(feature);
|
||||||
var marker = feature.createMarker();
|
var marker = feature.createMarker();
|
||||||
marker.events.register('click', feature, this.markerClick);
|
marker.events.register('click', feature, this.markerClick);
|
||||||
this.addMarker(marker);
|
this.addMarker(marker);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ OpenLayers.Tile.WFS.prototype =
|
|||||||
|
|
||||||
var feature = new this.layer.featureClass(this.layer,
|
var feature = new this.layer.featureClass(this.layer,
|
||||||
results[i]);
|
results[i]);
|
||||||
this.features.append(feature);
|
this.features.push(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -670,42 +670,12 @@ Array.prototype.clone = function() {
|
|||||||
return clone;
|
return clone;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} item
|
|
||||||
*/
|
|
||||||
Array.prototype.prepend = function(item) {
|
|
||||||
this.splice(0, 0, item);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} item
|
|
||||||
*/
|
|
||||||
Array.prototype.append = function(item){
|
|
||||||
this[this.length] = item;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
Array.prototype.clear = function() {
|
Array.prototype.clear = function() {
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} element
|
|
||||||
*
|
|
||||||
* @returns The first index of the element in the array if found. Else returns -1
|
|
||||||
* @type int
|
|
||||||
*/
|
|
||||||
Array.prototype.indexOf = function(element) {
|
|
||||||
var index = -1;
|
|
||||||
for(var i=0; i < this.length; i++) {
|
|
||||||
if (this[i] == element) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** NOTE: Works only with integer values does *not* work with floats!
|
/** NOTE: Works only with integer values does *not* work with floats!
|
||||||
*
|
*
|
||||||
|
|||||||
+6
-16
@@ -30,32 +30,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_03_Util_Array(t) {
|
function test_03_Util_Array(t) {
|
||||||
t.plan( 8 );
|
t.plan( 5 );
|
||||||
|
|
||||||
var array = new Array(1,2,3,4,5);
|
var array = new Array(1,2,3,4,5);
|
||||||
|
|
||||||
array.prepend(0);
|
|
||||||
t.eq( array.toString(), "0,1,2,3,4,5", "array.prepend works");
|
|
||||||
|
|
||||||
array.append(6);
|
|
||||||
t.eq( array.toString(), "0,1,2,3,4,5,6", "array.append works");
|
|
||||||
|
|
||||||
array.remove(3);
|
array.remove(3);
|
||||||
t.eq( array.toString(), "0,1,2,4,5,6", "array.remove works");
|
t.eq( array.toString(), "1,2,4,5", "array.remove works");
|
||||||
|
|
||||||
copy = array.clone();
|
copy = array.clone();
|
||||||
t.eq( copy.toString(), "0,1,2,4,5,6", "array.clone() works");
|
t.eq( copy.toString(), "1,2,4,5", "array.clone() works");
|
||||||
array.append(7);
|
array.push(7);
|
||||||
t.eq( copy.toString(), "0,1,2,4,5,6", "changing a value in the copied array doesnt affect the new array");
|
t.eq( copy.toString(), "1,2,4,5", "changing a value in the copied array doesnt affect the new array");
|
||||||
|
|
||||||
|
|
||||||
t.eq( copy.indexOf(5), 4, "indexOf function returns index of value in an array");
|
t.eq( copy.indexOf(5), 3, "indexOf function returns index of value in an array");
|
||||||
t.eq( copy.indexOf(75), -1, "indexOf function returns -1 when element not found in array");
|
t.eq( copy.indexOf(75), -1, "indexOf function returns -1 when element not found in array");
|
||||||
|
|
||||||
array.clear();
|
|
||||||
t.eq( array.toString(), "", "array.clear() works");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_04_Util_createDiv(t) {
|
function test_04_Util_createDiv(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user