Python-100-Days/Day61-65/code/project_of_tornado/assets/js/dataTables.responsive.min.js

1 line
11 KiB
JavaScript

!function(t){"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return t(e,window,document)}):"object"==typeof exports?module.exports=function(e,n){return e||(e=window),n&&n.fn.dataTable||(n=require("datatables.net")(e,n).$),t(n,e,e.document)}:t(jQuery,window,document)}(function(t,e,n,i){"use strict";var r=t.fn.dataTable,s=function(e,n){if(!r.versionCheck||!r.versionCheck("1.10.3"))throw"DataTables Responsive requires DataTables 1.10.3 or newer";this.s={dt:new r.Api(e),columns:[],current:[]},this.s.dt.settings()[0].responsive||(n&&"string"==typeof n.details?n.details={type:n.details}:n&&n.details===!1?n.details={type:!1}:n&&n.details===!0&&(n.details={type:"inline"}),this.c=t.extend(!0,{},s.defaults,r.defaults.responsive,n),e.responsive=this,this._constructor())};t.extend(s.prototype,{_constructor:function(){var n=this,i=this.s.dt,s=i.settings()[0],o=t(e).width();i.settings()[0]._responsive=this,t(e).on("resize.dtr orientationchange.dtr",r.util.throttle(function(){var i=t(e).width();i!==o&&(n._resize(),o=i)})),s.oApi._fnCallbackReg(s,"aoRowCreatedCallback",function(e,r,s){t.inArray(!1,n.s.current)!==-1&&t("td, th",e).each(function(e){var r=i.column.index("toData",e);n.s.current[r]===!1&&t(this).css("display","none")})}),i.on("destroy.dtr",function(){i.off(".dtr"),t(i.table().body()).off(".dtr"),t(e).off("resize.dtr orientationchange.dtr"),t.each(n.s.current,function(t,e){e===!1&&n._setColumnVis(t,!0)})}),this.c.breakpoints.sort(function(t,e){return t.width<e.width?1:t.width>e.width?-1:0}),this._classLogic(),this._resizeAuto();var a=this.c.details;a.type!==!1&&(n._detailsInit(),i.on("column-visibility.dtr",function(t,e,i,r){n._classLogic(),n._resizeAuto(),n._resize()}),i.on("draw.dtr",function(){n._redrawChildren()}),t(i.table().node()).addClass("dtr-"+a.type)),i.on("column-reorder.dtr",function(t,e,i){n._classLogic(),n._resizeAuto(),n._resize()}),i.on("column-sizing.dtr",function(){n._resizeAuto(),n._resize()}),i.on("init.dtr",function(e,r,s){n._resizeAuto(),n._resize(),t.inArray(!1,n.s.current)&&i.columns.adjust()}),this._resize()},_columnsVisiblity:function(e){var n,i,r=this.s.dt,s=this.s.columns,o=s.map(function(t,e){return{columnIdx:e,priority:t.priority}}).sort(function(t,e){return t.priority!==e.priority?t.priority-e.priority:t.columnIdx-e.columnIdx}),a=t.map(s,function(n){return(!n.auto||null!==n.minWidth)&&(n.auto===!0?"-":t.inArray(e,n.includeIn)!==-1)}),d=0;for(n=0,i=a.length;n<i;n++)a[n]===!0&&(d+=s[n].minWidth);var l=r.settings()[0].oScroll,c=l.sY||l.sX?l.iBarWidth:0,u=r.table().container().offsetWidth-c,h=u-d;for(n=0,i=a.length;n<i;n++)s[n].control&&(h-=s[n].minWidth);var p=!1;for(n=0,i=o.length;n<i;n++){var f=o[n].columnIdx;"-"===a[f]&&!s[f].control&&s[f].minWidth&&(p||h-s[f].minWidth<0?(p=!0,a[f]=!1):a[f]=!0,h-=s[f].minWidth)}var m=!1;for(n=0,i=s.length;n<i;n++)if(!s[n].control&&!s[n].never&&!a[n]){m=!0;break}for(n=0,i=s.length;n<i;n++)s[n].control&&(a[n]=m);return t.inArray(!0,a)===-1&&(a[0]=!0),a},_classLogic:function(){var e=this,n=this.c.breakpoints,r=this.s.dt,s=r.columns().eq(0).map(function(e){var n=this.column(e),s=n.header().className,o=r.settings()[0].aoColumns[e].responsivePriority;if(o===i){var a=t(n.header()).data("priority");o=a!==i?1*a:1e4}return{className:s,includeIn:[],auto:!1,control:!1,never:!!s.match(/\bnever\b/),priority:o}}),o=function(e,n){var i=s[e].includeIn;t.inArray(n,i)===-1&&i.push(n)},a=function(t,i,r,a){var d,l,c;if(r){if("max-"===r)for(d=e._find(i).width,l=0,c=n.length;l<c;l++)n[l].width<=d&&o(t,n[l].name);else if("min-"===r)for(d=e._find(i).width,l=0,c=n.length;l<c;l++)n[l].width>=d&&o(t,n[l].name);else if("not-"===r)for(l=0,c=n.length;l<c;l++)n[l].name.indexOf(a)===-1&&o(t,n[l].name)}else s[t].includeIn.push(i)};s.each(function(e,i){for(var r=e.className.split(" "),s=!1,o=0,d=r.length;o<d;o++){var l=t.trim(r[o]);if("all"===l)return s=!0,void(e.includeIn=t.map(n,function(t){return t.name}));if("none"===l||e.never)return void(s=!0);if("control"===l)return s=!0,void(e.control=!0);t.each(n,function(t,e){var n=e.name.split("-"),r=new RegExp("(min\\-|max\\-|not\\-)?("+n[0]+")(\\-[_a-zA-Z0-9])?"),o=l.match(r);o&&(s=!0,o[2]===n[0]&&o[3]==="-"+n[1]?a(i,e.name,o[1],o[2]+o[3]):o[2]!==n[0]||o[3]||a(i,e.name,o[1],o[2]))})}s||(e.auto=!0)}),this.s.columns=s},_detailsDisplay:function(e,n){var i=this,r=this.s.dt,s=this.c.details;if(s&&s.type!==!1){var o=s.display(e,n,function(){return s.renderer(r,e[0],i._detailsObj(e[0]))});o!==!0&&o!==!1||t(r.table().node()).triggerHandler("responsive-display.dt",[r,e,o,n])}},_detailsInit:function(){var e=this,n=this.s.dt,i=this.c.details;"inline"===i.type&&(i.target="td:first-child, th:first-child"),n.on("draw.dtr",function(){e._tabIndexes()}),e._tabIndexes(),t(n.table().body()).on("keyup.dtr","td, th",function(e){13===e.keyCode&&t(this).data("dtr-keyboard")&&t(this).click()});var r=i.target,s="string"==typeof r?r:"td, th";t(n.table().body()).on("click.dtr mousedown.dtr mouseup.dtr",s,function(i){if(t(n.table().node()).hasClass("collapsed")&&n.row(t(this).closest("tr")).length){if("number"==typeof r){var s=r<0?n.columns().eq(0).length+r:r;if(n.cell(this).index().column!==s)return}var o=n.row(t(this).closest("tr"));"click"===i.type?e._detailsDisplay(o,!1):"mousedown"===i.type?t(this).css("outline","none"):"mouseup"===i.type&&t(this).blur().css("outline","")}})},_detailsObj:function(e){var n=this,i=this.s.dt;return t.map(this.s.columns,function(t,r){if(!t.never&&!t.control)return{title:i.settings()[0].aoColumns[r].sTitle,data:i.cell(e,r).render(n.c.orthogonal),hidden:i.column(r).visible()&&!n.s.current[r],columnIndex:r,rowIndex:e}})},_find:function(t){for(var e=this.c.breakpoints,n=0,i=e.length;n<i;n++)if(e[n].name===t)return e[n]},_redrawChildren:function(){var t=this,e=this.s.dt;e.rows({page:"current"}).iterator("row",function(n,i){e.row(i);t._detailsDisplay(e.row(i),!0)})},_resize:function(){var n,i,r=this,s=this.s.dt,o=t(e).width(),a=this.c.breakpoints,d=a[0].name,l=this.s.columns,c=this.s.current.slice();for(n=a.length-1;n>=0;n--)if(o<=a[n].width){d=a[n].name;break}var u=this._columnsVisiblity(d);this.s.current=u;var h=!1;for(n=0,i=l.length;n<i;n++)if(u[n]===!1&&!l[n].never&&!l[n].control){h=!0;break}t(s.table().node()).toggleClass("collapsed",h);var p=!1;s.columns().eq(0).each(function(t,e){u[e]!==c[e]&&(p=!0,r._setColumnVis(t,u[e]))}),p&&(this._redrawChildren(),t(s.table().node()).trigger("responsive-resize.dt",[s,this.s.current]))},_resizeAuto:function(){var e=this.s.dt,n=this.s.columns;if(this.c.auto&&t.inArray(!0,t.map(n,function(t){return t.auto}))!==-1){var i=(e.table().node().offsetWidth,e.columns,e.table().node().cloneNode(!1)),r=t(e.table().header().cloneNode(!1)).appendTo(i),s=t(e.table().body()).clone(!1,!1).empty().appendTo(i),o=e.columns().header().filter(function(t){return e.column(t).visible()}).to$().clone(!1).css("display","table-cell");t(s).append(t(e.rows({page:"current"}).nodes()).clone(!1)).find("th, td").css("display","");var a=e.table().footer();if(a){var d=t(a.cloneNode(!1)).appendTo(i),l=e.columns().footer().filter(function(t){return e.column(t).visible()}).to$().clone(!1).css("display","table-cell");t("<tr/>").append(l).appendTo(d)}t("<tr/>").append(o).appendTo(r),"inline"===this.c.details.type&&t(i).addClass("dtr-inline collapsed"),t(i).find("[name]").removeAttr("name");var c=t("<div/>").css({width:1,height:1,overflow:"hidden"}).append(i);c.insertBefore(e.table().node()),o.each(function(t){var i=e.column.index("fromVisible",t);n[i].minWidth=this.offsetWidth||0}),c.remove()}},_setColumnVis:function(e,n){var i=this.s.dt,r=n?"":"none";t(i.column(e).header()).css("display",r),t(i.column(e).footer()).css("display",r),i.column(e).nodes().to$().css("display",r)},_tabIndexes:function(){var e=this.s.dt,n=e.cells({page:"current"}).nodes().to$(),i=e.settings()[0],r=this.c.details.target;n.filter("[data-dtr-keyboard]").removeData("[data-dtr-keyboard]");var s="number"==typeof r?":eq("+r+")":r;t(s,e.rows({page:"current"}).nodes()).attr("tabIndex",i.iTabIndex).data("dtr-keyboard",1)}}),s.breakpoints=[{name:"desktop",width:1/0},{name:"tablet-l",width:1024},{name:"tablet-p",width:768},{name:"mobile-l",width:480},{name:"mobile-p",width:320}],s.display={childRow:function(e,n,i){return n?t(e.node()).hasClass("parent")?(e.child(i(),"child").show(),!0):void 0:e.child.isShown()?(e.child(!1),t(e.node()).removeClass("parent"),!1):(e.child(i(),"child").show(),t(e.node()).addClass("parent"),!0)},childRowImmediate:function(e,n,i){return!n&&e.child.isShown()||!e.responsive.hasHidden()?(e.child(!1),t(e.node()).removeClass("parent"),!1):(e.child(i(),"child").show(),t(e.node()).addClass("parent"),!0)},modal:function(e){return function(i,r,s){if(r)t("div.dtr-modal-content").empty().append(s());else{var o=function(){a.remove(),t(n).off("keypress.dtr")},a=t('<div class="dtr-modal"/>').append(t('<div class="dtr-modal-display"/>').append(t('<div class="dtr-modal-content"/>').append(s())).append(t('<div class="dtr-modal-close">&times;</div>').click(function(){o()}))).append(t('<div class="dtr-modal-background"/>').click(function(){o()})).appendTo("body");t(n).on("keyup.dtr",function(t){27===t.keyCode&&(t.stopPropagation(),o())})}e&&e.header&&t("div.dtr-modal-content").prepend("<h2>"+e.header(i)+"</h2>")}}},s.renderer={listHidden:function(){return function(e,n,i){var r=t.map(i,function(t){return t.hidden?'<li data-dtr-index="'+t.columnIndex+'" data-dt-row="'+t.rowIndex+'" data-dt-column="'+t.columnIndex+'"><span class="dtr-title">'+t.title+'</span> <span class="dtr-data">'+t.data+"</span></li>":""}).join("");return!!r&&t('<ul data-dtr-index="'+n+'"/>').append(r)}},tableAll:function(e){return e=t.extend({tableClass:""},e),function(n,i,r){var s=t.map(r,function(t){return'<tr data-dt-row="'+t.rowIndex+'" data-dt-column="'+t.columnIndex+'"><td>'+t.title+":</td> <td>"+t.data+"</td></tr>"}).join("");return t('<table class="'+e.tableClass+'" width="100%"/>').append(s)}}},s.defaults={breakpoints:s.breakpoints,auto:!0,details:{display:s.display.childRow,renderer:s.renderer.listHidden(),target:0,type:"inline"},orthogonal:"display"};var o=t.fn.dataTable.Api;return o.register("responsive()",function(){return this}),o.register("responsive.index()",function(e){return e=t(e),{column:e.data("dtr-index"),row:e.parent().data("dtr-index")}}),o.register("responsive.rebuild()",function(){return this.iterator("table",function(t){t._responsive&&t._responsive._classLogic()})}),o.register("responsive.recalc()",function(){return this.iterator("table",function(t){t._responsive&&(t._responsive._resizeAuto(),t._responsive._resize())})}),o.register("responsive.hasHidden()",function(){var e=this.context[0];return!!e._responsive&&t.inArray(!1,e._responsive.s.current)!==-1}),s.version="2.1.0",t.fn.dataTable.Responsive=s,t.fn.DataTable.Responsive=s,t(n).on("preInit.dt.dtr",function(e,n,i){if("dt"===e.namespace&&(t(n.nTable).hasClass("responsive")||t(n.nTable).hasClass("dt-responsive")||n.oInit.responsive||r.defaults.responsive)){var o=n.oInit.responsive;o!==!1&&new s(n,t.isPlainObject(o)?o:{})}}),s});