Debian Codegraph @

dojox/grid/_Builder.js

raw symbols SCIP
1 define([
2 "../main",
3 "dojo/_base/array",
4 "dojo/_base/lang",
5 "dojo/_base/window",
6 "dojo/_base/event",
7 "dojo/_base/sniff",
8 "dojo/_base/connect",
9 "dojo/dnd/Moveable",
10 "dojox/html/metrics",
11 "./util",
12 "dojo/_base/html",
13 "dojo/dom-geometry"
14 ], function(dojox, array, lang, win, event, has, connect, Moveable, metrics, util, html, domGeometry){
15
16 var dg = dojox.grid;
17
18 var getTdIndex = function(td){
19 return td.cellIndex >=0 ? td.cellIndex : array.indexOf(td.parentNode.cells, td);
20 };
21
22 var getTrIndex = function(tr){
23 return tr.rowIndex >=0 ? tr.rowIndex : array.indexOf(tr.parentNode.childNodes, tr);
24 };
25
26 var getTr = function(rowOwner, index){
27 return rowOwner && ((rowOwner.rows||0)[index] || rowOwner.childNodes[index]);
28 };
29
30 var findTable = function(node){
31 for(var n=node; n && n.tagName!='TABLE'; n=n.parentNode){}
32 return n;
33 };
34
35 var ascendDom = function(inNode, inWhile){
36 for(var n=inNode; n && inWhile(n); n=n.parentNode){}
37 return n;
38 };
39
40 var makeNotTagName = function(inTagName){
41 var name = inTagName.toUpperCase();
42 return function(node){ return node.tagName != name; };
43 };
44
45 var rowIndexTag = util.rowIndexTag;
46 var gridViewTag = util.gridViewTag;
47
48 // base class for generating markup for the views
49 var _Builder = dg._Builder = lang.extend(function(view){
50 if(view){
51 this.view = view;
52 this.grid = view.grid;
53 }
54 },{
55 view: null,
56 // boilerplate HTML
57 _table: '<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation"',
58
59 // Returns the table variable as an array - and with the view width, if specified
60 getTableArray: function(){
61 var html = [this._table];
62 if(this.view.viewWidth){
63 html.push([' style="width:', this.view.viewWidth, ';"'].join(''));
64 }
65 html.push('>');
66 return html;
67 },
68
69 // generate starting tags for a cell
70 generateCellMarkup: function(inCell, inMoreStyles, inMoreClasses, isHeader){
71 var result = [], html;
72 if(isHeader){
73 var sortInfo = inCell.index != inCell.grid.getSortIndex() ? "" : inCell.grid.sortInfo > 0 ? 'aria-sort="ascending"' : 'aria-sort="descending"';
74 if (!inCell.id){
75 inCell.id = this.grid.id + "Hdr" + inCell.index;
76 }
77 // column headers are not editable, mark as aria-readonly=true
78 html = ['<th tabIndex="-1" aria-readonly="true" role="columnheader"', sortInfo, ' id="', inCell.id, '"'];
79 }else{
80 // cells inherit grid aria-readonly property; default value for aria-readonly is false(grid is editable)
81 // if grid is editable (had any editable cells), mark non editable cells as aria-readonly=true
82 // if no editable cells, grid's aria-readonly value will have been set to true and cells will inherit
83 var editInfo = this.grid.editable && !inCell.editable ? 'aria-readonly="true"' : "";
84 html = ['<td tabIndex="-1" role="gridcell"', editInfo];
85 }
86 if(inCell.colSpan){
87 html.push(' colspan="', inCell.colSpan, '"');
88 }
89 if(inCell.rowSpan){
90 html.push(' rowspan="', inCell.rowSpan, '"');
91 }
92 html.push(' class="dojoxGridCell ');
93 if(inCell.classes){
94 html.push(inCell.classes, ' ');
95 }
96 if(inMoreClasses){
97 html.push(inMoreClasses, ' ');
98 }
99 // result[0] => td opener, style
100 result.push(html.join(''));
101 // SLOT: result[1] => td classes
102 result.push('');
103 html = ['" idx="', inCell.index, '" style="'];
104 if(inMoreStyles && inMoreStyles[inMoreStyles.length-1] != ';'){
105 inMoreStyles += ';';
106 }
107 html.push(inCell.styles, inMoreStyles||'', inCell.hidden?'display:none;':'');
108 if(inCell.unitWidth){
109 html.push('width:', inCell.unitWidth, ';');
110 }
111 // result[2] => markup
112 result.push(html.join(''));
113 // SLOT: result[3] => td style
114 result.push('');
115 html = [ '"' ];
116 if(inCell.attrs){
117 html.push(" ", inCell.attrs);
118 }
119 html.push('>');
120 // result[4] => td postfix
121 result.push(html.join(''));
122 // SLOT: result[5] => content
123 result.push('');
124 // result[6] => td closes
125 result.push(isHeader?'</th>':'</td>');
126 return result; // Array
127 },
128
129 // cell finding
130 isCellNode: function(inNode){
131 return Boolean(inNode && inNode!=win.doc && html.attr(inNode, "idx"));
132 },
133
134 getCellNodeIndex: function(inCellNode){
135 return inCellNode ? Number(html.attr(inCellNode, "idx")) : -1;
136 },
137
138 getCellNode: function(inRowNode, inCellIndex){
139 for(var i=0, row; ((row = getTr(inRowNode.firstChild, i)) && row.cells); i++){
140 for(var j=0, cell; (cell = row.cells[j]); j++){
141 if(this.getCellNodeIndex(cell) == inCellIndex){
142 return cell;
143 }
144 }
145 }
146 return null;
147 },
148
149 findCellTarget: function(inSourceNode, inTopNode){
150 var n = inSourceNode;
151 while(n && (!this.isCellNode(n) || (n.offsetParent && gridViewTag in n.offsetParent.parentNode && n.offsetParent.parentNode[gridViewTag] != this.view.id)) && (n!=inTopNode)){
152 n = n.parentNode;
153 }
154 return n!=inTopNode ? n : null;
155 },
156
157 // event decoration
158 baseDecorateEvent: function(e){
159 e.dispatch = 'do' + e.type;
160 e.grid = this.grid;
161 e.sourceView = this.view;
162 e.cellNode = this.findCellTarget(e.target, e.rowNode);
163 e.cellIndex = this.getCellNodeIndex(e.cellNode);
164 e.cell = (e.cellIndex >= 0 ? this.grid.getCell(e.cellIndex) : null);
165 },
166
167 // event dispatch
168 findTarget: function(inSource, inTag){
169 var n = inSource;
170 while(n && (n!=this.domNode) && (!(inTag in n) || (gridViewTag in n && n[gridViewTag] != this.view.id))){
171 n = n.parentNode;
172 }
173 return (n != this.domNode) ? n : null;
174 },
175
176 findRowTarget: function(inSource){
177 return this.findTarget(inSource, rowIndexTag);
178 },
179
180 isIntraNodeEvent: function(e){
181 try{
182 return (e.cellNode && e.relatedTarget && html.isDescendant(e.relatedTarget, e.cellNode));
183 }catch(x){
184 // e.relatedTarget has permission problem in FF if it's an input: https://bugzilla.mozilla.org/show_bug.cgi?id=208427
185 return false;
186 }
187 },
188
189 isIntraRowEvent: function(e){
190 try{
191 var row = e.relatedTarget && this.findRowTarget(e.relatedTarget);
192 return !row && (e.rowIndex==-1) || row && (e.rowIndex==row.gridRowIndex);
193 }catch(x){
194 // e.relatedTarget on INPUT has permission problem in FF: https://bugzilla.mozilla.org/show_bug.cgi?id=208427
195 return false;
196 }
197 },
198
199 dispatchEvent: function(e){
200 if(e.dispatch in this){
201 return this[e.dispatch](e);
202 }
203 return false;
204 },
205
206 // dispatched event handlers
207 domouseover: function(e){
208 if(e.cellNode && (e.cellNode!=this.lastOverCellNode)){
209 this.lastOverCellNode = e.cellNode;
210 this.grid.onMouseOver(e);
211 }
212 this.grid.onMouseOverRow(e);
213 },
214
215 domouseout: function(e){
216 if(e.cellNode && (e.cellNode==this.lastOverCellNode) && !this.isIntraNodeEvent(e, this.lastOverCellNode)){
217 this.lastOverCellNode = null;
218 this.grid.onMouseOut(e);
219 if(!this.isIntraRowEvent(e)){
220 this.grid.onMouseOutRow(e);
221 }
222 }
223 },
224
225 domousedown: function(e){
226 if (e.cellNode)
227 this.grid.onMouseDown(e);
228 this.grid.onMouseDownRow(e);
229 },
230
231 _getTextDirStyle: function(textDir, inCell, inRowIndex){
232 // summary:
233 // Get BiDi text dir, just a placeholder, defined in dojox/grid/bidi/_BidiMixin
234 return "";
235 }
236 });
237
238 // Produces html for grid data content. Owned by grid and used internally
239 // for rendering data. Override to implement custom rendering.
240 var _ContentBuilder = dg._ContentBuilder = lang.extend(function(view){
241 _Builder.call(this, view);
242 },_Builder.prototype,{
243 update: function(){
244 this.prepareHtml();
245 },
246
247 // cache html for rendering data rows
248 prepareHtml: function(){
249 var defaultGet=this.grid.get, cells=this.view.structure.cells;
250 for(var j=0, row; (row=cells[j]); j++){
251 for(var i=0, cell; (cell=row[i]); i++){
252 cell.get = cell.get || (cell.value == undefined) && defaultGet;
253 cell.markup = this.generateCellMarkup(cell, cell.cellStyles, cell.cellClasses, false);
254 if (!this.grid.editable && cell.editable){
255 this.grid.editable = true;
256 }
257 }
258 }
259 },
260
261 // time critical: generate html using cache and data source
262 generateHtml: function(inDataIndex, inRowIndex){
263 var html = this.getTableArray();
264 var v = this.view;
265 var cells = v.structure.cells;
266 var item = this.grid.getItem(inRowIndex);
267 var dir;
268
269 util.fire(this.view, "onBeforeRow", [inRowIndex, cells]);
270 for(var j=0, row; (row = cells[j]); j++){
271 if(row.hidden || row.header){
272 continue;
273 }
274 html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">');
275 for(var i=0, cell, m, cc, cs; (cell=row[i]); i++){
276 m = cell.markup;
277 cc = cell.customClasses = [];
278 cs = cell.customStyles = [];
279
280 // content (format can fill in cc and cs as side-effects)
281 m[5] = cell.format(inRowIndex, item);
282 // classes
283 m[1] = cc.join(' ');
284 // styles
285 m[3] = cs.join(';');
286 dir = cell.textDir || this.grid.textDir;
287 if (dir) {
288 m[3] += this._getTextDirStyle(dir, cell, inRowIndex);
289 }
290 // in-place concat
291 html.push.apply(html, m);
292 }
293 html.push('</tr>');
294 }
295 html.push('</table>');
296 return html.join(''); // String
297 },
298
299 decorateEvent: function(e){
300 e.rowNode = this.findRowTarget(e.target);
301 if(!e.rowNode){return false;}
302 e.rowIndex = e.rowNode[rowIndexTag];
303 this.baseDecorateEvent(e);
304 e.cell = this.grid.getCell(e.cellIndex);
305 return true; // Boolean
306 }
307 });
308
309 // Produces html for grid header content. Owned by grid and used internally
310 // for rendering data. Override to implement custom rendering.
311 var _HeaderBuilder = dg._HeaderBuilder = lang.extend(function(view){
312 this.moveable = null;
313 _Builder.call(this, view);
314 },_Builder.prototype,{
315 _skipBogusClicks: false,
316 overResizeWidth: 4,
317 minColWidth: 1,
318
319 update: function(){
320 if(this.tableMap){
321 this.tableMap.mapRows(this.view.structure.cells);
322 }else{
323 this.tableMap = new dg._TableMap(this.view.structure.cells);
324 }
325 },
326
327 generateHtml: function(inGetValue, inValue){
328 var dir, html = this.getTableArray(), cells = this.view.structure.cells;
329
330 util.fire(this.view, "onBeforeRow", [-1, cells]);
331 for(var j=0, row; (row=cells[j]); j++){
332 if(row.hidden){
333 continue;
334 }
335 html.push(!row.invisible ? '<tr>' : '<tr class="dojoxGridInvisible">');
336 for(var i=0, cell, markup; (cell=row[i]); i++){
337 cell.customClasses = [];
338 cell.customStyles = [];
339 if(this.view.simpleStructure){
340 if(cell.draggable){
341 if(cell.headerClasses){
342 if(cell.headerClasses.indexOf('dojoDndItem') == -1){
343 cell.headerClasses += ' dojoDndItem';
344 }
345 }else{
346 cell.headerClasses = 'dojoDndItem';
347 }
348 }
349 if(cell.attrs){
350 if(cell.attrs.indexOf("dndType='gridColumn_") == -1){
351 cell.attrs += " dndType='gridColumn_" + this.grid.id + "'";
352 }
353 }else{
354 cell.attrs = "dndType='gridColumn_" + this.grid.id + "'";
355 }
356 }
357 markup = this.generateCellMarkup(cell, cell.headerStyles, cell.headerClasses, true);
358 // content
359 markup[5] = (inValue != undefined ? inValue : inGetValue(cell));
360 // styles
361 markup[3] = cell.customStyles.join(';');
362 dir = cell.textDir || this.grid.textDir;
363 if(dir){
364 markup[3] += this._getTextDirStyle(dir, cell, inValue);
365 }
366 // classes
367 markup[1] = cell.customClasses.join(' '); //(cell.customClasses ? ' ' + cell.customClasses : '');
368 html.push(markup.join(''));
369 }
370 html.push('</tr>');
371 }
372 html.push('</table>');
373 return html.join('');
374 },
375
376 // event helpers
377 getCellX: function(e){
378 var n, x, pos;
379 // Calculate starting x position
380 n = ascendDom(e.target, makeNotTagName("th"));
381 if(n){
382 // We have a proper parent node, use that for position
383 pos = domGeometry.position(n);
384 x = e.clientX - pos.x;
385 }else{
386 // Fall back to layerX
387 x = e.layerX;
388 }
389 return x;
390 },
391
392 // event decoration
393 decorateEvent: function(e){
394 this.baseDecorateEvent(e);
395 e.rowIndex = -1;
396 e.cellX = this.getCellX(e);
397 return true;
398 },
399
400 // event handlers
401 // resizing
402 prepareResize: function(e, mod){
403 do{
404 var i = e.cellIndex;
405 e.cellNode = (i ? e.cellNode.parentNode.cells[i+mod] : null);
406 e.cellIndex = (e.cellNode ? this.getCellNodeIndex(e.cellNode) : -1);
407 }while(e.cellNode && e.cellNode.style.display == "none");
408 return Boolean(e.cellNode);
409 },
410
411 canResize: function(e){
412 if(!e.cellNode || e.cellNode.colSpan > 1){
413 return false;
414 }
415 var cell = this.grid.getCell(e.cellIndex);
416 return !cell.noresize && cell.canResize();
417 },
418
419 overLeftResizeArea: function(e){
420 // We are never over a resize area if we are in the process of moving
421 if(html.hasClass(win.body(), "dojoDndMove")){
422 return false;
423 }
424 //Bugfix for crazy IE problem (#8807). IE returns position information for the icon and text arrow divs
425 //as if they were still on the left instead of returning the position they were 'float: right' to.
426 //So, the resize check ends up checking the wrong adjacent cell. This checks to see if the hover was over
427 //the image or text nodes, then just ignored them/treat them not in scale range.
428 if(has('ie')){
429 var tN = e.target;
430 if(html.hasClass(tN, "dojoxGridArrowButtonNode") ||
431 html.hasClass(tN, "dojoxGridArrowButtonChar") ||
432 html.hasClass(tN, "dojoxGridColCaption")){
433 return false;
434 }
435 }
436
437 if(this.grid.isLeftToRight()){
438 return (e.cellIndex>0) && (e.cellX > 0 && e.cellX < this.overResizeWidth) && this.prepareResize(e, -1);
439 }
440 var t = e.cellNode && (e.cellX > 0 && e.cellX < this.overResizeWidth);
441 return t;
442 },
443
444 overRightResizeArea: function(e){
445 // We are never over a resize area if we are in the process of moving
446 if(html.hasClass(win.body(), "dojoDndMove")){
447 return false;
448 }
449 //Bugfix for crazy IE problem (#8807). IE returns position information for the icon and text arrow divs
450 //as if they were still on the left instead of returning the position they were 'float: right' to.
451 //So, the resize check ends up checking the wrong adjacent cell. This checks to see if the hover was over
452 //the image or text nodes, then just ignored them/treat them not in scale range.
453 if(has('ie')){
454 var tN = e.target;
455 if(html.hasClass(tN, "dojoxGridArrowButtonNode") ||
456 html.hasClass(tN, "dojoxGridArrowButtonChar") ||
457 html.hasClass(tN, "dojoxGridColCaption")){
458 return false;
459 }
460 }
461
462 if(this.grid.isLeftToRight()){
463 return e.cellNode && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth);
464 }
465 return (e.cellIndex>0) && (e.cellX >= e.cellNode.offsetWidth - this.overResizeWidth) && this.prepareResize(e, -1);
466 },
467
468 domousemove: function(e){
469 //console.log(e.cellIndex, e.cellX, e.cellNode.offsetWidth);
470 if(!this.moveable){
471 var c = (this.overRightResizeArea(e) ? 'dojoxGridColResize' : (this.overLeftResizeArea(e) ? 'dojoxGridColResize' : ''));
472 if(c && !this.canResize(e)){
473 c = 'dojoxGridColNoResize';
474 }
475 html.toggleClass(e.sourceView.headerNode, "dojoxGridColNoResize", (c == "dojoxGridColNoResize"));
476 html.toggleClass(e.sourceView.headerNode, "dojoxGridColResize", (c == "dojoxGridColResize"));
477 if(c){
478 event.stop(e);
479 }
480 }
481 },
482
483 domousedown: function(e){
484 if(!this.moveable){
485 if((this.overRightResizeArea(e) || this.overLeftResizeArea(e)) && this.canResize(e)){
486 this.beginColumnResize(e);
487 }else{
488 this.grid.onMouseDown(e);
489 this.grid.onMouseOverRow(e);
490 }
491 //else{
492 // this.beginMoveColumn(e);
493 //}
494 }
495 },
496
497 doclick: function(e) {
498 if(this._skipBogusClicks){
499 event.stop(e);
500 return true;
501 }
502 return false;
503 },
504
505 // column resizing
506 colResizeSetup: function(/*Event Object*/e, /*boolean*/ isMouse ){
507 //Set up the drag object for column resizing
508 // Called with mouse event in case of drag and drop,
509 // Also called from keyboard shift-arrow event when focus is on a header
510 var headContentBox = html.contentBox(e.sourceView.headerNode);
511
512 if(isMouse){ //IE draws line even with no mouse down so separate from keyboard
513 this.lineDiv = document.createElement('div');
514
515 var vw = html.position(e.sourceView.headerNode, true);
516 var bodyContentBox = html.contentBox(e.sourceView.domNode);
517 //fix #11340
518 var l = e.pageX;
519 if(!this.grid.isLeftToRight() && has('ie') < 8){
520 l -= metrics.getScrollbar().w;
521 }
522 html.style(this.lineDiv, {
523 top: vw.y + "px",
524 left: l + "px",
525 height: (bodyContentBox.h + headContentBox.h) + "px"
526 });
527 html.addClass(this.lineDiv, "dojoxGridResizeColLine");
528 this.lineDiv._origLeft = l;
529 win.body().appendChild(this.lineDiv);
530 }
531 var spanners = [], nodes = this.tableMap.findOverlappingNodes(e.cellNode);
532 for(var i=0, cell; (cell=nodes[i]); i++){
533 spanners.push({ node: cell, index: this.getCellNodeIndex(cell), width: cell.offsetWidth });
534 //console.log("spanner: " + this.getCellNodeIndex(cell));
535 }
536
537 var view = e.sourceView;
538 var adj = this.grid.isLeftToRight() ? 1 : -1;
539 var views = e.grid.views.views;
540 var followers = [];
541 for(var j=view.idx+adj, cView; (cView=views[j]); j=j+adj){
542 followers.push({ node: cView.headerNode, left: window.parseInt(cView.headerNode.style.left) });
543 }
544 var table = view.headerContentNode.firstChild;
545 var drag = {
546 scrollLeft: e.sourceView.headerNode.scrollLeft,
547 view: view,
548 node: e.cellNode,
549 index: e.cellIndex,
550 w: html.contentBox(e.cellNode).w,
551 vw: headContentBox.w,
552 table: table,
553 tw: html.contentBox(table).w,
554 spanners: spanners,
555 followers: followers
556 };
557 return drag;
558 },
559 beginColumnResize: function(e){
560 this.moverDiv = document.createElement("div");
561 html.style(this.moverDiv,{position: "absolute", left:0}); // to make DnD work with dir=rtl
562 win.body().appendChild(this.moverDiv);
563 html.addClass(this.grid.domNode, "dojoxGridColumnResizing");
564 var m = (this.moveable = new Moveable(this.moverDiv));
565
566 var drag = this.colResizeSetup(e,true);
567
568 m.onMove = lang.hitch(this, "doResizeColumn", drag);
569
570 connect.connect(m, "onMoveStop", lang.hitch(this, function(){
571 this.endResizeColumn(drag);
572 if(drag.node.releaseCapture){
573 drag.node.releaseCapture();
574 }
575 this.moveable.destroy();
576 delete this.moveable;
577 this.moveable = null;
578 html.removeClass(this.grid.domNode, "dojoxGridColumnResizing");
579 }));
580
581 if(e.cellNode.setCapture){
582 e.cellNode.setCapture();
583 }
584 m.onMouseDown(e);
585 },
586
587 doResizeColumn: function(inDrag, mover, leftTop){
588 var changeX = leftTop.l;
589 var data = {
590 deltaX: changeX,
591 w: inDrag.w + (this.grid.isLeftToRight() ? changeX : -changeX),//fix #11341
592 vw: inDrag.vw + changeX,
593 tw: inDrag.tw + changeX
594 };
595
596 this.dragRecord = {inDrag: inDrag, mover: mover, leftTop:leftTop};
597
598 if(data.w >= this.minColWidth){
599 if (!mover) { // we are using keyboard do immediate resize
600 this.doResizeNow(inDrag, data);
601 }
602 else{
603 html.style(this.lineDiv, "left", (this.lineDiv._origLeft + data.deltaX) + "px");
604 }
605 }
606 },
607
608 endResizeColumn: function(inDrag){
609 if(this.dragRecord){
610 var leftTop = this.dragRecord.leftTop;
611 var changeX = this.grid.isLeftToRight() ? leftTop.l : -leftTop.l;
612 // Make sure we are not under our minimum
613 // http://bugs.dojotoolkit.org/ticket/9390
614 changeX += Math.max(inDrag.w + changeX, this.minColWidth) - (inDrag.w + changeX);
615 if(has('webkit') && inDrag.spanners.length){
616 // Webkit needs the pad border extents back in
617 changeX += html._getPadBorderExtents(inDrag.spanners[0].node).w;
618 }
619 var data = {
620 deltaX: changeX,
621 w: inDrag.w + changeX,
622 vw: inDrag.vw + changeX,
623 tw: inDrag.tw + changeX
624 };
625 // Only resize the columns when the drag has finished
626 this.doResizeNow(inDrag, data);
627 delete this.dragRecord;
628 }
629
630 html.destroy(this.lineDiv);
631 html.destroy(this.moverDiv);
632 html.destroy(this.moverDiv);
633 delete this.moverDiv;
634 this._skipBogusClicks = true;
635 inDrag.view.update();
636 this._skipBogusClicks = false;
637 this.grid.onResizeColumn(inDrag.index);
638 },
639 doResizeNow: function(inDrag, data){
640 inDrag.view.convertColPctToFixed();
641 if(inDrag.view.flexCells && !inDrag.view.testFlexCells()){
642 var t = findTable(inDrag.node);
643 if(t){
644 (t.style.width = '');
645 }
646 }
647 var i, s, sw, f, fl;
648 for(i=0; (s=inDrag.spanners[i]); i++){
649 sw = s.width + data.deltaX;
650 if(sw > 0){
651 s.node.style.width = sw + 'px';
652 inDrag.view.setColWidth(s.index, sw);
653 }
654 }
655 if(this.grid.isLeftToRight() || !has('ie')){//fix #11339
656 for(i=0; (f=inDrag.followers[i]); i++){
657 fl = f.left + data.deltaX;
658 f.node.style.left = fl + 'px';
659 }
660 }
661 inDrag.node.style.width = data.w + 'px';
662 inDrag.view.setColWidth(inDrag.index, data.w);
663 inDrag.view.headerNode.style.width = data.vw + 'px';
664 inDrag.view.setColumnsWidth(data.tw);
665 if(!this.grid.isLeftToRight()){
666 inDrag.view.headerNode.scrollLeft = inDrag.scrollLeft + data.deltaX;
667 }
668 }
669 });
670
671 // Maps an html table into a structure parsable for information about cell row and col spanning.
672 // Used by HeaderBuilder.
673 dg._TableMap = lang.extend(function(rows){
674 this.mapRows(rows);
675 },{
676 map: null,
677
678 mapRows: function(inRows){
679 // summary:
680 // Map table topography
681
682 //console.log('mapRows');
683 // # of rows
684 var rowCount = inRows.length;
685 if(!rowCount){
686 return;
687 }
688 // map which columns and rows fill which cells
689 this.map = [];
690 var row;
691 for(var k=0; (row=inRows[k]); k++){
692 this.map[k] = [];
693 }
694 for(var j=0; (row=inRows[j]); j++){
695 for(var i=0, x=0, cell, colSpan, rowSpan; (cell=row[i]); i++){
696 while(this.map[j][x]){x++;}
697 this.map[j][x] = { c: i, r: j };
698 rowSpan = cell.rowSpan || 1;
699 colSpan = cell.colSpan || 1;
700 for(var y=0; y<rowSpan; y++){
701 for(var s=0; s<colSpan; s++){
702 this.map[j+y][x+s] = this.map[j][x];
703 }
704 }
705 x += colSpan;
706 }
707 }
708 //this.dumMap();
709 },
710
711 dumpMap: function(){
712 for(var j=0, row, h=''; (row=this.map[j]); j++,h=''){
713 for(var i=0, cell; (cell=row[i]); i++){
714 h += cell.r + ',' + cell.c + ' ';
715 }
716 }
717 },
718
719 getMapCoords: function(inRow, inCol){
720 // summary:
721 // Find node's map coords by it's structure coords
722 for(var j=0, row; (row=this.map[j]); j++){
723 for(var i=0, cell; (cell=row[i]); i++){
724 if(cell.c==inCol && cell.r == inRow){
725 return { j: j, i: i };
726 }
727 //else{console.log(inRow, inCol, ' : ', i, j, " : ", cell.r, cell.c); };
728 }
729 }
730 return { j: -1, i: -1 };
731 },
732
733 getNode: function(inTable, inRow, inCol){
734 // summary:
735 // Find a node in inNode's table with the given structure coords
736 var row = inTable && inTable.rows[inRow];
737 return row && row.cells[inCol];
738 },
739
740 _findOverlappingNodes: function(inTable, inRow, inCol){
741 var nodes = [];
742 var m = this.getMapCoords(inRow, inCol);
743 //console.log("node j: %d, i: %d", m.j, m.i);
744 for(var j=0, row; (row=this.map[j]); j++){
745 if(j == m.j){ continue; }
746 var rw = row[m.i];
747 //console.log("overlaps: r: %d, c: %d", rw.r, rw.c);
748 var n = (rw?this.getNode(inTable, rw.r, rw.c):null);
749 if(n){ nodes.push(n); }
750 }
751 //console.log(nodes);
752 return nodes;
753 },
754
755 findOverlappingNodes: function(inNode){
756 return this._findOverlappingNodes(findTable(inNode), getTrIndex(inNode.parentNode), getTdIndex(inNode));
757 }
758 });
759
760 return {
761 _Builder: _Builder,
762 _HeaderBuilder: _HeaderBuilder,
763 _ContentBuilder: _ContentBuilder
764 };
765 });