37,17 → 37,17 |
|
/* Other private variables */ |
/** |
* Constructor of the abstract prototype for widgets. It provides |
* shallow copying of the passed properties, stores the reference to the |
* manipulated DOM object, and applies the given properties to the |
* display of that object. Widgets should inherit from this prototype, |
* and this constructor should be called only from the constructors of |
* prototypes of specialized widgets. |
* |
* @function |
*/ |
var _Widget = ( |
/** |
* Constructor of the abstract prototype for widgets. It provides |
* shallow copying of the passed properties, stores the reference to the |
* manipulated DOM object, and applies the given properties to the |
* display of that object. Widgets should inherit from this prototype, |
* and this constructor should be called only from the constructors of |
* prototypes of specialized widgets. |
* |
* @constructor |
* @param {Element} oTarget |
* Reference to the DOM object that represents the |
60,13 → 60,14 |
* {@link #appendTo()} method later to append it. |
* @param {Object} oProperties |
*/ |
function (oTarget, oParent, oProperties) { |
this._target = oTarget || document.createElement(this.elementType); |
function jsx_dom_widgets_Widget (oTarget, oParent, oProperties) { |
this._setTarget(oTarget || document.createElement(this.elementType)); |
|
if (oParent && !(oParent instanceof _Container)) |
{ |
return jsx.throwThis(jsx.InvalidArgumentError, |
[null, jsx.object.getFunctionName(oParent.constructor), "jsx.dom.widgets.Container"]); |
[null, jsx.object.getFunctionName(oParent.constructor), |
"jsx.dom.widgets.Container"]); |
} |
|
this._parent = oParent || null; |
93,7 → 94,7 |
} |
} |
|
if (this._target) |
if (this.getTarget()) |
{ |
this.init(); |
this.update(); |
113,6 → 114,7 |
elementType: "div", |
|
/** |
* @protected |
* @type Element |
*/ |
_target: null, |
134,6 → 136,18 |
}, |
|
/** |
* @protected |
* @param value |
*/ |
_setTarget: function (value) { |
this._target = value; |
}, |
|
getTarget: function () { |
return this._target; |
}, |
|
/** |
* Gets a property of this widget's target object. |
* |
* @param {String} name |
140,7 → 154,7 |
* @return {any} |
*/ |
getTargetProperty: function (name) { |
return this._target[name]; |
return this.getTarget()[name]; |
}, |
|
/** |
154,7 → 168,7 |
* @return {jsx.dom.widgets.Widget} |
*/ |
setTargetProperty: function (name, value) { |
this._target[name] = value; |
this.getTarget()[name] = value; |
return this; |
}, |
|
188,7 → 202,7 |
* @see jsx.dom.css.setStyleProperty() |
*/ |
setStyleProperty: function (name, value) { |
return _css.setStyleProperty(this._target, name, value); |
return _css.setStyleProperty(this.getTarget(), name, value); |
}, |
|
/** |
197,7 → 211,7 |
* @param {String} name |
*/ |
resetStyleProperty: function (name) { |
_css.resetStyleProperty(this._target, name); |
_css.resetStyleProperty(this.getTarget(), name); |
}, |
|
/** |
226,13 → 240,19 |
* and called by inheriting types. |
*/ |
update: function () { |
this.setStyle(this.style); |
/* TODO: Only update if dirty */ |
// if (this._dirty) |
// { |
this.setStyle(this.style); |
|
for (var i = 0, len = this.children.length; i < len; ++i) |
{ |
this.children[i].update(); |
} |
for (var i = 0, len = this.children.length; i < len; ++i) |
{ |
this.children[i].update(); |
} |
|
this._dirty = false; |
// } |
|
return this; |
}, |
|
241,7 → 261,7 |
*/ |
render: function (parent) { |
this.update(); |
this._target.style.display = ""; |
this.getTarget().style.display = ""; |
return this; |
}, |
|
250,7 → 270,7 |
* from the document tree. |
*/ |
unrender: function () { |
this._target.style.display = "none"; |
this.getTarget().style.display = "none"; |
return this; |
}, |
|
258,7 → 278,7 |
* Shows the widget |
*/ |
show: function () { |
this._target.style.visibility = "visible"; |
this.getTarget().style.visibility = "visible"; |
return this; |
}, |
|
266,7 → 286,7 |
* Hides the widget, but keeps its box |
*/ |
hide: function () { |
this._target.style.visibility = "hidden"; |
this.getTarget().style.visibility = "hidden"; |
return this; |
}, |
|
303,6 → 323,11 |
return this._parent.removeChild(this); |
}, |
|
/** |
* @protected |
* @param {String} propertyName |
* @return {Function|Null} |
*/ |
_getSetterFor: function (propertyName) { |
var setterName = |
"set" + propertyName.charAt(0).toUpperCase() + propertyName.substring(1); |
340,7 → 365,7 |
init: function () { |
_Container._super.prototype.init.call(this); |
|
this._defaultContent = this.innerHTML || this._target.innerHTML || ""; |
this._defaultContent = this.innerHTML || this.getTarget().innerHTML || ""; |
}, |
|
/** |
355,7 → 380,7 |
return function () { |
_Container._super.prototype.update.call(this); |
|
var target = this._target; |
var target = this.getTarget(); |
|
var html = this.innerHTML; |
if (html !== null) |
456,7 → 481,7 |
* @return {string} |
*/ |
getText: function () { |
this.text = this._target.textContent; |
this.text = this.getTarget().textContent; |
return this.text; |
}, |
|
498,8 → 523,8 |
*/ |
appendChild: function (child) { |
var result = null; |
var childTarget = child._target; |
var target = this._target; |
var childTarget = child.getTarget(); |
var target = this.getTarget(); |
var success = true; |
|
/* |
511,7 → 536,7 |
/* |
* … append it as child element |
*/ |
target.appendChild(child._target); |
target.appendChild(child.getTarget()); |
success = (target.lastChild == childTarget); |
} |
|
539,7 → 564,7 |
var childIndex = this.children.indexOf(child); |
if (childIndex >= 0) |
{ |
this._target.removeChild(child._target); |
this.getTarget().removeChild(child.getTarget()); |
this.children.splice(childIndex, 1); |
} |
} |
567,6 → 592,42 |
elementType: "a" |
}); |
|
var _Button = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_Button (oTarget, oParent, oProperties) { |
jsx_dom_widgets_Button._super.apply(this, arguments); |
} |
).extend(_Container, { |
/** |
* @memberOf jsx.dom.widgets.Button.prototype |
*/ |
elementType: "button", |
|
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.Widget.prototype.init() |
*/ |
init: function jsx_dom_widgets_Button_prototype_init () { |
_Button._super.prototype.init.call(this); |
|
var me = this; |
|
jsx.tryThis( |
function () { |
me.getTarget().type = "button"; |
}, |
|
function () { |
/* IE 7 and other borken UAs that don't support inline-block properly */ |
jsx.throwThis("jsx.dom.widgets.InitError", "jsx.dom.widgets.Button", |
jsx_dom_widgets_Button_prototype_init); |
} |
); |
} |
}); |
|
var _Label = ( |
/** |
* @constructor |
622,7 → 683,7 |
jsx_dom_widgets_Input._super.apply(this, arguments); |
|
var me = this; |
_jsx_dom.addEventListener(this._target, "keypress", _jsx_dom.createEventListener( |
_jsx_dom.addEventListener(this.getTarget(), "keypress", _jsx_dom.createEventListener( |
function (e) { |
var charCode = |
(typeof e.charCode != "undefined") |
660,12 → 721,12 |
|
if (typeof this.value != "undefined") |
{ |
this._target.value = this.value; |
this.getTarget().value = this.value; |
} |
|
if (typeof this.tabIndex != "undefined") |
{ |
this._target.tabIndex = this.tabIndex; |
this.getTarget().tabIndex = this.tabIndex; |
} |
|
return this; |
698,7 → 759,7 |
|
var me = this; |
|
var target = this._target; |
var target = this.getTarget(); |
_jsx_dom.addEventListener(target, "blur", function () { |
me.update(); |
}); |
741,7 → 802,7 |
init: function () { |
_NumberInput._super.prototype.init.call(this); |
|
var target = this._target; |
var target = this.getTarget(); |
|
if (target.type != "number") |
{ |
770,7 → 831,7 |
update: function () { |
_NumberInput._super.prototype.update.call(this); |
|
var target = this._target; |
var target = this.getTarget(); |
|
var v = parseFloat(target.value); |
|
814,10 → 875,11 |
|
if (!isNaN(value)) |
{ |
if (this._target.type == "number") |
var target = this.getTarget(); |
if (target.type == "number") |
{ |
/* HTML5 support */ |
this._target[valueType] = String(value); |
target[valueType] = String(value); |
} |
|
this[valueType + "Value"] = value; |
839,169 → 901,206 |
} |
}); |
|
var _ListItem = ( |
var _SpinnerInput = ( |
/** |
* @constructor |
* @param {Element} oTarget |
* Reference to the DOM object that represents the element that |
* provides the client area for the widget. Pass a false-value |
* to create a new element. |
* @param {Element} oParent |
* Reference to the DOM object that represents the parent element |
* for this widget. Pass <code>null</code> so that the widget |
* will not be automatically attached to the document tree. |
* You can call its {@link #appendTo()} method later to attach it. |
* @param {Object} oProperties |
*/ |
function jsx_dom_widgets_ListItem () { |
jsx_dom_widgets_ListItem._super.apply(this, arguments); |
} |
).extend(_Container, { |
/** |
* @memberOf jsx.dom.widgets.ListItem.prototype |
*/ |
elementType: "li" |
}); |
function jsx_dom_widgets_SpinnerInput (oTarget, oParent, oProperties) { |
var me = this; |
|
/** |
* @function |
*/ |
var _List = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_List () { |
jsx_dom_widgets_List._super.apply(this, arguments); |
} |
).extend(_Container, { |
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.Widget.prototype.init() |
*/ |
init: function () { |
_List._super.prototype.init.call(this); |
jsx_dom_widgets_SpinnerInput._super.apply(this, arguments); |
|
if (!this.items) |
var target = this.getTarget(); |
if (target.type != "number") |
{ |
var target = this._target; |
if (target) |
{ |
var childNodes = target.children || target.childNodes; |
for (var i = 0, len = childNodes.length; i < len; ++i) |
{ |
var node = childNodes[i]; |
if (node.nodeType == 1) |
/* If no HTML5 support, try adding arrow controls */ |
jsx.tryThis( |
function () { |
me.buttonUp = new _jsx_dom.widgets.Button(null, null, { |
text: "\u25B4", |
tabIndex: target.tabIndex, |
style: { |
display: "block", |
margin: "0", |
width: "1em", |
minWidth: "0", |
padding: "0", |
lineHeight: "1em" |
}, |
onclick: function () { |
me.inc(); |
|
var target = me.getTarget(); |
if (typeof target.onchange == "function") |
{ |
target.onchange(); |
} |
} |
}); |
|
me.buttonDown = new _jsx_dom.widgets.Button(null, null, { |
text: "\u25BE", |
tabIndex: target.tabIndex, |
style: { |
display: "block", |
margin: "0", |
width: "1em", |
minWidth: "0", |
padding: "0", |
lineHeight: "1em" |
}, |
onclick: function () { |
me.dec(); |
|
var target = me.getTarget(); |
if (typeof target.onchange == "function") |
{ |
target.onchange(); |
} |
} |
}); |
|
var buttonContainer = document.createElement("div"); |
buttonContainer.style.display = "inline-block"; |
buttonContainer.style.lineHeight = "1em"; |
buttonContainer.style.verticalAlign = "middle"; |
|
buttonContainer.appendChild(me.buttonUp.getTarget()); |
buttonContainer.appendChild(me.buttonDown.getTarget()); |
target.parentNode.insertBefore(buttonContainer, target.nextSibling); |
}, |
|
function (e) { |
if (!e || e.name !== "jsx.dom.widgets.InitError") |
{ |
var item = new _ListItem(node); |
item.appendTo(this); |
this.addItem(item); |
/* Rethrow unhandled exception */ |
jsx.rethrowThis(e); |
} |
} |
} |
); |
|
/* Add event listeners */ |
_jsx_dom.addEventListener(target, "keydown", _jsx_dom.createEventListener( |
function (e) { |
/** |
* Increases the value of the <code>value</code> property. |
*/ |
// function inc() |
// { |
// var v; |
// if ((me.maxValue == Infinity || this.value < me.maxValue) |
// && !isNaN(v = parseInt(this.value, 10) + 1) |
// && (this.maxLength < 1 || v.toString().length <= |
// this.maxLength)) |
// { |
// this.value = v; |
// } |
// } |
// |
// function dec() |
// { |
// var v; |
// if ((me.minValue == -Infinity || this.value > me.minValue) |
// && !isNaN(v = parseInt(this.value, 10) - 1) |
// && (this.maxLength < 1 || v.toString().length <= |
// this.maxLength)) |
// { |
// this.value = v; |
// } |
// } if (me.minValue != -Infinity || me.maxValue != Infinity) |
|
if (typeof e.keyIdentifier != "undefined") |
{ |
/* DOM Level 3 Events draft */ |
switch (e.keyIdentifier) |
{ |
case "Up": |
me.inc(); |
break; |
|
case "Down": |
me.dec(); |
} |
} |
else |
{ |
/* currently proprietary */ |
switch (e.keyCode) |
{ |
case 38: |
me.inc(); |
break; |
|
case 40: |
me.dec(); |
} |
} |
|
me.update(); |
} |
)); |
|
_jsx_dom.addEventListener(target, "keyup", function () { me.update(); }); |
} |
}, |
|
} |
).extend(_NumberInput, { |
/** |
* @memberOf jsx.dom.widgets.List.prototype |
* @param {any} listItem |
* Increases the value of the input by 1 |
* |
* @memberOf jsx.dom.widgets.SpinnerInput.prototype |
*/ |
addItem: function (listItem) { |
if (!this.items) |
inc: function () { |
var v, t = this.getTarget(); |
|
if ( (this.maxValue == Infinity || t.value < this.maxValue) |
&& !isNaN(v = parseInt(t.value, 10) + 1) |
&& (t.maxLength < 1 || v.toString().length <= t.maxLength)) |
{ |
this.items = []; |
t.value = v; |
} |
|
this.items.push(listItem); |
}, |
|
/** |
* @param {any} listItem |
* Decreases the value of the input by 1 |
*/ |
removeItem: function (item) { |
var items = this.items; |
if (items) |
dec: function () { |
var v, t = this.getTarget(); |
|
if ( (this.minValue == -Infinity || t.value > this.minValue) |
&& !isNaN(v = parseInt(t.value, 10) - 1) |
&& (t.maxLength < 1 || v.toString().length <= t.maxLength)) |
{ |
var i = items.indexOf(item); |
if (i > -1) |
{ |
items.splice(i, 1); |
} |
t.value = v; |
} |
}, |
|
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.List.prototype.update() |
* @see jsx.dom.widgets.NumberInput.prototype.update() |
*/ |
update: function () { |
_List._super.prototype.update.call(this); |
_NumberInput.prototype.update.call(this); |
|
var items = this._items; |
var i; |
var len = items && items.length || 0; |
|
for (i = len; i--;) |
var target = this.getTarget(); |
if (typeof target.onchange == "function") |
{ |
var item = items[i]; |
if (item._target.tagName.toUpperCase() != "LI") |
{ |
items[i] = new _ListItem(null, null, { |
children: [item] |
}); |
} |
|
items[i].update(); |
target.onchange(); |
} |
|
var target = this._target; |
var listItems = _gEBTN("li", -1, target); |
var len2 = listItems.length; |
for (i = 0; i < len && i < len2; ++i) |
{ |
var listItem = listItems[i]; |
item = items[i]; |
|
if (listItem != item._target) |
{ |
target.replaceChild(item._target, listItem); |
} |
} |
|
for (var j = listItems.length; j-- > i;) |
{ |
target.removeChild(listItems[j]); |
} |
|
for (++j; j < len; ++j) |
{ |
items[j].appendTo(this); |
} |
|
return this; |
} |
}); |
|
var _OrderedList = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_OrderedList () { |
jsx_dom_widgets_OrderedList._super.apply(this, arguments); |
} |
).extend(_List, { |
/** |
* @memberOf jsx.dom.widgets.OrderedList.prototype |
*/ |
elementType: "ol" |
}); |
|
/** |
* @function |
*/ |
var _UnorderedList = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_UnorderedList () { |
jsx_dom_widgets_UnorderedList._super.apply(this, arguments); |
} |
).extend(_List, { |
/** |
* @memberOf jsx.dom.widgets.UnorderedList.prototype |
*/ |
elementType: "ul" |
}); |
|
var _Checkbox = ( |
/** |
* @constructor |
1029,8 → 1128,9 |
init: function () { |
_Checkbox._super.prototype.init.call(this); |
|
this._target.type = "checkbox"; |
this._target.id = "checkbox" + (++this._uid); |
var target = this.getTarget(); |
target.type = "checkbox"; |
target.id = "checkbox" + (++this._uid); |
|
var label = this.label; |
if (label) |
1044,6 → 1144,12 |
} |
}, |
|
update: function () { |
this.getTarget().checked = this.checked; |
|
_Checkbox._super.prototype.update.call(this); |
}, |
|
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.Widget.prototype.render() |
1054,7 → 1160,7 |
var label = this.label; |
if (label) |
{ |
label._target.htmlFor = this._target.id; |
label.getTarget().htmlFor = this.getTarget().id; |
label.render(); |
} |
}, |
1115,13 → 1221,13 |
{ |
if (this.labelPosition === _jsx_dom.widgets.position.BEFORE) |
{ |
parent._target.insertBefore(label._target, this._target); |
parent.getTarget().insertBefore(label.getTarget(), this.getTarget()); |
} |
else |
{ |
if (this.labelPosition === _jsx_dom.widgets.position.AFTER) |
{ |
parent._target.insertBefore(label._target, this._target.nextSibling); |
parent.getTarget().insertBefore(label.getTarget(), this.getTarget().nextSibling); |
} |
} |
|
1139,243 → 1245,191 |
var CheckboxTarget = _Checkbox._super.prototype.remove.call(this); |
var labelTarget = this.label.remove(); |
return [CheckboxTarget, labelTarget]; |
}, |
|
setChecked: function (value) { |
this.checked = !!value; |
return this; |
}, |
|
getChecked: function () { |
return this.checked; |
}, |
|
check: function () { |
return this.setChecked(true); |
}, |
|
uncheck: function () { |
return this.setChecked(false); |
} |
}); |
|
var _Button = ( |
var _ListItem = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_Button (oTarget, oParent, oProperties) { |
jsx_dom_widgets_Button._super.apply(this, arguments); |
function jsx_dom_widgets_ListItem () { |
jsx_dom_widgets_ListItem._super.apply(this, arguments); |
} |
).extend(_Container, { |
/** |
* @memberOf jsx.dom.widgets.Button.prototype |
* @memberOf jsx.dom.widgets.ListItem.prototype |
*/ |
elementType: "button", |
elementType: "li" |
}); |
|
/** |
* @function |
*/ |
var _List = ( |
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.Widget.prototype.init() |
* @constructor |
*/ |
init: function jsx_dom_widgets_Button_prototype_init () { |
_Button._super.prototype.init.call(this); |
|
var me = this; |
|
jsx.tryThis( |
function () { |
me._target.type = "button"; |
}, |
|
function () { |
/* IE 7 and other borken UAs that don't support inline-block properly */ |
jsx.throwThis("jsx.dom.widgets.InitError", "jsx.dom.widgets.Button", |
jsx_dom_widgets_Button_prototype_init); |
} |
); |
function jsx_dom_widgets_List () { |
jsx_dom_widgets_List._super.apply(this, arguments); |
} |
}); |
|
var _SpinnerInput = ( |
).extend(_Container, { |
/** |
* @constructor |
* @param {Element} oTarget |
* Reference to the DOM object that represents the element that |
* provides the client area for the widget. Pass a false-value |
* to create a new element. |
* @param {Element} oParent |
* Reference to the DOM object that represents the parent element |
* for this widget. Pass <code>null</code> so that the widget |
* will not be automatically attached to the document tree. |
* You can call its {@link #appendTo()} method later to attach it. |
* @param {Object} oProperties |
* (non-JSdoc) |
* @see jsx.dom.widgets.Widget.prototype.init() |
*/ |
function jsx_dom_widgets_SpinnerInput (oTarget, oParent, oProperties) { |
var me = this; |
init: function () { |
_List._super.prototype.init.call(this); |
|
jsx_dom_widgets_SpinnerInput._super.apply(this, arguments); |
|
var target = this._target; |
if (target.type != "number") |
if (!this.items) |
{ |
/* If no HTML5 support, try adding arrow controls */ |
jsx.tryThis( |
function () { |
me.buttonUp = new _jsx_dom.widgets.Button(null, null, { |
text: "\u25B4", |
tabIndex: target.tabIndex, |
style: { |
display: "block", |
margin: "0", |
width: "1em", |
minWidth: "0", |
padding: "0", |
lineHeight: "1em" |
}, |
onclick: function () { |
me.inc(); |
|
if (typeof me._target.onchange == "function") |
{ |
me._target.onchange(); |
} |
} |
}); |
|
me.buttonDown = new _jsx_dom.widgets.Button(null, null, { |
text: "\u25BE", |
tabIndex: target.tabIndex, |
style: { |
display: "block", |
margin: "0", |
width: "1em", |
minWidth: "0", |
padding: "0", |
lineHeight: "1em" |
}, |
onclick: function () { |
me.dec(); |
|
if (typeof me._target.onchange == "function") |
{ |
me._target.onchange(); |
} |
} |
}); |
|
var buttonContainer = document.createElement("div"); |
buttonContainer.style.display = "inline-block"; |
buttonContainer.style.lineHeight = "1em"; |
buttonContainer.style.verticalAlign = "middle"; |
|
buttonContainer.appendChild(me.buttonUp._target); |
buttonContainer.appendChild(me.buttonDown._target); |
target.parentNode.insertBefore(buttonContainer, target.nextSibling); |
}, |
|
function (e) { |
if (!e || e.name !== "jsx.dom.widgets.InitError") |
var itemType = this.itemType || _ListItem; |
var target = this.getTarget(); |
if (target) |
{ |
var childNodes = target.children || target.childNodes; |
for (var i = 0, len = childNodes.length; i < len; ++i) |
{ |
var node = childNodes[i]; |
if (node.nodeType == 1) |
{ |
/* Rethrow unhandled exception */ |
jsx.rethrowThis(e); |
var item = new itemType(node); |
item.appendTo(this); |
this.addItem(item); |
} |
} |
); |
} |
} |
}, |
|
/* Add event listeners */ |
_jsx_dom.addEventListener(target, "keydown", _jsx_dom.createEventListener( |
function (e) { |
/** |
* Increases the value of the <code>value</code> property. |
*/ |
// function inc() |
// { |
// var v; |
// if ((me.maxValue == Infinity || this.value < me.maxValue) |
// && !isNaN(v = parseInt(this.value, 10) + 1) |
// && (this.maxLength < 1 || v.toString().length <= |
// this.maxLength)) |
// { |
// this.value = v; |
// } |
// } |
// |
// function dec() |
// { |
// var v; |
// if ((me.minValue == -Infinity || this.value > me.minValue) |
// && !isNaN(v = parseInt(this.value, 10) - 1) |
// && (this.maxLength < 1 || v.toString().length <= |
// this.maxLength)) |
// { |
// this.value = v; |
// } |
// } if (me.minValue != -Infinity || me.maxValue != Infinity) |
|
if (typeof e.keyIdentifier != "undefined") |
{ |
/* DOM Level 3 Events draft */ |
switch (e.keyIdentifier) |
{ |
case "Up": |
me.inc(); |
break; |
|
case "Down": |
me.dec(); |
} |
} |
else |
{ |
/* currently proprietary */ |
switch (e.keyCode) |
{ |
case 38: |
me.inc(); |
break; |
|
case 40: |
me.dec(); |
} |
} |
|
me.update(); |
} |
)); |
|
_jsx_dom.addEventListener(target, "keyup", function () { me.update(); }); |
} |
} |
).extend(_NumberInput, { |
/** |
* Increases the value of the input by 1 |
* |
* @memberOf jsx.dom.widgets.SpinnerInput.prototype |
* @memberOf jsx.dom.widgets.List.prototype |
* @param {any} listItem |
*/ |
inc: function () { |
var v, t = this._target; |
|
if ( (this.maxValue == Infinity || t.value < this.maxValue) |
&& !isNaN(v = parseInt(t.value, 10) + 1) |
&& (t.maxLength < 1 || v.toString().length <= t.maxLength)) |
addItem: function (listItem) { |
if (!this.items) |
{ |
t.value = v; |
this.items = []; |
} |
|
this.items.push(listItem); |
}, |
|
/** |
* Decreases the value of the input by 1 |
* @param {any} listItem |
*/ |
dec: function () { |
var v, t = this._target; |
|
if ( (this.minValue == -Infinity || t.value > this.minValue) |
&& !isNaN(v = parseInt(t.value, 10) - 1) |
&& (t.maxLength < 1 || v.toString().length <= t.maxLength)) |
removeItem: function (item) { |
var items = this.items; |
if (items) |
{ |
t.value = v; |
var i = items.indexOf(item); |
if (i > -1) |
{ |
items.splice(i, 1); |
} |
} |
}, |
|
/** |
* (non-JSdoc) |
* @see jsx.dom.widgets.NumberInput.prototype.update() |
* @see jsx.dom.widgets.List.prototype.update() |
*/ |
update: function () { |
_NumberInput.prototype.update.call(this); |
_List._super.prototype.update.call(this); |
|
var target = this._target; |
if (typeof target.onchange == "function") |
var items = this._items; |
var i; |
var len = items && items.length || 0; |
var itemType = this.itemType || _ListItem; |
|
for (i = len; i--;) |
{ |
target.onchange(); |
var item = items[i]; |
if (item.getTarget().tagName.toUpperCase() != "LI") |
{ |
items[i] = new itemType(null, null, { |
children: [item] |
}); |
} |
|
items[i].update(); |
} |
|
var target = this.getTarget(); |
var listItems = _gEBTN("li", -1, target); |
var len2 = listItems.length; |
for (i = 0; i < len && i < len2; ++i) |
{ |
var listItem = listItems[i]; |
item = items[i]; |
|
if (listItem != item.getTarget()) |
{ |
target.replaceChild(item.getTarget(), listItem); |
} |
} |
|
for (var j = listItems.length; j-- > i;) |
{ |
target.removeChild(listItems[j]); |
} |
|
for (++j; j < len; ++j) |
{ |
items[j].appendTo(this); |
} |
|
return this; |
} |
}); |
|
var _OrderedList = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_OrderedList () { |
jsx_dom_widgets_OrderedList._super.apply(this, arguments); |
} |
).extend(_List, { |
/** |
* @memberOf jsx.dom.widgets.OrderedList.prototype |
*/ |
elementType: "ol" |
}); |
|
/** |
* @function |
*/ |
var _UnorderedList = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_UnorderedList () { |
jsx_dom_widgets_UnorderedList._super.apply(this, arguments); |
} |
).extend(_List, { |
/** |
* @memberOf jsx.dom.widgets.UnorderedList.prototype |
*/ |
elementType: "ul" |
}); |
|
var _CheckboxList = ( |
/** |
* @constructor |
1407,7 → 1461,7 |
} |
|
/* Add the contained checkbox as item */ |
var checkbox = _gEBTN("input", 0, item._target); |
var checkbox = _gEBTN("input", 0, item.getTarget()); |
if (!checkbox|| checkbox.type.toLowerCase() != "checkbox") |
{ |
return jsx.throwThis(jsx.InvalidArgumentError, |
1428,8 → 1482,81 |
} |
}); |
|
var _TreeNode = ( |
function jsx_dom_widgets_TreeNode (oTarget, oParent, oProperties) { |
jsx_dom_widgets_TreeNode._super.apply(this, arguments); |
} |
).extend(_ListItem, { |
init: function () { |
_TreeNode._super.prototype.init.call(this); |
|
this._checkbox = new _Checkbox |
}, |
|
oncollapsechanged: function (collapse) { |
if (this._checkbox) |
{ |
this._checkbox.setChecked = !collapse; |
} |
} |
}); |
|
var _TreeList = ( |
/** |
* @constructor |
*/ |
function jsx_dom_widgets_TreeList (oTarget, oParent, oProperties) { |
jsx_dom_widgets_Tree._super.call(this, oTarget, oParent, oProperties); |
} |
).extend(_UnorderedList, { |
itemType: _TreeNode, |
|
/** |
* @memberOf jsx.dom.widgets.TreeList |
*/ |
addItem: function (item) { |
if (!(item instanceof _TreeNode)) |
{ |
if (!(item instanceof _ListItem)) |
{ |
return jsx.throwThis(jsx.InvalidArgumentError, |
[null, jsx.object.getFunctionName(item.constructor), |
"jsx.dom.widgets.TreeNode or jsx.dom.widgets.ListItem"]); |
} |
|
var node = new _TreeNode(item.getTarget()); |
} |
else |
{ |
node = item; |
} |
|
_TreeList._super.prototype.addItem.call(this, node); |
|
return item; |
} |
}); |
|
var _Tree = ( |
/** |
* A <code>Tree</code> widget is implemented using nested |
* unordered lists and checkboxes: |
* <pre> |
* Tree extends Widget |
* ._root : UnorderedList |
* ._target : HTMLULElement |
* ._items : [TreeNode] |
* |
* TreeNode extends ListItem |
* .target : HTMLLIElement |
* ._checkbox : Checkbox |
* .label |
* .icon |
* .collapsed |
* .childNodes : UnorderedList |
* .target : HTMLULElement |
* .items : [TreeNode] |
* </pre> |
* @constructor |
*/ |
function jsx_dom_widgets_Tree (oTarget, oParent, oProperties) { |
1448,10 → 1575,9 |
init: function () { |
_Tree._super.prototype.init.call(this); |
|
if (!this._list) |
if (!this._root) |
{ |
this._list = new _UnorderedList(); |
this._list.addItem(new _ListItem()); |
this._root = new _TreeList(this.getTarget()); |
} |
}, |
|
1493,7 → 1619,7 |
var id2title = {}; |
var rxSpace = /[ \t\n\x0C\r]+/; |
|
for (var rows = this._target.tBodies[0].rows, i = rows.length; i--;) |
for (var rows = this.getTarget().tBodies[0].rows, i = rows.length; i--;) |
{ |
var row = rows[i]; |
for (var cells = row.cells, j = cells.length; j--;) |
1568,7 → 1694,7 |
|
var expressions = []; |
|
for (var rows = this._target.tBodies[0].rows, i = rows.length; i--;) |
for (var rows = this.getTarget().tBodies[0].rows, i = rows.length; i--;) |
{ |
var row = rows[i]; |
row.style.display = "none"; |
1618,11 → 1744,12 |
}); |
|
/** |
* A <code>Timer</code> widget uses several <code>NumberInput</code> |
* widgets to implement a digital timer. |
* @function |
*/ |
var _Timer=( |
/** |
* A <code>Timer</code> widget uses several <code>NumberInput</code> |
* widgets to implement a digital timer. |
* @constructor |
* @param {Element} oTarget |
* Reference to the DOM object that represents the |
1784,7 → 1911,7 |
console.log("e = ", e); |
if (e) |
{ |
var t = e._target || e.srcElement; |
var t = e.getTarget() || e.srcElement; |
console.log("t = ", t); |
if (t && /^\s*\binput\b\s*$/i.test(t.tagName) |
&& /^\s*\btext\b\s*$/i.test(t.type)) |