/*
* === Cross Browser Class ===
* IE4, IE5, IE5.5, IE6, IE6sp2
* NN4.78, NS6, NS7
* Opera7
* Firefox1.0
*
* 2005/04/24 : JElement#toLaserElement()
*
* Mail : yunos@graviness.com
* Home : https://www.graviness.com/
*/
/**
* String id HTMLElementのID.
* Object layer HTMLElement.
* Object style HTMLElementのStyleオブジェクト.
* NNの場合,layerプロパティと同じ
*
*/
function class__JElement__(window) {
var classId = Object.getClassName(arguments.callee);
var document = window.document;
var BW = JClient.getInstance(window);
var nn = BW.nn;
var ie = BW.ie;
var gk = BW.gk;
var op = BW.op;
var dom = BW.dom;
var $listeners = Object.privateId();
/**
* エレメントを取得.
* HTMLElement getLayer(String id)
* @param id HTMLElementのid属性.name属性ではないことに注意.
* @return id
の付いたエレメントが
* 見つからないとき,null
.
*/
function getLayer(id) {
if (ie) {
var e = document.all[id];
return e !== void 0 ? e : null;
} else if (dom) {
return document.getElementById(id);
} else if (nn) {
var e = function(ls, id) {
for (var i = 0, n = ls.length; i < n; i++) {
if (ls[i].name == id) {
return ls[i];
} else if (ls[i].document.layers.length != 0) {
var l = arguments.callee(ls[i].document.layers, id);
if (l != null)
return l;
}
}
return null;
}(document.layers, id);
return e;
} else {
return null;
}
}
var user_create_element_number = 0;
/**
* JElement(String id)
* JElement(HTMLElement layer)
* JElement(JElement element)
*/
var F = window[classId] = function(p) {
if (this.constructor !== F)
this.constructor = F;
switch ((typeof p).charAt(0)) {
case 's' :
this.id = p;
this.layer = getLayer(this.id);
break;
case 'o' :
if (p === null)
break;
if (p.constructor === F) { // JElement
this.id = p.id;
this.layer = p.layer;
this.style = p.style;
return;
} else { // Layer
this.id = p.id !== void 0 ? p.id : p.name;
this.layer = p;
}
break;
}
if (Boolean(this.layer)) {
this.style =
this.layer.style !== void 0 ? this.layer.style : this.layer;
} else { // $ERROR$
window.errorMessage(""
+ "Error@" + classId + "\n\n"
+ "An element(id=[" + this.id + "]) can\'t be acquired.");
}
};
var FP = F.prototype;
F.zIndex = 0;
/**
* レイヤーの生成.
* ページ読み込み完了前はBODY要素にdocument.writeln
で追加,
* ページ読み込み完了後は動的にレイヤーを生成する.
* 生成されたレイヤー(JElement)は不可視の状態になっている.
*/
F.createInstance = function() {
var id = "_js_layer_" + user_create_element_number++;
var s = "position:absolute;"
+ ("left:0px;top:0px;z-index:" + F.zIndex + ";")
+ ("width:0px;height:0px;")
+ "visibility:hidden;";
if (window.isLoaded !== void 0 && window.isLoaded()) {
var layer = null;
if (ie) {
document.body.insertAdjacentHTML(
"BeforeEnd",
("
zIndex
)に設定.
*
* void setZ(int zIndex)
*/
FP.setZ = function(d) {
this.style.zIndex = d !== void 0 ? Math.round(d) : F.zIndex;
};
/**
* void setPosition(Point p)
* void setPosition(number x, number y)
*/
FP.setPosition = function() {
var l, t;
var a = arguments;
switch (a.length) {
case 1 :
l = a[0].x;
t = a[0].y;
break;
case 2 :
l = a[0];
t = a[1];
break;
default :
return;
}
if (ie || op) {
this.style.pixelLeft = l;
this.style.pixelTop = t;
} else if (dom) {
this.style.left = l + "px";
this.style.top = t + "px";
} else if (nn) {
this.layer.moveTo(l, t);
}
};
/**
* void setPoint(Point3 p);
* void setPoint(number x, number y, number z);
*/
FP.setPoint = function() {
var l, t, d;
var a = arguments;
switch (a.length) {
case 1 :
l = a[0].x;
t = a[0].y;
d = a[0].z;
break;
case 3 :
l = a[0];
t = a[1];
d = a[2];
break;
}
var s = this.style;
if (ie || op) {
s.pixelLeft = l;
s.pixelTop = t;
} else if (dom) {
s.left = l + "px";
s.top = t + "px";
} else if (nn) {
s.moveTo(l, t);
}
s.zIndex = Math.round(d);
};
/**
* int getX()
*/
FP.getX = function() {
if (ie || op)
return this.style.pixelLeft;
else if (dom)
return parseInt(this.style.left);
else if (nn)
return this.layer.left;
return 0;
};
/**
* int getY()
*/
FP.getY = function() {
if (ie || op)
return this.style.pixelTop;
else if (dom)
return parseInt(this.style.top);
else if (nn)
return this.layer.top;
return 0;
};
/**
* int getZ()
*/
FP.getZ = function() {
return parseInt(this.style.zIndex);
};
/**
* Point getPosition()
*/
FP.getPosition = function() {
if (ie || op)
return new Point(this.style.pixelLeft, this.style.pixelTop);
else if (dom)
return new Point(
parseInt(this.style.left), parseInt(this.style.top));
else if (nn)
return new Point(this.layer.left, this.layer.top);
return new Point();
};
/**
* Point3 getPoint()
*/
FP.getPoint = function() {
var s = this.style;
if (ie || op)
return new Point3(s.pixelLeft, s.pixelTop, parseInt(s.zIndex));
else if (dom)
return new Point3(parseInt(s.left), parseInt(s.top), parseInt(s.zIndex));
else if (nn)
return new Point3(s.left, s.top, s.zIndex);
return new Point3();
};
/**
* void moveForward(JElement e)
*/
FP.moveForward = function(e) {
this.setZ(e.getZ() + 1);
};
/**
* void moveBackward(JElement e)
*/
FP.moveBackward = function(e) {
this.setZ(e.getZ() - 1);
};
/**
* void initSize()
*/
FP.initSize = function() {
if (ie || op) {
this.style.pixelWidth = this.layer.offsetWidth;
this.style.pixelHeight = this.layer.offsetHeight;
} else if (dom) {
this.style.width = this.layer.offsetWidth + "px";
this.style.height = this.layer.offsetHeight + "px";
}
};
/**
* void setWidth(number w)
*/
FP.setWidth = function(w) {
if (ie || op)
this.style.pixelWidth = w;
else if (dom)
this.style.width = w + "px";
else if (nn)
this.layer.clip.width = w;
};
/**
* void setHeight(number h)
*/
FP.setHeight = function(h) {
if (ie || op)
this.style.pixelHeight = h;
else if (dom)
this.style.height = h + "px";
else if (nn)
this.layer.clip.height = h;
};
/**
* void setSize(Dimension size)
* void setSize(number w, number h)
*/
FP.setSize = function() {
var w, h;
var a = arguments;
switch (a.length) {
case 1 :
w = a[0].width;
h = a[0].height;
break;
case 2 :
w = a[0];
h = a[1];
break;
}
if (ie || op) {
this.style.pixelWidth = w;
this.style.pixelHeight = h;
} else if (dom) {
this.style.width = w + "px";
this.style.height = h + "px";
} else if (nn)
this.layer.resizeTo(w, h);
};
/**
* 幅の取得.
* int getWidth()
*
* int getWidth(boolean include)
* @param include 枠線等を含む幅を返す.
*/
FP.getWidth = function(b) {
if (b) {
if (this.layer.offsetWidth !== void 0)
return this.layer.offsetWidth;
else
return this.getWidth(false);
} else {
if (ie || op)
return this.style.pixelWidth;
else if (dom)
return parseInt(this.style.width);
else if (nn)
return this.layer.clip.width;
return 0;
}
};
/**
* 高さの取得.
* int getWidth()
*
* int getWidth(boolean include)
* @param include 枠線等を含む高さを返す.
*/
FP.getHeight = function(b) {
if (b) {
if (this.layer.offsetHeight !== void 0)
return this.layer.offsetHeight;
else
return this.getHeight(false);
} else {
if (ie || op)
return this.style.pixelHeight;
else if (dom)
return parseInt(this.style.height);
else if (nn)
return this.layer.clip.height;
return 0;
}
};
/**
* Dimension getSize(b)
*/
FP.getSize = function(b) {
if (b) {
if (this.layer.offsetWidth !== void 0)
return new Dimension(this.layer.offsetWidth, this.layer.offsetHeight);
else
return this.getSize(false);
} else {
if (ie || op)
return new Dimension(
this.style.pixelWidth, this.style.pixelHeight);
else if (dom)
return new Dimension(
parseInt(this.style.width), parseInt(this.style.height));
else if (nn)
return new Dimension(
this.layer.clip.width, this.layer.clip.height);
return new Dimension();
}
};
/**
* void setTrim()
* void setTrim(number[] ltrb)
* void setTrim(Rectangle area)
* void setTrim(Point lt, Point rb)
* void setTrim(number l, number t, number r, number b)
*/
FP.setTrim = function() {
var l, t, r, b;
var a = arguments;
switch (a.length) {
case 0 :
l = t = r = b = 0;
break;
case 1 :
var p = a[0];
if (p.constructor === Array) {
l = p[0];
t = p[1];
r = p[2];
b = p[3];
} else {
l = p.x;
t = p.y;
r = l + p.width;
b = t + p.height;
}
break;
case 2 :
l = a[0].x;
t = a[0].y;
r = a[1].x;
b = a[1].y;
break;
case 4 :
l = a[0];
t = a[1];
r = a[2];
b = a[3];
break;
}
if (ie || dom) {
this.style.clip = "rect(" + t + " " + r + " " + b + " " + l + ")";
} else if (nn) {
var c = this.layer.clip;
c.left = l;
c.top = t;
c.right = r;
c.bottom = b;
}
};
var TRIM_CORNER_SYMBOLS = new Object();
/* static */ {
TRIM_CORNER_SYMBOLS["L"] = TRIM_CORNER_SYMBOLS["l"] = 0;
TRIM_CORNER_SYMBOLS["T"] = TRIM_CORNER_SYMBOLS["t"] = 1;
TRIM_CORNER_SYMBOLS["R"] = TRIM_CORNER_SYMBOLS["r"] = 2;
TRIM_CORNER_SYMBOLS["B"] = TRIM_CORNER_SYMBOLS["b"] = 3;
}
/**
* int[] getTrim()
* int getTrim(char ltrb)
*/
FP.getTrim = function() {
var a = arguments;
switch (a.length) {
case 0 :
if (ie || dom) {
var v = this.style.clip;
var r = v.substring(5, v.length - 1).split(" ");
return new Array(
parseInt(r[3]),
parseInt(r[0]),
parseInt(r[1]),
parseInt(r[2]));
} else if (nn) {
var c = this.style.clip;
return new Array(c.left, c.top, c.right, c.bottom);
}
case 1 :
return this.getTrim()[TRIM_CORNER_SYMBOLS[a[0]]];
}
return null;
};
/**
* HTMLImageElement[] f()
*/
FP.getImages = function() {
return BW.getElementsByTagName("img", this.layer);
};
/**
* HTMLImageElement f(String id)
*/
FP.getImage = function(id) {
if (ie) {
var image = document.images[id];
if (image !== void 0)
return image;
} else if (nn) {
return this.layer.document.images[id];
}
if (dom) {
var image = document.getElementById(id);
if (image !== null)
return image;
var images = document.getElementsByName(id);
if (images.length != 0)
return images[0];
}
return null;
};
/**
* HTMLLinkElement[] f()
*/
FP.getLinks = function() {
return BW.getElementsByTagName("a", this.layer);
};
/**
* void f()
* void f(String body)
*/
FP.setBody = function(t) {
if (t === void 0)
t = "";
if (ie || dom)
this.layer.innerHTML = t;
else if (nn) {
var d = this.layer.document;
d.open("text/html", "replace");
d.write(t);
d.close();
}
};
/**
* void f(String uri)
*/
FP.loadFile = function(p) {
if (ie || dom)
this.layer.innerHTML =
("<" + "iframe")
+ " src=\"" + p + "\""
+ " scrolling=\"no\" frameBorder=\"no\""
+ " style=\"width:100%;height:100%;margin:0px;padding:0px;\""
+"><\/iframe>";
else if (nn)
this.layer.src = p;
};
/**
* void f(String type, function listener)
*/
FP.setEventListener = function(t, l) {
t = t.toLowerCase();
if (gk && t == "dblclick") {
this.layer.addEventListener(t, l, true);
} else {
if (nn) {
this.layer.document.captureEvents(Event[t.toUpperCase()]);
this.layer.document["on" + t] = l;
}
this.layer["on" + t] = l;
}
};
/**
* void f(String type);
* void f(String type, function listener_dblclick);
*/
FP.clearEventListener = function(t) {
t = t.toLowerCase();
if (gk && t == "dblclick") {
this.layer.addEventListener(t, arguments[1], true);
} else {
if (nn)
this.layer.document["on" + t] = null;
this.layer["on" + t] = null;
}
};
/**
* void f(String type, function listener)
*/
FP.addEventListener = function(t, l) {
// attachEvent
// detachEvent
if (this[$listeners] === void 0) {
this[$listeners] = new Object();
this[$listeners].listener = function(t) {
var cp = this;
return function(e) {
for (var i = 0; i < cp[t].length; i++)
if (Boolean(cp[t][i]))
cp[t][i](e);
};
};
}
t = t.toLowerCase();
var listeners = this[$listeners];
if (listeners[t] === void 0)
listeners[t] = new Array();
if (gk && t == "dblclick")
this.layer.addEventListener(t, l, true);
else {
if (nn) {
this.layer.document.captureEvents(Event[t.toUpperCase()]);
this.layer.document["on" + t] = listeners.listener(t);
}
this.layer["on" + t] = listeners.listener(t);
listeners[t][listeners[t].length] = l;
}
};
/**
* boolean f(String type, function listener)
* boolean f(String type, int index)
*/
FP.removeEventListener = function(t, l) {
if (this[$listeners] === void 0)
return false;
t = t.toLowerCase();
var listeners = this[$listeners];
if (gk && t == "dblclick")
return this.layer.removeEventListener(t, l, true);
else {
if (typeof l != "number") {
for (var i = 0; i < listeners[t].length; i++) {
if (listeners[t][i] === l) {
listeners[t][i] = null;
return true;
}
}
return false;
} else
return Boolean(listeners[t][l]) ?
this.removeEventListener(t, listeners[t][l]) : false;
}
};
var CORNER_SYMBOLS = new Object();
/* static */ {
CORNER_SYMBOLS["$TL"] = CORNER_SYMBOLS["$UL"] = 0;
CORNER_SYMBOLS["$TR"] = CORNER_SYMBOLS["$UR"] = 1;
CORNER_SYMBOLS["$BL"] = CORNER_SYMBOLS["$LL"] = 2;
CORNER_SYMBOLS["$BR"] = CORNER_SYMBOLS["$LR"] = 3;
for (var corner in CORNER_SYMBOLS) {
if (corner.charAt(0) != '$')
continue;
var C0 = corner.charAt(1), C1 = corner.charAt(2);
var c0 = C0.toLowerCase(), c1 = C0.toLowerCase();
CORNER_SYMBOLS["$" + C1 + C0] =
CORNER_SYMBOLS["$" + c0 + c1] =
CORNER_SYMBOLS["$" + c1 + c0] = CORNER_SYMBOLS[corner];
}
}
/*
* ■ BackCompat
*
* ┌──────width-──────┐
* borderL borderR
* ┌─-┐ ┌─-┐
* ┌A━━━━━━━━━━━━━━━┓┐
* │┃ ┃|borderT
* h│┃ ┏━━━━━━━━━━┓ ┃┘
* e│┃ ┃ ┃ ┃
* i│┃ ┃ ┃ ┃
* g│┃ ┃ ┃ ┃
* h│┃ ┃ ┃ ┃
* t│┃ ┗━━━━━━━━━━┛ ┃┐
* │┃ ┃|borderB
* └┗━━━━━━━━━━━━━━━B┘
* A:UL
* B:BR
*
* ■ CSS1Compat
*
* ┌────-offsetWidth─────┐
* borderL borderR
* ┌─-┐ ┌─-┐
* A━━━━━━━━━━━━━━━┓┐ ┐
* ┃ ┌───-width────┐ ┃|borderT|
* ┃h┌┏━━━━━━━━━━┓ ┃┘ |
* ┃e│┃ ┃ ┃ |
* ┃i│┃ ┃ ┃ |offsetHeight
* ┃g│┃ ┃ ┃ |
* ┃h│┃ ┃ ┃ |
* ┃t└┗━━━━━━━━━━┛ ┃┐ |
* ┃ ┃|borderB|
* ┗━━━━━━━━━━━━━━━B┘ ┘
* A:UL
* B:BR
*/
/**
* void setCornerPosition(String cornerSymbol, Point p)
*/
FP.setCornerPosition = function(t, p) {
var x = p.x, y = p.y;
switch (CORNER_SYMBOLS["$" + t]) {
case 0 : // Upper-Left
this.setPosition(x, y);
return;
case 1 : // Upper-Right
this.setPosition(x - this.getWidth(BW.compatMode == 1), y);
return;
case 2 : // Lower-Left
this.setPosition(x, y - this.getHeight(BW.compatMode == 1));
return;
case 3 : // Lower-Right
var d = this.getSize(BW.compatMode == 1);
this.setPosition(x - d.width, y - d.height);
return;
default : // $ERROR$
window.errorMessage(
("IllegalArguments@" + classId + "#setCornerPosition\n")
+ ("arguments[0] = " + t));
return;
}
};
/**
* void setCenterPosition(Point p)
*/
FP.setCenterPosition = function(p) {
var s = this.getSize(BW.compatMode == 1);
this.setPosition(p.x - s.width / 2, p.y - s.height / 2);
};
/**
* void setCenterPoint(Point3 p)
*/
FP.setCenterPoint = function(p) {
var s = this.getSize(BW.compatMode == 1);
this.setPoint(p.x - s.width / 2, p.y - s.height / 2, p.z);
};
/**
* Point getCornerPosition(String corner)
*/
FP.getCornerPosition = function(t) {
var p = this.getPosition();
switch (CORNER_SYMBOLS["$" + t]) {
case 0 : // Upper-Left
return p;
case 1 : // Upper-Right
p.x += this.getWidth(BW.compatMode == 1);
return p;
case 2 : // Lower-Left
p.y += this.getHeight(BW.compatMode == 1);
return p;
case 3 : // Lower-Right
var s = this.getSize(BW.compatMode == 1);
p.x += s.width;
p.y += s.height;
return p;
default : // $ERROR$
window.errorMessage(
("IllegalArguments@" + classId + "#getCornerPosition\n")
+ ("arguments[0] = " + t));
return null;
}
};
/**
* Point getCenterPosition()
*/
FP.getCenterPosition = function() {
var p = this.getPosition();
var s = this.getSize(BW.compatMode == 1);
p.x += s.width * 0.5;
p.y += s.height * 0.5;
return p;
};
/**
* boolean equals(Object e)
*/
FP.equals = function(e) {
if (e == null || e.constructor !== F)
return false;
return this.layer === e.layer && this.style === e.style;
};
/**
* String toString()
*/
FP.toString = function() {
return classId + " : " + this.id;
};
/**
* String paramString()
*/
FP.paramString = function() {
return ""
+ "id=" + this.id + ","
+ "width=" + this.getWidth() + ","
+ "height=" + this.getHeight() + ","
+ "x=" + this.getX() + ","
+ "y=" + this.getY() + ","
+ "z=" + this.getZ() + ","
+ "visibility=" + this.getVisibility() + ","
+ "clip=" + this.getTrim()
+ "";
};
} class__JElement__(window);