-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathangular-table.min.js
5 lines (5 loc) · 5.49 KB
/
angular-table.min.js
1
2
3
4
5
// author: Samuel Mueller
// version: 0.0.4
// license: MIT
// homepage: http://github.com/ssmm/angular-table
!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element("<tr></tr>"),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element("<th style='cursor: pointer;'></th>"),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element("<i style='margin-left: 10px;'></i>"),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},n=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},{restrict:"AC",scope:!0,compile:function(r,a,l){var o,u,c,g,s,d,f;return n(a),d=r.find("thead"),g=r.find("tbody"),s=r.find("td"),d[0]&&(u=t.collectCustomHeaderMarkup(d),o=t.collectBodyDefinition(g),f=d.find("tr"),f.remove(),d.append(i(u,o.tds))),c=e(a),c.compile(r,a,l),{post:function(t,e,i){return o.initialSorting&&(t.predicate=o.initialSorting.predicate,t.descending="desc"===o.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},c.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" <div class='pagination' style='margin: 0px;'> <ul> <li ng-class='{disabled: currentPage <= 0}'> <a href='' ng-click='goToPage(currentPage - 1)'>«</a> </li> <li ng-class='{active: currentPage == page}' ng-repeat='page in pages'> <a href='' ng-click='goToPage(page)'>{{page + 1}}</a> </li> <li ng-class='{disabled: currentPage >= numberOfPages - 1}'> <a href='' ng-click='goToPage(currentPage + 1); normalize()'>»</a> </li> </ul> </div>",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a;if(a=t.sortContext||"global","global"===a)e="item in "+t.pagination+".list "+n+" "+i;else{if("page"!==a)throw"Invalid sort-context: "+a+".";e="item in "+t.pagination+".list "+i+" "+n+" "}this.compile=function(t,i){var n,a,l,o,u,c,g;if(a=r(t,e),"undefined"!=typeof i.fillLastPage){for(u=t.find("td"),o="",c=0,g=u.length;g>c;c++)l=u[c],o+="<td> </td>";return n=angular.element("<tr>"+o+"</tr>"),n.attr("ng-repeat","item in "+i.pagination+".getFillerArray() "),a.append(n)}},this.link=function(e){var i;return i=t.pagination,e.fromPage=function(){return e[i]?e[i].fromPage():void 0},e.toPage=function(){return e[i]?e[i].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this);