forked from lorenzofox3/Smart-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmart-table.min.js
6 lines (6 loc) · 6.2 KB
/
smart-table.min.js
1
2
3
4
5
6
/**
* @version 2.1.3
* @license MIT
*/
!function(t,e){"use strict";t.module("smart-table",[]).run(["$templateCache",function(t){t.put("template/smart-table/pagination.html",'<nav ng-if="numPages && pages.length >= 2"><ul class="pagination"><li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a ng-click="selectPage(page)">{{page}}</a></li></ul></nav>')}]),t.module("smart-table").constant("stConfig",{pagination:{template:"template/smart-table/pagination.html",itemsByPage:10,displayedPages:5},search:{delay:400,inputEvent:"input"},select:{mode:"single",selectedClass:"st-selected"},sort:{ascentClass:"st-sort-ascent",descentClass:"st-sort-descent",skipNatural:!1},pipe:{delay:100}}),t.module("smart-table").controller("stTableController",["$scope","$parse","$filter","$attrs",function(a,s,n,i){function r(t){return t?[].concat(t):[]}function l(){b=r(o(a)),S===!0&&v.pipe()}function c(t,e){if(-1!=e.indexOf(".")){var a=e.split("."),n=a.pop(),i=a.join("."),r=s(i)(t);delete r[n],0==Object.keys(r).length&&c(t,i)}else delete t[e]}var o,u,p,g=i.stTable,f=s(g),d=f.assign,m=n("orderBy"),h=n("filter"),b=r(f(a)),P={sort:{},search:{},pagination:{start:0,totalItemCount:0}},S=!0,v=this;i.stSafeSrc&&(o=s(i.stSafeSrc),a.$watch(function(){var t=o(a);return t?t.length:0},function(t){t!==b.length&&l()}),a.$watch(function(){return o(a)},function(t,e){t!==e&&(P.pagination.start=0,l())})),this.sortBy=function(e,a){return P.sort.predicate=e,P.sort.reverse=a===!0,t.isFunction(e)?P.sort.functionName=e.name:delete P.sort.functionName,P.pagination.start=0,this.pipe()},this.search=function(e,a){var n=P.search.predicateObject||{},i=a?a:"$";return e=t.isString(e)?e.trim():e,s(i).assign(n,e),e||c(n,i),P.search.predicateObject=n,P.pagination.start=0,this.pipe()},this.pipe=function(){var t,s=P.pagination;u=P.search.predicateObject?h(b,P.search.predicateObject):b,P.sort.predicate&&(u=m(u,P.sort.predicate,P.sort.reverse)),s.totalItemCount=u.length,s.number!==e&&(s.numberOfPages=u.length>0?Math.ceil(u.length/s.number):1,s.start=s.start>=u.length?(s.numberOfPages-1)*s.number:s.start,t=u.slice(s.start,s.start+parseInt(s.number))),d(a,t||u)},this.select=function(t,s){var n=r(f(a)),i=n.indexOf(t);-1!==i&&("single"===s?(t.isSelected=t.isSelected!==!0,p&&(p.isSelected=!1),p=t.isSelected===!0?t:e):n[i].isSelected=!n[i].isSelected)},this.slice=function(t,e){return P.pagination.start=t,P.pagination.number=e,this.pipe()},this.tableState=function(){return P},this.getFilteredCollection=function(){return u||b},this.setFilterFunction=function(t){h=n(t)},this.setSortFunction=function(t){m=n(t)},this.preventPipeOnWatch=function(){S=!1}}]).directive("stTable",function(){return{restrict:"A",controller:"stTableController",link:function(t,e,a,s){a.stSetFilter&&s.setFilterFunction(a.stSetFilter),a.stSetSort&&s.setSortFunction(a.stSetSort)}}}),t.module("smart-table").directive("stSearch",["stConfig","$timeout","$parse",function(t,e,a){return{require:"^stTable",link:function(s,n,i,r){var l=r,c=null,o=i.stDelay||t.search.delay,u=i.stInputEvent||t.search.inputEvent;i.$observe("stSearch",function(t,e){var a=n[0].value;t!==e&&a&&(r.tableState().search={},l.search(a,t))}),s.$watch(function(){return r.tableState().search},function(t){var e=i.stSearch||"$";t.predicateObject&&a(e)(t.predicateObject)!==n[0].value&&(n[0].value=a(e)(t.predicateObject)||"")},!0),n.bind(u,function(t){t=t.originalEvent||t,null!==c&&e.cancel(c),c=e(function(){l.search(t.target.value,i.stSearch||""),c=null},o)})}}}]),t.module("smart-table").directive("stSelectRow",["stConfig",function(t){return{restrict:"A",require:"^stTable",scope:{row:"=stSelectRow"},link:function(e,a,s,n){var i=s.stSelectMode||t.select.mode;a.bind("click",function(){e.$apply(function(){n.select(e.row,i)})}),e.$watch("row.isSelected",function(e){e===!0?a.addClass(t.select.selectedClass):a.removeClass(t.select.selectedClass)})}}}]),t.module("smart-table").directive("stSort",["stConfig","$parse",function(a,s){return{restrict:"A",require:"^stTable",link:function(n,i,r,l){function c(){g++,u=t.isFunction(p(n))?p(n):r.stSort,g%3===0&&!!h!=!0?(g=0,l.tableState().sort={},l.tableState().pagination.start=0,l.pipe()):l.sortBy(u,g%2===0)}var o,u=r.stSort,p=s(u),g=0,f=r.stClassAscent||a.sort.ascentClass,d=r.stClassDescent||a.sort.descentClass,m=[f,d],h=r.stSkipNatural!==e?r.stSkipNatural:a.sort.skipNatural;r.stSortDefault&&(o=n.$eval(r.stSortDefault)!==e?n.$eval(r.stSortDefault):r.stSortDefault),i.bind("click",function(){u&&n.$apply(c)}),o&&(g="reverse"===o?1:0,c()),n.$watch(function(){return l.tableState().sort},function(t){t.predicate!==u?(g=0,i.removeClass(f).removeClass(d)):(g=t.reverse===!0?2:1,i.removeClass(m[g%2]).addClass(m[g-1]))},!0)}}}]),t.module("smart-table").directive("stPagination",["stConfig",function(t){return{restrict:"EA",require:"^stTable",scope:{stItemsByPage:"=?",stDisplayedPages:"=?",stPageChange:"&"},templateUrl:function(e,a){return a.stTemplate?a.stTemplate:t.pagination.template},link:function(e,a,s,n){function i(){var t,a,s=n.tableState().pagination,i=1,r=e.currentPage;for(e.totalItemCount=s.totalItemCount,e.currentPage=Math.floor(s.start/s.number)+1,i=Math.max(i,e.currentPage-Math.abs(Math.floor(e.stDisplayedPages/2))),t=i+e.stDisplayedPages,t>s.numberOfPages&&(t=s.numberOfPages+1,i=Math.max(1,t-e.stDisplayedPages)),e.pages=[],e.numPages=s.numberOfPages,a=i;t>a;a++)e.pages.push(a);r!==e.currentPage&&e.stPageChange({newPage:e.currentPage})}e.stItemsByPage=e.stItemsByPage?+e.stItemsByPage:t.pagination.itemsByPage,e.stDisplayedPages=e.stDisplayedPages?+e.stDisplayedPages:t.pagination.displayedPages,e.currentPage=1,e.pages=[],e.$watch(function(){return n.tableState().pagination},i,!0),e.$watch("stItemsByPage",function(t,a){t!==a&&e.selectPage(1)}),e.$watch("stDisplayedPages",i),e.selectPage=function(t){t>0&&t<=e.numPages&&n.slice((t-1)*e.stItemsByPage,e.stItemsByPage)},n.tableState().pagination.number||n.slice(0,e.stItemsByPage)}}}]),t.module("smart-table").directive("stPipe",["stConfig","$timeout",function(e,a){return{require:"stTable",scope:{stPipe:"="},link:{pre:function(s,n,i,r){var l=null;t.isFunction(s.stPipe)&&(r.preventPipeOnWatch(),r.pipe=function(){return null!==l&&a.cancel(l),l=a(function(){s.stPipe(r.tableState(),r)},e.pipe.delay)})},post:function(t,e,a,s){s.pipe()}}}}])}(angular);
//# sourceMappingURL=smart-table.min.js.map