You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
18 KiB

4 years ago
  1. /*!
  2. Responsive 2.0.0
  3. 2014-2015 SpryMedia Ltd - datatables.net/license
  4. */
  5. (function (c) {
  6. "function" === typeof define && define.amd ? define(["jquery", "datatables.net"], function (l) {
  7. return c(l, window, document)
  8. }) : "object" === typeof exports ? module.exports = function (l, k) {
  9. l || (l = window);
  10. if (!k || !k.fn.dataTable) k = require("datatables.net")(l, k).$;
  11. return c(k, l, l.document)
  12. } : c(jQuery, window, document)
  13. })(function (c, l, k, p) {
  14. var n = c.fn.dataTable,
  15. j = function (a, b) {
  16. if (!n.versionCheck || !n.versionCheck("1.10.3")) throw "DataTables Responsive requires DataTables 1.10.3 or newer";
  17. this.s = {
  18. dt: new n.Api(a),
  19. columns: [],
  20. current: []
  21. };
  22. this.s.dt.settings()[0].responsive || (b && "string" === typeof b.details && (b.details = {
  23. type: b.details
  24. }), this.c = c.extend(!0, {}, j.defaults, n.defaults.responsive, b), a.responsive = this, this._constructor())
  25. };
  26. c.extend(j.prototype, {
  27. _constructor: function () {
  28. var a = this,
  29. b = this.s.dt,
  30. d = b.settings()[0];
  31. b.settings()[0]._responsive = this;
  32. c(l).on("resize.dtr orientationchange.dtr", n.util.throttle(function () {
  33. a._resize()
  34. }));
  35. d.oApi._fnCallbackReg(d, "aoRowCreatedCallback", function (e) {
  36. -1 !== c.inArray(!1, a.s.current) &&
  37. c("td, th", e).each(function (e) {
  38. e = b.column.index("toData", e);
  39. !1 === a.s.current[e] && c(this).css("display", "none")
  40. })
  41. });
  42. b.on("destroy.dtr", function () {
  43. b.off(".dtr");
  44. c(b.table().body()).off(".dtr");
  45. c(l).off("resize.dtr orientationchange.dtr");
  46. c.each(a.s.current, function (e, b) {
  47. !1 === b && a._setColumnVis(e, !0)
  48. })
  49. });
  50. this.c.breakpoints.sort(function (a, b) {
  51. return a.width < b.width ? 1 : a.width > b.width ? -1 : 0
  52. });
  53. this._classLogic();
  54. this._resizeAuto();
  55. d = this.c.details;
  56. !1 !== d.type && (a._detailsInit(), b.on("column-visibility.dtr",
  57. function () {
  58. a._classLogic();
  59. a._resizeAuto();
  60. a._resize()
  61. }), b.on("draw.dtr", function () {
  62. a._redrawChildren()
  63. }), c(b.table().node()).addClass("dtr-" + d.type));
  64. b.on("column-reorder.dtr", function (b, d, c) {
  65. if (c.drop) {
  66. a._classLogic();
  67. a._resizeAuto();
  68. a._resize()
  69. }
  70. });
  71. this._resize()
  72. },
  73. _columnsVisiblity: function (a) {
  74. var b = this.s.dt,
  75. d = this.s.columns,
  76. e, f, h = d.map(function (a, b) {
  77. return {
  78. columnIdx: b,
  79. priority: a.priority
  80. }
  81. }).sort(function (a, b) {
  82. return a.priority !== b.priority ? a.priority - b.priority : a.columnIdx - b.columnIdx
  83. }),
  84. g = c.map(d,
  85. function (b) {
  86. return b.auto && null === b.minWidth ? !1 : !0 === b.auto ? "-" : -1 !== c.inArray(a, b.includeIn)
  87. }),
  88. m = 0;
  89. e = 0;
  90. for (f = g.length; e < f; e++) !0 === g[e] && (m += d[e].minWidth);
  91. e = b.settings()[0].oScroll;
  92. e = e.sY || e.sX ? e.iBarWidth : 0;
  93. b = b.table().container().offsetWidth - e - m;
  94. e = 0;
  95. for (f = g.length; e < f; e++) d[e].control && (b -= d[e].minWidth);
  96. m = !1;
  97. e = 0;
  98. for (f = h.length; e < f; e++) {
  99. var i = h[e].columnIdx;
  100. "-" === g[i] && (!d[i].control && d[i].minWidth) && (m || 0 > b - d[i].minWidth ? (m = !0, g[i] = !1) : g[i] = !0, b -= d[i].minWidth)
  101. }
  102. h = !1;
  103. e = 0;
  104. for (f = d.length; e < f; e++)
  105. if (!d[e].control &&
  106. !d[e].never && !g[e]) {
  107. h = !0;
  108. break
  109. }
  110. e = 0;
  111. for (f = d.length; e < f; e++) d[e].control && (g[e] = h); - 1 === c.inArray(!0, g) && (g[0] = !0);
  112. return g
  113. },
  114. _classLogic: function () {
  115. var a = this,
  116. b = this.c.breakpoints,
  117. d = this.s.dt,
  118. e = d.columns().eq(0).map(function (a) {
  119. var b = this.column(a),
  120. e = b.header().className,
  121. a = d.settings()[0].aoColumns[a].responsivePriority;
  122. a === p && (a = c(b.header).data("priority") !== p ? 1 * c(b.header).data("priority") : 1E4);
  123. return {
  124. className: e,
  125. includeIn: [],
  126. auto: !1,
  127. control: !1,
  128. never: e.match(/\bnever\b/) ? !0 : !1,
  129. priority: a
  130. }
  131. }),
  132. f = function (a,
  133. b) {
  134. var d = e[a].includeIn; - 1 === c.inArray(b, d) && d.push(b)
  135. },
  136. h = function (d, c, i, h) {
  137. if (i)
  138. if ("max-" === i) {
  139. h = a._find(c).width;
  140. c = 0;
  141. for (i = b.length; c < i; c++) b[c].width <= h && f(d, b[c].name)
  142. } else if ("min-" === i) {
  143. h = a._find(c).width;
  144. c = 0;
  145. for (i = b.length; c < i; c++) b[c].width >= h && f(d, b[c].name)
  146. } else {
  147. if ("not-" === i) {
  148. c = 0;
  149. for (i = b.length; c < i; c++) - 1 === b[c].name.indexOf(h) && f(d, b[c].name)
  150. }
  151. } else e[d].includeIn.push(c)
  152. };
  153. e.each(function (a, e) {
  154. for (var d = a.className.split(" "), f = !1, j = 0, l = d.length; j < l; j++) {
  155. var k = c.trim(d[j]);
  156. if ("all" === k) {
  157. f = !0;
  158. a.includeIn = c.map(b, function (a) {
  159. return a.name
  160. });
  161. return
  162. }
  163. if ("none" === k || a.never) {
  164. f = !0;
  165. return
  166. }
  167. if ("control" === k) {
  168. f = !0;
  169. a.control = !0;
  170. return
  171. }
  172. c.each(b, function (a, b) {
  173. var c = b.name.split("-"),
  174. d = k.match(RegExp("(min\\-|max\\-|not\\-)?(" + c[0] + ")(\\-[_a-zA-Z0-9])?"));
  175. d && (f = !0, d[2] === c[0] && d[3] === "-" + c[1] ? h(e, b.name, d[1], d[2] + d[3]) : d[2] === c[0] && !d[3] && h(e, b.name, d[1], d[2]))
  176. })
  177. }
  178. f || (a.auto = !0)
  179. });
  180. this.s.columns = e
  181. },
  182. _detailsDisplay: function (a, b) {
  183. var d = this,
  184. e = this.s.dt,
  185. f = this.c.details.display(a, b, function () {
  186. return d.c.details.renderer(e,
  187. a[0], d._detailsObj(a[0]))
  188. });
  189. (!0 === f || !1 === f) && c(e.table().node()).triggerHandler("responsive-display.dt", [e, a, f, b])
  190. },
  191. _detailsInit: function () {
  192. var a = this,
  193. b = this.s.dt,
  194. d = this.c.details;
  195. "inline" === d.type && (d.target = "td:first-child");
  196. b.on("draw.dtr", function () {
  197. a._tabIndexes()
  198. });
  199. a._tabIndexes();
  200. c(b.table().body()).on("keyup.dtr", "td", function (a) {
  201. a.keyCode === 13 && c(this).data("dtr-keyboard") && c(this).click()
  202. });
  203. var e = d.target,
  204. d = "string" === typeof e ? e : "td";
  205. c(b.table().body()).on("mousedown.dtr", d, function (a) {
  206. a.preventDefault()
  207. }).on("click.dtr",
  208. d,
  209. function () {
  210. if (c(b.table().node()).hasClass("collapsed") && b.row(c(this).closest("tr")).length) {
  211. if (typeof e === "number") {
  212. var d = e < 0 ? b.columns().eq(0).length + e : e;
  213. if (b.cell(this).index().column !== d) return
  214. }
  215. d = b.row(c(this).closest("tr"));
  216. a._detailsDisplay(d, false)
  217. }
  218. })
  219. },
  220. _detailsObj: function (a) {
  221. var b = this,
  222. d = this.s.dt;
  223. return c.map(this.s.columns, function (c, f) {
  224. if (!c.never) return {
  225. title: d.settings()[0].aoColumns[f].sTitle,
  226. data: d.cell(a, f).render(b.c.orthogonal),
  227. hidden: d.column(f).visible() && !b.s.current[f]
  228. }
  229. })
  230. },
  231. _find: function (a) {
  232. for (var b = this.c.breakpoints, d = 0, c = b.length; d < c; d++)
  233. if (b[d].name === a) return b[d]
  234. },
  235. _redrawChildren: function () {
  236. var a = this,
  237. b = this.s.dt;
  238. b.rows({
  239. page: "current"
  240. }).iterator("row", function (c, e) {
  241. b.row(e);
  242. a._detailsDisplay(b.row(e), !0)
  243. })
  244. },
  245. _resize: function () {
  246. var a = this,
  247. b = this.s.dt,
  248. d = c(l).width(),
  249. e = this.c.breakpoints,
  250. f = e[0].name,
  251. h = this.s.columns,
  252. g, m = this.s.current.slice();
  253. for (g = e.length - 1; 0 <= g; g--)
  254. if (d <= e[g].width) {
  255. f = e[g].name;
  256. break
  257. }
  258. var i = this._columnsVisiblity(f);
  259. this.s.current = i;
  260. e = !1;
  261. g = 0;
  262. for (d = h.length; g < d; g++)
  263. if (!1 === i[g] && !h[g].never) {
  264. e = !0;
  265. break
  266. }
  267. c(b.table().node()).toggleClass("collapsed", e);
  268. var j = !1;
  269. b.columns().eq(0).each(function (b, c) {
  270. i[c] !== m[c] && (j = !0, a._setColumnVis(b, i[c]))
  271. });
  272. j && this._redrawChildren()
  273. },
  274. _resizeAuto: function () {
  275. var a = this.s.dt,
  276. b = this.s.columns;
  277. if (this.c.auto && -1 !== c.inArray(!0, c.map(b, function (a) {
  278. return a.auto
  279. }))) {
  280. a.table().node();
  281. var d = a.table().node().cloneNode(!1),
  282. e = c(a.table().header().cloneNode(!1)).appendTo(d),
  283. f = c(a.table().body().cloneNode(!1)).appendTo(d),
  284. h = a.columns().header().filter(function (b) {
  285. return a.column(b).visible()
  286. }).to$().clone(!1).css("display", "table-cell");
  287. c(f).append(c(a.rows({
  288. page: "current"
  289. }).nodes()).clone(!1)).find("th, td").css("display", "");
  290. if (f = a.table().footer()) {
  291. var f = c(f.cloneNode(!1)).appendTo(d),
  292. g = a.columns().header().filter(function (b) {
  293. return a.column(b).visible()
  294. }).to$().clone(!1).css("display", "table-cell");
  295. c("<tr/>").append(g).appendTo(f)
  296. }
  297. c("<tr/>").append(h).appendTo(e);
  298. "inline" === this.c.details.type && c(d).addClass("dtr-inline collapsed");
  299. d = c("<div/>").css({
  300. width: 1,
  301. height: 1,
  302. overflow: "hidden"
  303. }).append(d);
  304. d.insertBefore(a.table().node());
  305. h.each(function (c) {
  306. c = a.column.index("fromVisible", c);
  307. b[c].minWidth = this.offsetWidth || 0
  308. });
  309. d.remove()
  310. }
  311. },
  312. _setColumnVis: function (a, b) {
  313. var d = this.s.dt,
  314. e = b ? "" : "none";
  315. c(d.column(a).header()).css("display", e);
  316. c(d.column(a).footer()).css("display", e);
  317. d.column(a).nodes().to$().css("display", e)
  318. },
  319. _tabIndexes: function () {
  320. var a = this.s.dt,
  321. b = a.cells({
  322. page: "current"
  323. }).nodes().to$(),
  324. d = a.settings()[0],
  325. e = this.c.details.target;
  326. b.filter("[data-dtr-keyboard]").removeData("[data-dtr-keyboard]");
  327. c("number" === typeof e ? ":eq(" + e + ")" : e, a.rows({
  328. page: "current"
  329. }).nodes()).attr("tabIndex", d.iTabIndex).data("dtr-keyboard", 1)
  330. }
  331. });
  332. j.breakpoints = [{
  333. name: "desktop",
  334. width: Infinity
  335. }, {
  336. name: "tablet-l",
  337. width: 1024
  338. }, {
  339. name: "tablet-p",
  340. width: 768
  341. }, {
  342. name: "mobile-l",
  343. width: 480
  344. }, {
  345. name: "mobile-p",
  346. width: 320
  347. }];
  348. j.display = {
  349. childRow: function (a, b, d) {
  350. if (b) {
  351. if (c(a.node()).hasClass("parent")) return a.child(d(), "child").show(), !0
  352. } else {
  353. if (a.child.isShown()) return a.child(!1),
  354. c(a.node()).removeClass("parent"), !1;
  355. a.child(d(), "child").show();
  356. c(a.node()).addClass("parent");
  357. return !0
  358. }
  359. },
  360. childRowImmediate: function (a, b, d) {
  361. if (!b && a.child.isShown() || !a.responsive.hasHidden()) return a.child(!1), c(a.node()).removeClass("parent"), !1;
  362. a.child(d(), "child").show();
  363. c(a.node()).addClass("parent");
  364. return !0
  365. },
  366. modal: function (a) {
  367. return function (b, d, e) {
  368. if (d) c("div.dtr-modal-content").empty().append(e());
  369. else {
  370. var f = function () {
  371. h.remove();
  372. c(k).off("keypress.dtr")
  373. },
  374. h = c('<div class="dtr-modal"/>').append(c('<div class="dtr-modal-display"/>').append(c('<div class="dtr-modal-content"/>').append(e())).append(c('<div class="dtr-modal-close">&times;</div>').click(function () {
  375. f()
  376. }))).append(c('<div class="dtr-modal-background"/>').click(function () {
  377. f()
  378. })).appendTo("body");
  379. a && a.header && h.find("div.dtr-modal-content").prepend("<h2>" + a.header(b) + "</h2>");
  380. c(k).on("keyup.dtr", function (a) {
  381. 27 === a.keyCode && (a.stopPropagation(), f())
  382. })
  383. }
  384. }
  385. }
  386. };
  387. j.defaults = {
  388. breakpoints: j.breakpoints,
  389. auto: !0,
  390. details: {
  391. display: j.display.childRow,
  392. renderer: function (a, b, d) {
  393. return (a = c.map(d, function (a, b) {
  394. return a.hidden ? '<li data-dtr-index="' + b + '"><span class="dtr-title">' + a.title + '</span> <span class="dtr-data">' + a.data + "</span></li>" : ""
  395. }).join("")) ? c('<ul data-dtr-index="' + b + '"/>').append(a) : !1
  396. },
  397. target: 0,
  398. type: "inline"
  399. },
  400. orthogonal: "display"
  401. };
  402. var o = c.fn.dataTable.Api;
  403. o.register("responsive()", function () {
  404. return this
  405. });
  406. o.register("responsive.index()", function (a) {
  407. a = c(a);
  408. return {
  409. column: a.data("dtr-index"),
  410. row: a.parent().data("dtr-index")
  411. }
  412. });
  413. o.register("responsive.rebuild()", function () {
  414. return this.iterator("table", function (a) {
  415. a._responsive && a._responsive._classLogic()
  416. })
  417. });
  418. o.register("responsive.recalc()", function () {
  419. return this.iterator("table", function (a) {
  420. a._responsive && (a._responsive._resizeAuto(), a._responsive._resize())
  421. })
  422. });
  423. o.register("responsive.hasHidden()", function () {
  424. var a = this.context[0];
  425. return a._responsive ? -1 !== c.inArray(!1, a._responsive.s.current) : !1
  426. });
  427. j.version = "2.0.0";
  428. c.fn.dataTable.Responsive = j;
  429. c.fn.DataTable.Responsive = j;
  430. c(k).on("init.dt.dtr", function (a, b) {
  431. if ("dt" === a.namespace && (c(b.nTable).hasClass("responsive") || c(b.nTable).hasClass("dt-responsive") || b.oInit.responsive || n.defaults.responsive)) {
  432. var d = b.oInit.responsive;
  433. !1 !== d && new j(b, c.isPlainObject(d) ? d : {})
  434. }
  435. });
  436. return j
  437. });