_Builder.js 23 KB

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