forked from tinkerwell/angular-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-table.min.js
5 lines (5 loc) · 5.59 KB
/
angular-table.min.js
1
2
3
4
5
// author: Samuel Mueller
// version: 0.0.6
// 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,r;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},r=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."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,l,o){var u,c,g,s,d,f;return n(l),r(l),d=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),d[0]&&(c=t.collectCustomHeaderMarkup(d),f=d.find("tr"),f.remove(),d.append(i(c,u.tds))),g=e(l),g.compile(a,l,o),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.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("itemsPerPage",function(){return 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,l;if(l=t.sortContext||"global",e=t.pagination,"global"===l)a="item in "+e+".list "+n+" "+i;else{if("page"!==l)throw"Invalid sort-context: "+l+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,l,o,u,c,g,s;if(l=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)o=c[g],u+="<td> </td>";return n=angular.element("<tr>"+u+"</tr>"),n.attr("ng-repeat","item in "+e+".getFillerArray() "),l.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}).call(this);