YUI.add("aui-datatable-highlight",function(e,t){var n=e.Lang,r=n.isArray,i=n.isString,s=n.isBoolean,o="active",u="activeBorderWidth",a="activeCell",f="activeCoordChange",l="activeRow",c="border",h="cells",p="children",d="dataChange",v="highlight",m="highlightRange",g="host",y="overlay",b="overlayActiveNode",w="overlayNode",E="rangeBorderWidth",S="region",x="rows",T="selectionChange",N="type",C=" ",k=function(t){var s=this,o=0,u;i(t)?t=n.trim(t).replace(/\s+/g," ").split(C):r(t)||(t=e.Array(t));for(u=4-t.length;o<u;o++)t.push(t[o]);return e.Array.map(t,parseFloat)},L=e.Base.create("datatable-highlight",e.Plugin.Base,[],{CLASS_NAMES:null,TPL_FRAME:'<div class="{overlay}"><div class="{border}"></div><div class="{border}"></div><div class="{border}"></div><div class="{border}"></div></div>',_lastActiveRow:null,_nodes:null,initializer:function(){var e=this,t=e.get(g);e.CLASS_NAMES={active:t.getClassName(o),border:t.getClassName(v,c),highlight:t.getClassName(v),overlay:t.getClassName(v,y),overlayActive:t.getClassName(v,y,o)},e.afterHostEvent(f,e._afterActiveCoordChange),e.afterHostEvent(T,e._afterSelectionChange),e.afterHostEvent(d,e._afterDataChange)},clear:function(){var e=this,t=e.get(g),n=t.get(a);n&&n.removeClass(e.CLASS_NAMES.active),e._clearBorders(),e._clearHighlights()},getActiveRegion:function(){var e=this,t=e.get(g),n=e.get(N),r=null,i;return n===x?i=t.get(l):i=t.get(a),i&&(r=i.get(S)),r},getSelectionRegion:function(){var e=this,t=e._nodes,n=t[0].get(S),r=t[t.length-1].get(S);return{0:n.top,1:n.left,bottom:r.bottom,height:r.bottom-n.top,left:n.left,right:r.right,top:n.top,width:r.right-n.left}},_afterActiveCoordChange:function(e){var t=this,n=t.get(g),r=t.get(u),i=t.get(b),s=t.CLASS_NAMES,o=n.get(l),a=t._lastActiveRow;if(!t.get(N))return;t.clear(),a&&a.removeClass(s.active),o&&(t._alignBorder(i,t.getActiveRegion(),r),o.addClass(s.active)),t._lastActiveRow=o},_afterDataChange:function(e){var t=this;t.clear()},_afterSelectionChange:function(t){var n=this,r,i=n.get(m),s=n.get(w),o=n.get(E);if(!n.get(N))return;n._clearHighlights(),r=n._collectNodes(t.newVal),i&&r&&r.length>1&&(n._alignBorder(s,n.getSelectionRegion(),o),e.Array.each(r,function(e){e.addClass(n.CLASS_NAMES.highlight)}))},_alignBorder:function(e,t,n){var r=this,i=r.get(g);i._tableNode.appendChild(e);if(t){var s=e.get(p),o=s.item(0),u=s.item(1),a=s.item(2),f=s.item(3);e.setXY([t.left,t.top]),o.sizeTo(t.width,n[0]),f.sizeTo(n[3],t.height-n[2]),a.sizeTo(t.width,n[2]),u.sizeTo(n[1],t.height-n[2]),o.setXY([t.left,t.top]),f.setXY([t.left,t.top]),a.setXY([t.left,t.bottom-n[2]]),u.setXY([t.right-n[1],t.top])}},_collectNodes:function(e){var t=this,n=t.get(N);return!n||!e?null:t._nodes=e[n]},_clearBorders:function(){var e=this;e.get(w).remove(),e.get(b).remove()},_clearHighlights:function(){var t=this;e.Array.each(t._nodes,function(e){e&&e.removeClass(t.CLASS_NAMES.highlight)})},_validateType:function(e){return e===h||e===x||e===null}},{NS:v,NAME:"datatable-highlight",ATTRS:{activeBorderWidth:{setter:k,value:2},overlayActiveNode:{setter:function(t){var r=this,i=r.CLASS_NAMES;return t||(t=e.Node.create(n.sub(r.TPL_FRAME,i)),t.addClass(i.overlayActive)),t},value:null},overlayNode:{setter:function(t){var r=this;return t||(t=e.Node.create(n.sub(r.TPL_FRAME,r.CLASS_NAMES))),t},value:null},highlightRange:{validator:s,value:!0},rangeBorderWidth:{setter:k,value:1},type:{validator:"_validateType",value:h}}});e.namespace("Plugin").DataTableHighlight=L},"2.0.0",{requires:["aui-datatable-selection"],skinnable:!0});
