Subversion Repositories JSX

Compare Revisions

Last modification

Ignore whitespace Rev 460 → Rev 461

/trunk/dom/widgets.js
66,45 → 66,44
* {@link #appendTo()} method later to append it.
* @param {Object} oProperties
*/
jsx.dom.widgets.Widget =
function jsx_dom_widgets_Widget (oTarget, oParent, oProperties) {
this._target = oTarget || document.createElement(this.elementType);
jsx.dom.widgets.Widget = function (oTarget, oParent, oProperties) {
this._target = oTarget || document.createElement(this.elementType);
 
if (oParent && !(oParent instanceof jsx_dom_widgets_Widget))
{
return jsx.throwThis(jsx.InvalidArgumentError, [null, "Widget", oParent]);
}
if (oParent && !(oParent instanceof jsx.dom.widgets.Container))
{
return jsx.throwThis(jsx.InvalidArgumentError, [null, "jsx.dom.widgets.Container", oParent]);
}
 
this._parent = oParent || null;
this._parent = oParent || null;
 
/**
* @type Array[Widget]
*/
this.children = [];
/**
* @type Array[Widget]
*/
this.children = [];
 
for (var propertyName in oProperties)
for (var propertyName in oProperties)
{
/* Do not overwrite methods */
if (typeof this[propertyName] != "function")
{
/* Do not overwrite methods */
if (typeof this[propertyName] != "function")
var setter = this._getSetterFor(propertyName);
if (setter)
{
var setter = this._getSetterFor(propertyName);
if (setter)
{
setter.call(this, oProperties[propertyName]);
}
else
{
this[propertyName] = oProperties[propertyName];
}
setter.call(this, oProperties[propertyName]);
}
else
{
this[propertyName] = oProperties[propertyName];
}
}
}
 
if (this._target)
{
this.init();
this.update();
}
};
if (this._target)
{
this.init();
this.update();
}
};
 
jsx.dom.widgets.Widget.extend(null, {
/**
121,38 → 120,101
_target: null,
 
/**
* Defines actions to be performed when the widget is initialized;
* overridden by inheriting types.
* Defines actions to be performed when the widget is initialized.
* Can be overridden by inheriting types. If it is overridden,
* it must also be called.
*/
init: function () {
/* stub */
if (this._parent)
{
/*
* Automagically append widget to parent
* (without necessarily rendering it)
*/
/* FIXME */
// this.appendTo();
}
},
 
/**
* Defines actions to be performed when the widget's canvas should be
* updated to reflect its current status; should be overridden
* and called by inheriting types.
* Sets a style property of this widget
*
* @function
*/
update: (function () {
var _setStyleProperty = jsx.dom.setStyleProperty;
setStyleProperty: (function () {
var jsx_dom_setStyleProperty = jsx.dom.setStyleProperty;
 
return function () {
var style = this.style;
for (var styleProperty in style)
{
_setStyleProperty(this._target, styleProperty, style[styleProperty]);
}
/**
* @param {String} name
* @param value
* @return {boolean}
* @see jsx.dom.setStyleProperty()
*/
function Widget_setStyleProperty (name, value)
{
return jsx_dom_setStyleProperty(this._target, name, value);
}
 
for (var i = 0, len = this.children.length; i < len; ++i)
return Widget_setStyleProperty;
}()),
 
/**
* Resets a style property of this widget to its inherited value
*
* @function
*/
resetStyleProperty: (function (name) {
var jsx_dom_css_resetStyleProperty = jsx.dom.css.resetStyleProperty;
 
/**
* @param name
* @returns {Function}
*/
function Widget_resetStyleProperty (name)
{
jsx_dom_css_resetStyleProperty(this._target, name);
}
 
return Widget_resetStyleProperty;
}()),
 
/**
* Sets several style properties of this widget at once
*
* @param {Object} style
*/
setStyle: function (style) {
var result = true;
 
for (var propertyName in style)
{
var resultPart = this.setStyleProperty(propertyName, style[propertyName]);
if (result && !resultPart)
{
this.children[i].update();
result = false;
}
}
 
return this;
};
}()),
return result;
},
 
/**
* Defines actions to be performed when the widget's canvas should be
* updated to reflect its current status; should be overridden
* and called by inheriting types.
*/
update: function () {
this.setStyle(this.style);
 
for (var i = 0, len = this.children.length; i < len; ++i)
{
this.children[i].update();
}
 
return this;
},
 
/**
* Causes the widget to be rendered, and attached to the document tree
* if not already attached.
*