civio/quienmanda.es

View on GitHub
app/assets/javascripts/footable.min.sort.js

Summary

Maintainability
A
0 mins
Test Coverage
(function(t,e,undefined){function a(){var e=this;e.name="Footable Sortable",e.init=function(a){e.footable=a,a.options.sort===!0&&t(a.table).bind({footable_initialized:function(){var o,i,n=t(a.table),r=(n.find("> tbody"),a.options.classes.sort);if(n.data("sort")!==!1){n.find("> thead > tr:last-child > th, > thead > tr:last-child > td").each(function(){i=t(this),o=a.columns[i.index()],o.sort.ignore===!0||i.hasClass(r.sortable)||(i.addClass(r.sortable),t("<span />").addClass(r.indicator).appendTo(i))}),n.find("> thead > tr:last-child > th."+r.sortable+", > thead > tr:last-child > td."+r.sortable).unbind("click.footable").bind("click.footable",function(a){a.preventDefault(),i=t(this);var o=!i.hasClass(r.sorted);return e.doSort(i.index(),o),!1});var l=!1;for(var s in a.columns)if(o=a.columns[s],o.sort.initial){var d="descending"!==o.sort.initial;e.doSort(o.index,d);break}l&&a.bindToggleSelectors()}},footable_redrawn:function(){var o=t(a.table),i=a.options.classes.sort;o.data("sorted")>=0&&o.find("> thead > tr:last-child > th").each(function(a){var o=t(this);return o.hasClass(i.sorted)||o.hasClass(i.descending)?(e.doSort(a),undefined):undefined})},footable_column_data:function(e){var a=t(e.column.th);e.column.data.sort=e.column.data.sort||{},e.column.data.sort.initial=a.data("sort-initial")||!1,e.column.data.sort.ignore=a.data("sort-ignore")||!1,e.column.data.sort.selector=a.data("sort-selector")||null;var o=a.data("sort-match")||0;o>=e.column.data.matches.length&&(o=0),e.column.data.sort.match=e.column.data.matches[o]}}).data("footable-sort",e)},e.doSort=function(a,o){var i=e.footable;if(t(i.table).data("sort")!==!1){var n=t(i.table),r=n.find("> tbody"),l=i.columns[a],s=n.find("> thead > tr:last-child > th:eq("+a+")"),d=i.options.classes.sort,f=i.options.events.sort;if(o=o===undefined?s.hasClass(d.sorted):"toggle"===o?!s.hasClass(d.sorted):o,l.sort.ignore===!0)return!0;var u=i.raise(f.sorting,{column:l,direction:o?"ASC":"DESC"});u&&u.result===!1||(n.data("sorted",l.index),n.find("> thead > tr:last-child > th, > thead > tr:last-child > td").not(s).removeClass(d.sorted+" "+d.descending),o===undefined&&(o=s.hasClass(d.sorted)),o?s.removeClass(d.descending).addClass(d.sorted):s.removeClass(d.sorted).addClass(d.descending),e.sort(i,r,l,o),i.bindToggleSelectors(),i.raise(f.sorted,{column:l,direction:o?"ASC":"DESC"}))}},e.rows=function(e,a,o){var i=[];return a.find("> tr").each(function(){var a=t(this),n=null;if(a.hasClass(e.options.classes.detail))return!0;a.next().hasClass(e.options.classes.detail)&&(n=a.next().get(0));var r={row:a,detail:n};return o!==undefined&&(r.value=e.parse(this.cells[o.sort.match],o)),i.push(r),!0}).detach(),i},e.sort=function(t,a,o,i){var n=e.rows(t,a,o),r=t.options.sorters[o.type]||t.options.sorters.alpha;n.sort(function(t,e){return i?r(t.value,e.value):r(e.value,t.value)});for(var l=0;n.length>l;l++)a.append(n[l].row),null!==n[l].detail&&a.append(n[l].detail)}}if(e.footable===undefined||null===e.footable)throw Error("Please check and make sure footable.js is included in the page and is loaded prior to this script.");var o={sort:!0,sorters:{alpha:function(t,e){return t===e?0:e>t?-1:1},numeric:function(t,e){return t-e}},classes:{sort:{sortable:"footable-sortable",sorted:"footable-sorted",descending:"footable-sorted-desc",indicator:"footable-sort-indicator"}},events:{sort:{sorting:"footable_sorting",sorted:"footable_sorted"}}};e.footable.plugins.register(a,o)})(jQuery,window);