-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.gettable.min.js
1 lines (1 loc) · 3.57 KB
/
jquery.gettable.min.js
1
!function(n){"use strict";function e(e,t){n.each(t,function(t,o){n.inArray(o,e)<0&&e.push(o)})}function t(t,o){function r(n){var e;if(!c.rows[n])for(e=0;n>=e;e++)c.rows[e]=c.rows[e]||{cells:[],table:c};return c.rows[n]}function l(n){var e;if(!c.cols[n])for(e=0;n>=e;e++)c.cols[e]=c.cols[e]||{cells:[],table:c};return c.cols[n]}var c={rows:[],cols:[],cells:[]},s="number"==typeof o?o:y.length,u=-1,a={},i="table"===t.get(0).nodeName.toLowerCase()?t.get(0):function(){var n=t.closest("table");return n.length?n.get(0):void 0}();return i?(c.elm=i,n(i).data(N,"table:"+s),n.each(i.rows,function(e,t){var o,i,f,h,w,v,g,m,b,d=0;for(n(t).data(N,"table:"+s+",row:"+e),function(){var e=0;n.each(t.cells,function(n,t){e+=+t.colSpan||1}),e-1>u&&(u=e-1)}(),h=0;u>=h;h++)if((!a[e]||!a[e][h])&&(w=t.cells[d++])){for(n(w).data(N,"table:"+s+",cell:"+c.cells.length),f={elm:w,rows:[],cols:[],table:c,iRow:e,iCol:h},v=(+w.rowSpan||1)-1,g=(+w.colSpan||1)-1,m=0;v>=m;m++)o=r(e+m),f.rows.push(o),o.cells.push(f);for(m=0;g>=m;m++)i=l(h+m),f.cols.push(i),i.cells.push(f);for(m=1;v>=m;m++)for(a[e+m]=a[e+m]||{},b=0;g>=b;b++)a[e+m][h+b]=!0;h+=g,c.cells.push(f)}}),n.each(c.cells,function(t,o){var r=[o];n.each(o.rows.concat(o.cols),function(n,t){e(r,t.cells)}),o.xCells=r}),n.each(c.rows,function(n,e){e.cells.sort(function(n,e){return n.iCol-e.iCol})}),n.each(c.cols,function(n,e){e.cells.sort(function(n,e){return n.iRow-e.iRow})}),y[s]=c,c):null}function o(n){for(var e,t={},o=n.data(N)||"",r=/\b(\w+):(\d+)/g;null!==(e=r.exec(o));)t[e[1]]=+e[2];return t}function r(n,e){var r=o(n).table;return e||"number"!=typeof r||!y[r]?t(n,r):y[r]}function l(n){return"table"===n}function c(n){return"tr"===n}function s(n){return"td"===n||"th"===n}function u(n){return"thead"===n||"tfoot"===n||"tbody"===n}function a(n){return l(n)||c(n)||s(n)||u(n)}function i(e){return n.map(e,function(n){return n.elm})}function f(e){return n(i(e))}function h(t){var a=[];return t.each(function(){var t,f=n(this),h=f.get(0).nodeName.toLowerCase();l(h)&&(t=r(f))?e(a,i(t.cells)):c(h)&&(t=r(f))?e(a,i(t.rows[o(f).row].cells)):s(h)&&(t=r(f))?e(a,[t.cells[o(f).cell].elm]):u(h)&&(t=r(f))&&n.each(f.get(0).rows,function(r,l){e(a,i(t.rows[o(n(l)).row].cells))})}),n(a.length?a:null)}function w(t){var l=[];return t.each(function(){var t,c=n(this),u=c.get(0).nodeName.toLowerCase();s(u)&&(t=r(c))&&e(l,i(t.cells[o(c).cell].xCells))}),n(l.length?l:null)}function v(t){var a=[];return t.each(function(){var t,i=n(this),f=i.get(0).nodeName.toLowerCase();l(f)&&(t=r(i))?e(a,t.rows):c(f)&&(t=r(i))?e(a,[t.rows[o(i).row]]):s(f)&&(t=r(i))?e(a,t.cells[o(i).cell].rows):u(f)&&(t=r(i))&&e(a,n.map(i.get(0).rows,function(e){return t.rows[o(n(e)).row]}))}),a}function g(t){var a=[];return t.each(function(){var t,i=n(this),f=i.get(0).nodeName.toLowerCase();(l(f)||c(f)||u(f))&&(t=r(i))?e(a,t.cols):s(f)&&(t=r(i))&&e(a,t.cells[o(i).cell].cols)}),a}function m(e){return n.map(v(e),function(n){return f(n.cells)})}function b(t){var o=[];return n.each(v(t),function(n,t){e(o,i(t.cells))}),n(o.length?o:null)}function d(e){return n.map(g(e),function(n){return f(n.cells)})}function p(t){var o=[];return n.each(g(t),function(n,t){e(o,i(t.cells))}),n(o.length?o:null)}function C(t){var o=[];return t.each(function(){var t,l=n(this),c=l.get(0).nodeName.toLowerCase();a(c)&&(t=r(l))&&e(o,[t.elm])}),n(o.length?o:null)}function L(e){return e.each(function(){var e=n(this),t=e.get(0).nodeName.toLowerCase();a(t)&&r(e,!0)})}var N="getTable",y=[];n.fn[N]=function(n){return"cells"===n?h(this):"xCells"===n?w(this):"rows"===n?m(this):"rowsCells"===n?b(this):"cols"===n?d(this):"colsCells"===n?p(this):"table"===n?C(this):L(this)}}(jQuery);