home *** CD-ROM | disk | FTP | other *** search
- var pattern = /^(padding(-(left|right|top|bottom))?)|(border(-(left|right|top|bottom))?(-(color|width|style)))?$/;
-
- var gridInheritAttributes = {
- __proto__: null,
- "width": 1,
- "min-width": 1,
- "max-width": 1,
- "height": 1,
- "min-height": 1,
- "max-height": 1,
- "padding": 1,
- "padding-top": 1,
- "padding-right": 1,
- "padding-bottom": 1,
- "padding-left": 1,
- "border": 1,
- "border-width": 1,
- "border-style": 1,
- "border-color": 1,
- "border-top": 1,
- "border-right": 1,
- "border-bottom": 1,
- "border-left": 1,
- "border-top-width": 1,
- "border-right-width": 1,
- "border-bottom-width": 1,
- "border-left-width": 1,
- "border-top-style": 1,
- "border-right-style": 1,
- "border-bottom-style": 1,
- "border-left-style": 1,
- "border-top-color": 1,
- "border-right-color": 1,
- "border-bottom-color": 1,
- "border-left-color": 1,
- "v-align": 1,
- "h-align": 1,
- };
-
- XB.UI.Behaviour.Grid = XB.UI.Behaviour.extend({
- name: "grid",
- nodeName: "table",
- inheritAttributes: gridInheritAttributes,
-
- create: function() {
- this.namespaceURI = XB.UI.consts.STR_HTML_NS;
- this.base();
- },
-
- inheritanceAttributesEx: function(heir, attributes) {
- if (heir.name == "cell") {
- function columnFilter(item) {return item.name == "column";}
- var index = heir.index();
- var columns = this.children().filter(columnFilter);
- if (columns[index]) {
- var column = columns[index];
- attributes = column.inheritanceAttributesEx(heir, attributes);
- }
- }
-
- this.base(heir, attributes);
- }
- });
-
- XB.UI.Behaviour.Column = XB.UI.Behaviour.extend({
- name: "column",
- inheritAttributes: gridInheritAttributes,
-
- append: function () {
- },
-
- inheritanceAttributesEx: function(heir, attributes) {
- var parent = this.parent;
- this.parent = null;
- attributes = this.base(heir, attributes);
- this.parent = parent;
- return attributes;
- },
-
- heirs: function() {
- function rowFilter(item) {return item.name == "row";}
- function cellFilter(item) {return item.name == "cell";}
- var heirs = [],
- index = this.index(),
- rows = this.parent.children().filter(rowFilter);
-
- for each (var row in rows) {
- var cells = row.children().filter(cellFilter);
- if (cells[index])
- heirs.push(cells[index]);
- }
-
- return heirs;
- }
- });
-
- XB.UI.Behaviour.Row = XB.UI.Behaviour.extend({
- name: "row",
- nodeName: "tr",
- inheritAttributes: gridInheritAttributes,
-
- create: function() {
- this.namespaceURI = XB.UI.consts.STR_HTML_NS;
- this.base();
- }
- });
-
- XB.UI.Behaviour.Cell = XB.UI.Behaviour.extend({
- name: "cell",
- nodeName: "td",
- succeedAttributes: gridInheritAttributes,
-
- constructor: function(comment, element, widgetInstanceId, builder) {
- this.base(comment, element, widgetInstanceId, builder);
- this.span = {"left": 0, "up": 0};
- },
-
- create: function() {
- this.namespaceURI = XB.UI.consts.STR_HTML_NS;
- this.base();
- },
-
- append: function() {
- if (!!this.isMerged() == !!this.node.parentNode) {
- if (this.isMerged())
- this.node.parentNode.removeChild(this.node);
- else
- this.base();
- }
- },
-
- onAttribute: function(event) {
- var set = XB._base.runtime.xToBool(event.value);
- switch (event.name) {
- case "merge-left":
- this.change("left", set ? 1 : -1);
- this.updateDisplayMode();
- break;
- case "merge-up":
- this.change("up", set ? 1 : -1);
- this.updateDisplayMode();
- break;
- case "h-align":
- this.node.setAttribute("align", event.value);
- break;
- case "v-align":
- this.node.setAttribute("valign", event.value);
- break;
- default:
- this.node.setAttribute("xb-ui-" + event.name, event.value);
- break;
- }
-
- var name = event.name,
- value = event.value,
- match = null;
-
- if (name in gridInheritAttributes) {
- if (!isNaN(parseInt(value, 10)))
- value = parseInt(value, 10) + "px";
- this.node.style[misc.camelize(name)] = value;
-
- return;
- }
-
- },
-
- change: function(direction, delta) {
- this.span[direction] += delta;
- if (this.isMerge(direction))
- this.sibling(direction).change(direction, delta);
- this.updateDisplayMode();
- },
-
- updateDisplayMode: function() {
- this.append();
- if (!this.isMerged()) {
- var map = {"up": "rowspan", "left": "colspan"};
-
- for (var i in map)
- if (this.span[i] > 0)
- this.node.setAttribute(map[i], this.span[i] + 1);
- else
- this.node.removeAttribute(map[i]);
- }
- },
-
- isMerge: function(direction) {
- var name = "merge-" + direction;
- return this.attribute[name] && XB._base.runtime.xToBool(this.attribute[name]);
- },
-
- isMerged: function() {
- return this.isMerge("left") || this.isMerge("up");
- },
-
- sibling: function(direction) {
- function isCellComment(node) {
- return node &&
- (node.nodeType == node.COMMENT_NODE) &&
- (node.behaviour) &&
- (node.behaviour.name == "cell");
- }
-
- var comment = this.comment;
-
- if (direction == "left") {
- while (comment = comment.previousSibling)
- if (isCellComment(comment))
- return comment.behaviour;
- }
-
- if (direction == "up") {
- var number = 0;
- while (comment = comment.previousSibling)
- if (isCellComment(comment))
- number ++;
- var tr = this.comment.parentNode;
-
- while (tr = tr.previousSibling)
- if (tr.localName == "tr")
- break;
-
- comment = tr.firstChild;
- do {
- if (isCellComment(comment))
- if (number == 0) {
- return comment.behaviour;
- }
- else
- number --;
- } while (comment && (comment = comment.nextSibling));
- }
-
- return null;
- }
- });