home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / filFD2A3DD7719CE1372B648DC53AEE4DBA < prev    next >
Text File  |  2010-07-12  |  7KB  |  237 lines

  1. var pattern = /^(padding(-(left|right|top|bottom))?)|(border(-(left|right|top|bottom))?(-(color|width|style)))?$/;
  2.  
  3. var gridInheritAttributes = {
  4.     __proto__: null,
  5.     "width": 1,
  6.     "min-width": 1,
  7.     "max-width": 1,
  8.     "height": 1,
  9.     "min-height": 1,
  10.     "max-height": 1,
  11.     "padding": 1,
  12.     "padding-top": 1,
  13.     "padding-right": 1,
  14.     "padding-bottom": 1,
  15.     "padding-left": 1,
  16.     "border": 1,
  17.     "border-width": 1,
  18.     "border-style": 1,
  19.     "border-color": 1,
  20.     "border-top": 1,
  21.     "border-right": 1,
  22.     "border-bottom": 1,
  23.     "border-left": 1,
  24.     "border-top-width": 1,
  25.     "border-right-width": 1,
  26.     "border-bottom-width": 1,
  27.     "border-left-width": 1,
  28.     "border-top-style": 1,
  29.     "border-right-style": 1,
  30.     "border-bottom-style": 1,
  31.     "border-left-style": 1,
  32.     "border-top-color": 1,
  33.     "border-right-color": 1,
  34.     "border-bottom-color": 1,
  35.     "border-left-color": 1,
  36.     "v-align": 1,
  37.     "h-align": 1,
  38. };
  39.  
  40. XB.UI.Behaviour.Grid = XB.UI.Behaviour.extend({
  41.     name: "grid",
  42.     nodeName: "table",
  43.     inheritAttributes: gridInheritAttributes,
  44.     
  45.     create: function() {
  46.         this.namespaceURI = XB.UI.consts.STR_HTML_NS;
  47.         this.base();
  48.     },
  49.     
  50.     inheritanceAttributesEx: function(heir, attributes) {
  51.         if (heir.name == "cell") {
  52.             function columnFilter(item) {return item.name == "column";}
  53.             var index = heir.index();
  54.             var columns = this.children().filter(columnFilter);
  55.             if (columns[index]) {
  56.                 var column = columns[index];
  57.                 attributes = column.inheritanceAttributesEx(heir, attributes);
  58.             }
  59.         }
  60.         
  61.         this.base(heir, attributes);
  62.     }
  63. });
  64.  
  65. XB.UI.Behaviour.Column = XB.UI.Behaviour.extend({
  66.     name: "column",
  67.     inheritAttributes: gridInheritAttributes,
  68.     
  69.     append: function () {
  70.     },
  71.     
  72.     inheritanceAttributesEx: function(heir, attributes) {
  73.         var parent = this.parent;
  74.         this.parent = null;
  75.         attributes = this.base(heir, attributes);
  76.         this.parent = parent;
  77.         return attributes;
  78.     },
  79.     
  80.     heirs: function() {
  81.         function rowFilter(item) {return item.name == "row";}
  82.         function cellFilter(item) {return item.name == "cell";}
  83.         var heirs = [],
  84.             index = this.index(),
  85.             rows = this.parent.children().filter(rowFilter);
  86.         
  87.         for each (var row in rows) {
  88.             var cells = row.children().filter(cellFilter);
  89.             if (cells[index])
  90.                 heirs.push(cells[index]);
  91.         }
  92.         
  93.         return heirs;
  94.     }
  95. });
  96.  
  97. XB.UI.Behaviour.Row = XB.UI.Behaviour.extend({
  98.     name: "row",
  99.     nodeName: "tr",
  100.     inheritAttributes: gridInheritAttributes,
  101.     
  102.     create: function() {
  103.         this.namespaceURI = XB.UI.consts.STR_HTML_NS;
  104.         this.base();
  105.     }
  106. });
  107.  
  108. XB.UI.Behaviour.Cell = XB.UI.Behaviour.extend({
  109.     name: "cell",
  110.     nodeName: "td",
  111.     succeedAttributes: gridInheritAttributes,
  112.     
  113.     constructor: function(comment, element, widgetInstanceId, builder) {
  114.         this.base(comment, element, widgetInstanceId, builder);
  115.         this.span = {"left": 0, "up": 0};
  116.     },
  117.     
  118.     create: function() {
  119.         this.namespaceURI = XB.UI.consts.STR_HTML_NS;
  120.         this.base();
  121.     },
  122.     
  123.     append: function() {
  124.         if (!!this.isMerged() == !!this.node.parentNode) {
  125.             if (this.isMerged())
  126.                 this.node.parentNode.removeChild(this.node);
  127.             else
  128.                 this.base();
  129.         }
  130.     },
  131.     
  132.     onAttribute: function(event) {
  133.         var set = XB._base.runtime.xToBool(event.value);
  134.         switch (event.name) {
  135.             case "merge-left":
  136.                 this.change("left", set ? 1 : -1);
  137.                 this.updateDisplayMode();
  138.                 break;
  139.             case "merge-up":
  140.                 this.change("up", set ? 1 : -1);
  141.                 this.updateDisplayMode();
  142.                 break;
  143.             case "h-align":
  144.                 this.node.setAttribute("align", event.value);
  145.                 break;
  146.             case "v-align":
  147.                 this.node.setAttribute("valign", event.value);
  148.                 break;
  149.             default:
  150.                 this.node.setAttribute("xb-ui-" + event.name, event.value);
  151.             break;
  152.         }
  153.         
  154.         var name = event.name,
  155.             value = event.value,
  156.             match = null;
  157.         
  158.         if (name in gridInheritAttributes) {
  159.             if (!isNaN(parseInt(value, 10)))
  160.                 value = parseInt(value, 10) + "px";
  161.             this.node.style[misc.camelize(name)] = value;
  162.             
  163.             return;
  164.         }
  165.         
  166.     },
  167.     
  168.     change: function(direction, delta) {
  169.         this.span[direction] += delta;
  170.         if (this.isMerge(direction))
  171.             this.sibling(direction).change(direction, delta);
  172.         this.updateDisplayMode();
  173.     },
  174.     
  175.     updateDisplayMode: function() {
  176.         this.append();
  177.         if (!this.isMerged()) {
  178.             var map = {"up": "rowspan", "left": "colspan"};
  179.             
  180.             for (var i in map)
  181.                 if (this.span[i] > 0)
  182.                     this.node.setAttribute(map[i], this.span[i] + 1);
  183.                 else
  184.                     this.node.removeAttribute(map[i]);
  185.         }
  186.     },
  187.     
  188.     isMerge: function(direction) {
  189.         var name = "merge-" + direction;
  190.         return this.attribute[name] && XB._base.runtime.xToBool(this.attribute[name]);
  191.     },
  192.     
  193.     isMerged: function() {
  194.         return this.isMerge("left") || this.isMerge("up");
  195.     },
  196.     
  197.     sibling: function(direction) {
  198.         function isCellComment(node) {
  199.             return node && 
  200.                 (node.nodeType == node.COMMENT_NODE) &&
  201.                 (node.behaviour) &&
  202.                 (node.behaviour.name == "cell");
  203.         }
  204.         
  205.         var comment = this.comment;
  206.         
  207.         if (direction == "left") {
  208.             while (comment = comment.previousSibling)
  209.                 if (isCellComment(comment))
  210.                     return comment.behaviour;
  211.         }
  212.         
  213.         if (direction == "up") {
  214.             var number = 0;
  215.             while (comment = comment.previousSibling)
  216.                 if (isCellComment(comment))
  217.                     number ++;
  218.             var tr = this.comment.parentNode;
  219.             
  220.             while (tr = tr.previousSibling)
  221.                 if (tr.localName == "tr")
  222.                     break;
  223.             
  224.             comment = tr.firstChild;
  225.             do {
  226.                 if (isCellComment(comment))
  227.                     if (number == 0) {
  228.                         return comment.behaviour;
  229.                     }
  230.                     else
  231.                         number --;
  232.             } while (comment && (comment = comment.nextSibling));
  233.         }
  234.         
  235.         return null;
  236.     }
  237. });