_Builder.js 23 KB

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