//>>built
define("dojox/grid/enhanced/plugins/CellMerge","dojo/_base/declare dojo/_base/array dojo/_base/lang dojo/_base/html ../_Plugin ../../EnhancedGrid".split(" "),function(p,m,k,l,w,x){p=p("dojox.grid.enhanced.plugins.CellMerge",w,{name:"cellMerge",constructor:function(a,b){this.grid=a;this._records=[];this._merged={};b&&k.isObject(b)&&this._setupConfig(b.mergedCells);this._initEvents();this._mixinGrid()},mergeCells:function(a,b,c,e){(a=this._createRecord({row:a,start:b,end:c,major:e}))&&this._updateRows(a);
return a},unmergeCells:function(a){var b;a&&0<=(b=m.indexOf(this._records,a))&&(this._records.splice(b,1),this._updateRows(a))},getMergedCells:function(){var a=[],b;for(b in this._merged)a=a.concat(this._merged[b]);return a},getMergedCellsByRow:function(a){return this._merged[a]||[]},_setupConfig:function(a){m.forEach(a,this._createRecord,this)},_initEvents:function(){m.forEach(this.grid.views.views,function(a){this.connect(a,"onAfterRow",k.hitch(this,"_onAfterRow",a.index))},this)},_mixinGrid:function(){var a=
this.grid;a.mergeCells=k.hitch(this,"mergeCells");a.unmergeCells=k.hitch(this,"unmergeCells");a.getMergedCells=k.hitch(this,"getMergedCells");a.getMergedCellsByRow=k.hitch(this,"getMergedCellsByRow")},_getWidth:function(a){a=this.grid.layout.cells[a].getHeaderNode();return l.position(a).w},_onAfterRow:function(a,b,c){try{if(!(0>b)){var e=[],h,d,t=this._records.length,r=this.grid.layout.cells;for(h=0;h<t;++h){var f=this._records[h],u=this.grid._by_idx[b];if(f.view==a&&f.row(b,u&&u.item,this.grid.store)){var n=
{record:f,hiddenCells:[],totalWidth:0,majorNode:r[f.major].getNode(b),majorHeaderNode:r[f.major].getHeaderNode()};for(d=f.start;d<=f.end;++d){var y=this._getWidth(d,b);n.totalWidth+=y;d!=f.major&&n.hiddenCells.push(r[d].getNode(b))}if(1!=c.length||0<n.totalWidth){for(d=e.length-1;0<=d;--d){var q=e[d].record;(q.start>=f.start&&q.start<=f.end||q.end>=f.start&&q.end<=f.end)&&e.splice(d,1)}e.push(n)}}}this._merged[b]=[];m.forEach(e,function(g){m.forEach(g.hiddenCells,function(z){l.style(z,"display","none")});
var A=l.marginBox(g.majorHeaderNode).w-l.contentBox(g.majorHeaderNode).w,v=g.totalWidth;l.isWebKit||(v-=A);l.style(g.majorNode,"width",v+"px");g.majorNode.setAttribute("colspan",g.hiddenCells.length+1);this._merged[b].push({row:b,start:g.record.start,end:g.record.end,major:g.record.major,handle:g.record})},this)}}catch(g){}},_createRecord:function(a){if(this._isValid(a)){a={row:a.row,start:a.start,end:a.end,major:a.major};a.view=this.grid.layout.cells[a.start].view.index;a.major="number"!=typeof a.major||
isNaN(a.major)?a.start:a.major;if("number"==typeof a.row){var b=a.row;a.row=function(e){return e===b}}else if("string"==typeof a.row){var c=a.row;a.row=function(e,h,d){try{if(d&&h&&d.getFeatures()["dojo.data.api.Identity"])return d.getIdentity(h)==c}catch(t){}return!1}}if(k.isFunction(a.row))return this._records.push(a),a}return null},_isValid:function(a){var b=this.grid.layout.cells,c=b.length;return k.isObject(a)&&"row"in a&&"start"in a&&"end"in a&&0<=a.start&&a.start<c&&a.end>a.start&&a.end<c&&
b[a.start].view.index==b[a.end].view.index&&b[a.start].subrow==b[a.end].subrow&&!("number"==typeof a.major&&(a.major<a.start||a.major>a.end))},_updateRows:function(a){for(var b=null,c=0,e=this.grid.rowCount;c<e;++c){var h=this.grid._by_idx[c];h&&a.row(c,h&&h.item,this.grid.store)&&(this.grid.views.updateRow(c),null===b&&(b=c))}0<=b&&this.grid.scroller.rowHeightChanged(b)}});x.registerPlugin(p);return p});