UNPKG

magix-components

Version:
1 lines 4.12 kB
define("mx-table/index",["magix","$"],function(e,t,d){var r=e("magix"),i=e("$"),a=/width\s*:\s*(\d+)px/;r.applyStyle("C",".eP{width:100%;overflow:auto;border:1px solid #e6e6e6;position:relative}.eQ,.eR thead,.eS{background-color:#fff}.eQ,.eS{position:absolute;top:1px;width:auto;z-index:1}.eT{border:none}.eQ{left:1px}.eS{right:1px}.eU,.eU thead{-webkit-box-shadow:6px 0 6px -4px rgba(0,0,0,.2);box-shadow:6px 0 6px -4px rgba(0,0,0,.2)}.eV,.eV thead{-webkit-box-shadow:-6px 0 6px -4px rgba(0,0,0,.2);box-shadow:-6px 0 6px -4px rgba(0,0,0,.2)}"),d.exports=r.View.extend({init:function(e){var t=this,d=e.rwdRange;t.__dM=((d||[2,-1])+"").split(","),t.__dN=e.sticky+""=="true"},__dO:function(e,t,d,r,a,n){for(var s=i('<table id="'+n+'" class="'+e+'"><thead></thead><tbody></tbody></table>'),o=s.find("thead"),h=s.find("tbody"),_=i("<tr/>"),f=t;f<d;f++){var l=r.eq(f);i('<th fake="true"/>').css({height:l.outerHeight(),width:l.outerWidth()}).insertBefore(l),_.append(l)}o.append(_);for(f=0;f<a.length;f++){_=i("<tr/>");for(var p=a.eq(f).find("td"),c=t;c<d;c++){var g=p.eq(c);i('<td fake="true"/>').css({height:g.outerHeight(),width:g.outerWidth()}).insertBefore(g),_.append(g)}h.append(_)}return s},__dP:function(e,t,d,r,a){for(var n=e.find("thead>tr>th"),s=e.find("tbody"),o=s.find("tr"),h=t;h<d;h++){var _=r.eq(h);"true"!==_.attr("fake")&&(i('<th fake="true"/>').css({height:_.outerHeight(),width:_.outerWidth()}).insertBefore(_),n.eq(h-t).replaceWith(_))}for(h=0;h<a.length;h++){for(var f=a.eq(h).find("td"),l=h>=o.length,p=void 0,c=(p=l?i("<tr/>"):o.eq(h)).find("td"),g=t;g<d;g++){var u=f.eq(g);"true"!==u.attr("fake")&&(i('<td fake="true"/>').css({height:u.outerHeight(),width:u.outerWidth()}).insertBefore(u),l?p.append(u):c.eq(g-t).replaceWith(u))}l&&s.append(p)}for(h=a.length;h<o.length;h++)o.eq(h).remove()},__dQ:function(e,t,d){for(var r=0,i=t.length;i--;){var n=t.eq(i).attr("style").match(a);n&&(r+=parseInt(n[1]))}return r>d?(e.css({width:r}),e.find("thead").css({width:r}),!1):(e.css({width:"inherit"}),e.find("thead").css({width:"inherit"}),!0)},__dZ:function(){var e=this,t=i("#"+e.id),d=e.__dR||t.find("table"),a=e.__dS||d.find("thead>tr>th"),n=0;if(delete e.__dR,delete e.__dS,t.hasClass("eP"))e.__dV!=a.length&&(n=e.__dQ(d,a,t.width()),e.__dV=a.length);else{t.wrap('<div class="ae eR"></div>'),t.addClass("eP"),e.__dT=t,t.on("scroll",function(){e.__dU()}),e.on("destroy",function(){t.off("scroll")}),d.addClass("eT");var s=d.find("tfoot");s.length&&i('<table class="ay"></table>').append(s).insertAfter(t),n=e.__dQ(d,a,t.width()),e.__dV=a.length}if(n)return(v=e.__dW)&&(v.remove(),delete e.__dW),void((v=e.__dX)&&(v.remove(),delete e.__dX));for(var o=e.__dM,h=+o[0],_=+o[1],f=t.find("tbody>tr"),l=a.length;l--;){var p=a.eq(l);"true"!==p.attr("fake")&&p.css({height:p.outerHeight()})}for(l=f.length;l--;){var c=f.eq(l).find("td"),g=c.eq(0);g.css({height:g.outerHeight()}),(g=c.last()).css({height:g.outerHeight()})}if(e.__dX)e.__dP(e.__dX,0,h,a,f);else if(h){u="t_"+e.id+"_left";(v=e.__dO(d.attr("class")+" eQ",0,h,a,f,u)).insertAfter(t),e.__dX=v,e.__dN&&e.owner.mountVframe(u,"mx-table/isticky")}if(e.__dW)e.__dP(e.__dW,_+a.length,a.length,a,f);else if(_){var u="t_"+e.id+"_right",v=e.__dO(d.attr("class")+" eS",_+a.length,a.length,a,f,u);v.insertAfter(t),e.__dW=v,e.__dN&&e.owner.mountVframe(u,"mx-table/isticky")}e.__dN&&!e.__dY&&(e.__dY=1,(u=d.attr("id"))||d.attr("id",u=r.guid("table_")),e.owner.mountVframe(u,"mx-table/isticky"))},__dU:function(){var e=this,t=e.__dT;if(t){var d=e.__dX,r=e.__dW;if(t.prop("clientWidth")<t.prop("scrollWidth")){if(d){t.prop("scrollLeft")>=10?d.hasClass("eU")||d.addClass("eU"):d.hasClass("eU")&&d.removeClass("eU")}if(r){t.prop("scrollLeft")<t.prop("scrollWidth")-t.prop("clientWidth")-10?r.hasClass("eV")||r.addClass("eV"):r.hasClass("eV")&&r.removeClass("eV")}}}},render:function(){var e=this;e.__dZ(),e.__dU()},"$doc<htmlchanged>":function(e){var t=this;if(e.vId==t.owner.pId){var d=i("#"+t.id).find("table"),r=d.find("thead>tr>th"),a=d.find("tbody>tr").first().find("td");r.length==a.length&&(t.__dR=d,t.__dS=r,t.render())}},"$win<resize>":function(){this.__dU()}})});