Changed around the order of arguments for createImage, createDiv, and createAlphaImage. bubbled out helper function OpenLayers.Util.modifyDOMElement() to handle common mods. Official order now is: id, px, sz, imgURL, position, border[, overflow]

git-svn-id: http://svn.openlayers.org/trunk/openlayers@384 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-26 01:23:11 +00:00
parent 0e7e831f0d
commit f115b797a3
10 changed files with 165 additions and 128 deletions

View File

@@ -570,103 +570,111 @@ Array.prototype.indexOf = function(element) {
return index;
}
/**
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} position
* @param {String} border
* @param {String} overflow
*/
OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position,
border, overflow) {
if (id) {
element.id = id;
}
if (px) {
element.style.left = px.x;
element.style.top = px.y;
}
if (sz) {
element.style.width = sz.w + "px";
element.style.height = sz.h + "px";
}
if (position) {
element.style.position = position;
}
if (border) {
element.style.border = border;
}
if (overflow) {
element.style.overflow = overflow;
}
};
/**
* zIndex is NOT set
*
* @param {String} id - HTML ID of new element, if empty something is made up
* @param {OpenLayers.Pixel} px - x,y point if missing 0,0 is used
* @param {OpenLayers.Size} sz - size else size of parent is used
* @param {String} overflow - behavior of clipped/overflow content
* @param {String} img - background image url
* @param {String} position - relative or absolute?
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
* @param {String} overflow
*
* @returns A DOM Div created with the specified attributes.
* @type DOMElement
*/
OpenLayers.Util.createDiv = function(id, px, sz, overflow, img, position) {
var x,y,w,h;
if (px) {
x = px.x;
y = px.y;
} else {
x = y = 0;
}
if (!position) {
position = "absolute";
}
if (!id) {
id = "OpenLayersDiv" + (Math.random() * 10000 % 10000);
}
OpenLayers.Util.createDiv = function(id, px, sz, imgURL, position,
border, overflow) {
var dom = document.createElement('div');
dom.id = id;
if (overflow) {
dom.style.overflow = overflow;
}
if (sz) {
dom.style.width = sz.w + "px";
dom.style.height = sz.h + "px";
}
dom.style.position = position;
dom.style.top = y;
dom.style.left = x;
//set specific properties
dom.style.padding = "0";
dom.style.margin = "0";
dom.style.cursor = "inherit";
if (img) {
dom.style.backgroundImage = 'url(' + img + ')';
if (imgURL) {
dom.style.backgroundImage = 'url(' + imgURL + ')';
}
//set generic properties
if (!id) {
id = "OpenLayersDiv" + (Math.random() * 10000 % 10000);
}
if (!position) {
position = "absolute";
}
OpenLayers.Util.modifyDOMElement(dom, id, px, sz,
position, border, overflow);
return dom;
};
/**
* @param {String} img - src URL
* @param {OpenLayers.Size} sz
* @param {OpenLayers.Pixel} xy
* @param {String} position
* @param {String} id
* @param {int} border
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
*
* @returns A DOM Image created with the specified attributes.
* @type DOMElement
*/
OpenLayers.Util.createImage = function(img, sz, xy, position, id, border) {
OpenLayers.Util.createImage = function(id, px, sz, imgURL, position, border) {
image = document.createElement("img");
if (id) {
image.id = id;
image.style.alt = id;
}
if (xy) {
image.style.left = xy.x;
image.style.top = xy.y;
}
if (sz) {
image.style.width = sz.w;
image.style.height = sz.h;
}
if (position) {
image.style.position = position;
} else {
image.style.position = "relative";
}
if (border) {
image.style.border = border + "px solid";
} else {
image.style.border = 0;
}
//set special properties
image.style.alt = id;
image.style.cursor = "inherit";
if (img) {
image.src = img;
}
image.galleryImg = "no";
if (imgURL) {
image.src = imgURL;
}
//set generic properties
if (!id) {
id = "OpenLayersDiv" + (Math.random() * 10000 % 10000);
}
if (!position) {
position = "relative";
}
OpenLayers.Util.modifyDOMElement(image, id, px, sz, position, border);
return image;
};
@@ -679,23 +687,23 @@ OpenLayers.Util.alphaHack = function() {
}
/**
* @param {String} imgURL
* @param {OpenLayers.Size} sz
* @param {OpenLayers.Pixel} px
* @param {String} position
* @param {String} id
* @param {int} border
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} sz
* @param {String} imgURL
* @param {String} position
* @param {String} border
*
* @returns A DOM Div created with a DOM Image inside it. If the hack is
* needed for transparency in IE, it is added.
* @type DOMElement
*/
OpenLayers.Util.createAlphaImageDiv = function(imgURL, sz, px, position,
id, border) {
OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
position, border) {
var div = OpenLayers.Util.createDiv(id, px, sz);
var img = OpenLayers.Util.createImage(imgURL, sz, null, "relative",
id + "_innerImage", border);
var img = OpenLayers.Util.createImage(id + "_innerImage", null, sz,
imgURL, "relative", border);
div.appendChild(img);
if (OpenLayers.Util.alphaHack()) {