if(typeof parsedCommon == "undefined"){ parsedCommon = true; /** * inheritance * siehe http://www.kevlindev.com/tutorials/javascript/inheritance/ */ OOP = {}; OOP.extend = function(subClass, baseClass) { function inheritance() {} inheritance.prototype = baseClass.prototype; subClass.prototype = new inheritance(); subClass.prototype.constructor = subClass; subClass.baseConstructor = baseClass; subClass.superClass = baseClass.prototype; } /** * Basisklasse für eine Komponente */ function BaseComponent(id, left, top, width, height) { this.parent = null; this.id = id; this.left = left; this.top = top; this.width = width; this.height = height; this.style = new Object(); this.isRenderd = false; this.value = null; this.enabled = false; this.autoExecWithContainer = true; // Rendern, Starten, Stoppen, wenn der Container dies tut. } BaseComponent.prototype.start = function() { this.enabled = true; } BaseComponent.prototype.stop = function() { this.enabled = false; } BaseComponent.prototype.getId = function() { return this.id; } BaseComponent.prototype.getParent = function() { return this.parent; } BaseComponent.prototype.setParent = function(parent) { this.parent = parent; this.setIdPrefix(parent.id); } BaseComponent.prototype.setIdPrefix = function(prefix) { this.id = prefix + "." + this.id; } BaseComponent.prototype.getElement = function() { return document.getElementById(this.id); } BaseComponent.prototype.getValue = function() { return this.value } BaseComponent.prototype.setValue = function(value) { this.value = value; } BaseComponent.prototype.setVisible = function(value) { if (value) { this.show(); } else { this.hide(); } } BaseComponent.prototype.isVisible = function() { var ret = false; var el = this.getElement(); if (el != null) { ret = (el.style["top"] != "-10000px"); } return this.getStyle()["top"] != "-10000px"; } BaseComponent.prototype.render = function() { var ret = null; var el = document.getElementsByTagName("body")[0]; if (el != null) { ret = this.renderTo(el) } return ret; } BaseComponent.prototype.renderTo = function(el) { var newEl = document.createElement("div"); var newAtt = document.createAttribute("id"); newAtt.nodeValue = this.id; newEl.setAttributeNode(newAtt); newAtt = document.createAttribute("class"); newAtt.nodeValue = this.styleClass; newEl.setAttributeNode(newAtt); this.setStyleFor(newEl, "position", "absolute") this.setStyleFor(newEl, "display", "block") this.setStyleFor(newEl, "left", this.left+"px") this.setStyleFor(newEl, "top", this.top+"px") this.setStyleFor(newEl, "width", this.width+"px") this.setStyleFor(newEl, "height", this.height+"px") for (var style in this.style) { this.setStyleFor(newEl, style, this.style[style]); } this.style = new Object(); el.appendChild(newEl); this.isRenderd = true; return newEl; } BaseComponent.prototype.getStyle = function(){ var el = this.getElement(); if (el != null) { return el.style; } else { return this.style; } } BaseComponent.prototype.setStyle = function(name, value){ var el = this.getElement(); if (el != null) { this.setStyleFor(el, name, value); } else { this.style[name] = value; } } BaseComponent.prototype.setStyleClass = function(styleClass) { this.styleClass = styleClass; } BaseComponent.prototype.setStyleFor = function(el, name, value){ el.style[name] = value; } BaseComponent.prototype.show = function() { this.setStyle("top", this.top+"px"); if (!this.isRenderd) { /* var el = this.getElement(); if (el != null) { this.setStyleFor(el, "top", this.top+"px"); } } else { */ this.render(); } } BaseComponent.prototype.hide = function() { this.setStyle("top", "-10000px"); } BaseComponent.prototype.moveTo = function(x, y) { var el = this.getElement(); if (el != null) { this.left = x; this.top = y; this.setStyleFor(el, "left", x+"px"); this.setStyleFor(el, "top", y+"px"); } } /** * Basisklasse für einen Container */ function BaseContainer(id, left, top, width, height) { BaseContainer.baseConstructor.call(this, id, left, top, width, height); this.components = new Array(); this.shadow = null; this.shadowWidth = 0; this.shadowColor = null; } OOP.extend(BaseContainer, BaseComponent); BaseContainer.prototype.setShadow = function(width, color) { this.shadowWidth = width; this.shadowColor = color; this.shadow = new BaseContainer(this.id+".shadow", this.left + width, this.top + width, this.width, this.height); } BaseContainer.prototype.addComponent = function(component) { component.setParent(this); this.components.push(component); return component; } BaseContainer.prototype.getComponent = function (index) { return this.components[index]; } BaseContainer.prototype.getComponentById = function (id) { var component = null; var realId = this.id + "." + id; for (var i = 0; i < this.components.length; i++) { if (this.getComponent(i).id == realId) { component = this.getComponent(i); break; } } return component; } BaseContainer.prototype.getComponentIndex = function (component) { var index = -1; for (var i = 0; i < this.components.length; i++) { if (this.getComponent(i).id == component.id) { index = i; break; } } return index; } BaseContainer.prototype.setIdPrefix = function(prefix) { this.id = prefix + "." + this.id; for (var i = 0; i < this.components.length; i++) { this.getComponent(i).setIdPrefix(prefix); } if (this.shadow) {this.shadow.setIdPrefix(prefix);} } BaseContainer.prototype.renderTo = function(el) { if (this.shadow) { var newEl = this.shadow.renderTo(el); this.setStyleFor(newEl, "backgroundColor", this.shadowColor); } var newContainer = BaseContainer.superClass.renderTo.call(this, el); for (var i = 0; i < this.components.length; i++) { var component = this.getComponent(i); if (component.autoExecWithContainer) {component.renderTo(newContainer);} } return newContainer; } BaseContainer.prototype.show = function() { BaseContainer.superClass.show.call(this); if (this.shadow) {this.shadow.show();} } BaseContainer.prototype.hide = function() { BaseContainer.superClass.hide.call(this); if (this.shadow) {this.shadow.hide();} } BaseContainer.prototype.moveTo = function(x, y) { BaseContainer.superClass.moveTo.call(this); if (this.shadow) {this.shadow.moveTo(x, y);} } BaseContainer.prototype.start = function() { if (this.enabled) {return;} this.enabled = true; for (var i = 0; i < this.components.length; i++) { var component = this.getComponent(i); if (component.autoExecWithContainer) {component.start();} } } BaseContainer.prototype.stop = function() { if (!this.enabled) {return;} this.enabled = false; for (var i = 0; i < this.components.length; i++) { var component = this.getComponent(i); if (component.autoExecWithContainer) {component.stop();} } } /** * Basisklasse für Event-Argumente */ function BaseEventArgs(typ, obj) { //obj = vom Browser generiertes Event oder Error this.typ = typ; this.obj = obj; } BaseEventArgs.prototype.getBaseEvent = function() { return this.obj; } BaseEventArgs.prototype.getTyp = function() { return this.typ; } /** * Klasse für ErrorEvent-Argumente */ function ErrorEventArgs(errortyp, obj) { ErrorEventArgs.baseConstructor.call(this, "error", obj); this.errortyp = errortyp; } OOP.extend(ErrorEventArgs, BaseEventArgs); ErrorEventArgs.prototype.getErrorTyp = function() { return this.errortyp; } ErrorEventArgs.prototype.getError = function() { return this.obj; } /** * Klasse für CancelEvent-Argumente */ function CancelEventArgs(typ, obj) { CancelEventArgs.baseConstructor.call(this, typ, obj); this.canceled = false; } OOP.extend(CancelEventArgs, BaseEventArgs); CancelEventArgs.prototype.isCanceled = function() { return this.canceled; } CancelEventArgs.prototype.setCanceled = function(value) { this.canceled = value; } /** * Klasse für KeyEvent-Argumente */ function KeyEventArgs(typ, obj) { KeyEventArgs.baseConstructor.call(this, typ, obj); } OOP.extend(KeyEventArgs, CancelEventArgs); KeyEventArgs.prototype.getKeyEvent = function() { return this.obj; } /** * Klasse für MouseEvent-Argumente */ function MouseEventArgs(typ, obj) { MouseEventArgs.baseConstructor.call(this, typ, obj); } OOP.extend(MouseEventArgs, CancelEventArgs); MouseEventArgs.prototype.getMouseEvent = function() { return this.obj; } }