-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfolium.min.js
22 lines (22 loc) · 11.1 KB
/
folium.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var FoliumTable=function(b,E){function G(a){-1===a?(n=-1,r=void 0):e===$(document).attr("activeTable")&&(n=a,N=b.rows[H(a)]._ROW_ID,void 0!==r&&r.removeClass("selectedRow"),a=(new Number(a)).toString(),r=$("#"+e+" tbody tr:eq("+a+")"),r.focus(),r.addClass("selectedRow"))}function v(a){if(!(a>=I)&&e===$(document).attr("activeTable")){$("#"+e+" thead th:eq("+l+")").removeClass("selectedColumnHeader");l=a;void 0!==t&&t.removeClass("selectedColumn");var b=(new Number(n)).toString();t=$("#"+e+" tbody tr:eq("+
b+")").find("td:eq("+a+")");t.addClass("selectedColumn");$("#"+e+" thead th:eq("+l+")").addClass("selectedColumnHeader");t.focus()}}function O(a,b){return a.localeCompare(b,P)}function J(a,b){return a-b}function K(a,d){d=void 0===d?!0:d;if(-1!==a&&b.sortable){var k=b.columns[a].columnId,p=b.columns[a].dataType,c=L.get(k);d&&(c*=-1,L.set(k,c));var e=w.get(p),u=q?a:k;f?g.sort(function(a,b){return c*e(a[u],b[u])}):b.rows.sort(function(a,b){return c*e(a[u],b[u])})}}function M(a){a=void 0===a?b.rows:a;
var d=a.length%c.pageSize;c.numOfPages=parseInt(a.length/c.pageSize);c.numOfPages=0!==d?c.numOfPages+1:c.numOfPages;d=(c.currentPage-1)*c.pageSize+1;a=d+a.slice((c.currentPage-1)*c.pageSize,c.currentPage*c.pageSize).length-1;if($("#foliumPageJumpTo option").length!==c.numOfPages){$("#foliumPageJumpTo").empty();for(var k="",p=2;p<=c.numOfPages;p++)k+='<option value="'+p+'">'+p+"</option>";$("#foliumPageSwitcher").html('<select id="foliumPageJumpTo" class="pageJumpComboBox"><option value="1">1</option>'+
k+"</select> / "+c.numOfPages);$("#foliumPageJumpTo").change(function(){c.currentPage=parseInt($(this).val());m(f?g:b.rows)})}$("#foliumPageJumpTo option:selected").prop("selected",!1);$("#foliumPageJumpTo option[value="+c.currentPage+"]").prop("selected",!0);$("#currentPageInfo").html(d+"-"+a+" | Page: ")}function m(a){a=void 0===a?b.rows:a;$("#"+b.tableId+" tbody").remove();x(a);M(a)}function x(a){a=void 0===a?b.rows:a;a=b.pagination.active?a.slice((c.currentPage-1)*c.pageSize,c.currentPage*c.pageSize):
a;var d="";y=[];a.forEach(function(a,c){var k='<tr class="'+(0===c%2?"evenRow":"oddRow")+'">';b.columns.forEach(function(b,d){var p=q?a[d]:a[b.columnId],e=B(c,d,p,a);k+=void 0===p?"<td></td>":"<td>"+e+"</td>"});k+="</tr>";d+=k;y.push(a._ROW_ID)});E.append("<tbody>"+d+"</tbody>");a=a.map(function(a){return a._ROW_ID}).indexOf(N);if(-1!==a){a=$("#"+e+" tbody tr:eq("+a+")");a.removeClass();a.addClass("selectedRow");var k=a.find("td:eq("+l+")");k.addClass("selectedColumn");r=a;t=k}$("#"+e+" tbody").on("click",
"td",function(){var a=$(this).parent(),b=$(this);a=a.index();b=b.index();G(a);v(b);F.get("rowClicked")(a)});$("#"+b.tableId+" tbody td").dblclick(function(){var a=$(this).parent().index();Q($(this));F.get("rowDoubleClicked")(a)})}function H(a){return-1===a?-1:f?(a=g[b.pagination.active?(c.currentPage-1)*c.pageSize+a:a]._ROW_ID,b.rows.map(function(a){return a._ROW_ID}).indexOf(a)):b.pagination.active?(c.currentPage-1)*c.pageSize+a:a}function Q(a){var d=a.css("width"),c=a.parent().index(),e=a.index(),
f=b.pagination.active?H(c):c,g=b.columns[e].columnId,u=q?b.rows[f][e]:b.rows[f][g];if(b.editable){a.html('<input type="text" id="cellEditor" style="width:'+d+'" value="'+u+'" />');var h=$("#cellEditor");h.focus();h[0].setSelectionRange(u.length,u.length);$("#cellEditor").focusout(function(){var d=h.val();d=z.get(b.columns[e].dataType)(d);q?b.rows[f][e]=d:b.rows[f][g]=d;d=B(c,e,d,b.rows[f]);a.html(d)});$("#cellEditor").keypress(function(a){13===a.keyCode&&(v(e+1),E.focus())})}}var T=this;if(void 0===
b.columns)console.error('"columns" property is not defined in table settings. Please make sure that it is defined in your table settings.');else{b.rows=void 0===b.rows?[]:b.rows;var h=b.rows.length,I=b.columns.length,C=0,n=-1,N=-1,r=void 0,l=-1,t=void 0,e=b.tableId,B=void 0,R=void 0,P="en-US",D=function(a){return!0},f=!1,A=-1,g=void 0,q=void 0,y=[],c={pageSize:-1,numOfPages:0,currentPage:1},L=new Map,w=new Map,F=new Map,z=new Map;F.set("rowClicked",function(a){});F.set("rowDoubleClicked",function(a){});
b.pagination=void 0===b.pagination?{active:!1,size:-1}:b.pagination;b.sortable=void 0===b.sortable||"boolean"!==typeof b.sortable?!1:b.sortable;b.editable=void 0===b.editable||"boolean"!==typeof b.editable?!1:b.editable;b.showSearchHint=void 0===b.showSearchHint||"boolean"!==typeof b.showSearchHint?!0:b.showSearchHint;b.searchTipText=void 0===b.searchTipText||null===b.searchTipText?function(a){return a+" row(s) presented."}:b.searchTipText;if(0<b.columns.filter(function(a){return"_ROW_ID"===a.columnId}).length)console.error("_ROW_ID is specifically defined column for Folium Table. Please try to name this column with a different name.");
else{b.rows.forEach(function(a){Object.defineProperty(a,"_ROW_ID",{value:C,writable:!1,enumerable:!0,configurable:!1});C++});w.set("number",J);w.set("float",J);w.set("integer",J);w.set("datetime",function(a,b){return a>b?1:a<b?-1:0});w.set("string",O);w.set(void 0,O);z.set("integer",function(a){return parseInt(a)});z.set("float",function(a){return parseFloat(a)});z.set("number",function(a){return parseFloat(a)});z.set("datetime",function(a){return new Date(a)});z.set("integer",function(a){return a.toString()});
z.set(void 0,function(a){return a.toString()});E.addClass("folium");E.attr("tabindex","0");q=void 0!==b.rowsAsArrays&&null!==b.rowsAsArrays&&"boolean"===typeof b.rowsAsArrays?b.rowsAsArrays:!1;B=void 0!==b.cellRenderer?b.cellRenderer:function(a,b,c,e){return c};R=void 0!==b.headerRenderer?b.headerRenderer:function(a,b,c){return b};void 0!==b.width&&$(".folium").css("width",""+b.width);void 0!==b.height&&$(".folium").css("height",""+b.height);var S=b.columns;S.forEach(function(a){return L.set(a.columnId,
-1)});(function(a){var b='<thead><tr id="columns">';a.forEach(function(a,d){return b+='<th class="columnHeader sortHeader" id="'+a.columnId+'">'+R(d,a.displayText,a)+"</th>"});b+="</tr>";E.append(b+"</thead>")})(S);b.pagination.active&&"number"===typeof b.pagination.size&&($("#"+e).before('<div class="foliumPageBar"><button id="'+e+'foliumPageFirst" class="pageBarButton">First</button><button class="pageBarButton" id="'+e+'foliumPagePrevious"><</button><div id="'+e+'pageInfo" class="infoBox"><span id="currentPageInfo"></span><div id="foliumPageSwitcher"><select id="foliumPageJumpTo" class="pageJumpComboBox"><option value="1">1</option></select> / 0</div></div><button class="pageBarButton" id="'+
e+'foliumPageNext">></button><button class="pageBarButton" id="'+e+'foliumPageLast">Last</button><span id="searchInfo" class="pageBarText"></span></div>'),$(".foliumPageBar").css("width",$("#"+e).css("width")),c.pageSize=b.pagination.size,M(),$("#"+e+"foliumPageNext").click(function(){c.currentPage+1>c.numOfPages||(c.currentPage++,m(f?g:b.rows))}),$("#"+e+"foliumPagePrevious").click(function(){1>c.currentPage-1||(c.currentPage--,m(f?g:b.rows))}),$("#"+e+"foliumPageFirst").click(function(){1!==c.currentPage&&
(c.currentPage=1,m(f?g:b.rows))}),$("#"+e+"foliumPageLast").click(function(){c.currentPage!==c.numOfPages&&(c.currentPage=c.numOfPages,m(f?g:b.rows))}));void 0===b.pagination.size&&console.error("Pagination size is not defined! Pagination skipped.");x();$("td,th").on("focus",function(){$(T).closest("table").focus()});$("#"+b.tableId).focus(function(){$(document).attr("activeTable",b.tableId)});$("#"+b.tableId).focusout(function(){$(document).attr("activeTable",null)});$("#"+e+" thead th").click(function(){var a=
$(this).index();A=a;v(a);b.sortable&&(K(a),$("#"+b.tableId+" tbody").remove(),x(f?g:b.rows))});$(document).keydown(function(a){var d=$(document).attr("activeTable");a=a.keyCode;null!==d&&void 0!==d&&d===e&&(37===a?0>=l||v(l-1):38===a?0>=n||(G(n-1),v(l)):39===a?l!==I-1&&v(l+1):40===a?(d=$("#"+e+" tbody tr").length,n!==(b.pagination.active?d-1:h-1)&&(G(n+1),v(l))):b.editable&&Q(t))});this.addRow=function(a){Object.defineProperty(a,"_ROW_ID",{value:C,writable:!1,enumerable:!0,configurable:!1});C++;b.rows.push(a);
var d=0===h?0:h;h+=1;if(f)this.search(D);else if(-1!==A&&(K(A,!1),d=b.rows.map(function(a){return a._ROW_ID}).indexOf(a._ROW_ID)),b.pagination.active)m();else{var c='<tr class="'+(0===d%2?"evenRow":"oddRow")+'">';b.columns.forEach(function(b,e){var k=q?a[e]:a[b.columnId],f=B(d,e,k,a);c+=void 0===k?"<td></td>":"<td>"+f+"</td>"});c+="</tr>";y.push(a._ROW_ID);1===h?$("#"+e+" tbody").append(c):0===d?$("#"+e+" tbody tr:eq(0)").before(c):$("#"+e+" tbody tr:eq("+(d-1)+")").after(c)}};this.addRows=function(a){a.forEach(function(a){Object.defineProperty(a,
"_ROW_ID",{value:C,writable:!1,enumerable:!0,configurable:!1});C++});b.rows=b.rows.concat(a);if(f)this.search(D);else if(-1!==A&&K(A,!1),b.pagination.active)m();else if(-1!==A)$("#"+e+" tbody").empty(),x(f?g:b.rows);else{var d="";a.forEach(function(a){var c='<tr class="'+(0===h%2?"evenRow":"oddRow")+'">';b.columns.forEach(function(b,d){var e=q?a[d]:a[b.columnId],k=B(h-1,d,e,a);c+=void 0===e?"<td></td>":"<td>"+k+"</td>"});c+="</tr>";d+=c;h++;y.push(a._ROW_ID)});$("#"+e+" tbody").append(d)}};this.updateRow=
function(a,d){q?(Object.defineProperty(d,"_ROW_ID",{value:b.rows[a]._ROW_ID,writable:!1,enumerable:!0,configurable:!1}),b.rows[a]=d):Object.keys(d).forEach(function(c){return b.rows[a][c]=d[c]});var c=b.rows[a],f="";b.columns.forEach(function(a,b){var d=q?c[b]:c[a.columnId],e=B(h-1,b,d,c);f+=void 0===d?"<td></td>":"<td>"+e+"</td>"});var g=y.indexOf(c._ROW_ID);-1!==g&&$("#"+e+" tbody tr:eq("+g+")").html(f)};this.updateRows=function(a,b){var d=this;a.forEach(function(a,c){return d.updateRow(a,b[c])})};
this.deleteRow=function(a){var c=b.rows.splice(a,1)[0];if(void 0!==c)if(--h,f)this.search(D);else if(b.pagination.active)m();else if(c=y.indexOf(c._ROW_ID),y.splice(c,1),-1!==c&&(console.log(c),-1!==c))for(G(0!==c?c-1:0),$("#"+e+" tbody tr:eq("+c+")").remove();a<h;a++)c=0===a%2?"evenRow":"oddRow",$("#"+e+" tbody tr:eq("+a+")").removeClass().addClass(c)};this.deleteRows=function(a){var c=a.filter(function(a){return a<h});b.rows=b.rows.filter(function(a,b){return-1===c.indexOf(b)});h-=c.length;f?this.search(D):
b.pagination.active?m():($("#"+b.tableId+" tbody").remove(),x())};this.selectedRow=function(){return n};this.selectedRowInModel=function(){return H(n)};this.selectedColumn=function(){return l};this.getColumn=function(a){return b.columns[a]};this.columnCount=function(){return I};this.rowCount=function(){return h};this.getRow=function(a){return b.rows[a]};this.getRows=function(){return b.rows};this.on=function(a,b){F.set(a,b)};this.currentPage=function(){return currentPage};this.pageCount=function(){return pageCount};
this.getId=function(){return e};this.setLocale=function(a){P=a};this.search=function(a){if(void 0===a||null===a)return g=void 0,D=function(a){return!0},f=!1,$("#searchInfo").html(""),b.pagination.active?(c.currentPage=1,m()):x(),b.rows.length;D=a;g=b.rows.filter(function(b){return a(b)});$("#"+b.tableId+" tbody").remove();b.pagination.active?(c.currentPage=1,m(g)):x(g);f=!0;b.pagination.active&&b.showSearchHint&&$("#searchInfo").html(b.searchTipText(g.length));return g.length};this.clear=function(){$("#"+
e+" tbody").empty();b.rows=[];h=0;l=n=-1;t=r=void 0;A=-1;c.currentPage=1;c.numOfPages=0;b.pagination.active&&M(b.rows)}}}};$.fn.FoliumTable=function(b){if(void 0===b)return this[0].foliumObject;b.tableId=this[0].id;b=new FoliumTable(b,$(this));this[0].foliumObject=b;return this[0].foliumObject};