bootstrap-table-resizable.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define([], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory();
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory();
  11. global.bootstrapTableResizable = mod.exports;
  12. }
  13. })(this, function () {
  14. "use strict";
  15. /**
  16. * @author: Dennis Hernández
  17. * @webSite: http://djhvscf.github.io/Blog
  18. * @version: v2.0.0
  19. */
  20. (function ($) {
  21. "use strict";
  22. var initResizable = function initResizable(that) {
  23. if (that.options.resizable && !that.options.cardView && !isInit(that)) {
  24. that.$el.resizableColumns();
  25. }
  26. };
  27. var reInitResizable = function reInitResizable(that) {
  28. destroy(that);
  29. initResizable(that);
  30. };
  31. var destroy = function destroy(that) {
  32. if (isInit(that)) {
  33. that.$el.data("resizableColumns").destroy();
  34. }
  35. };
  36. var isInit = function isInit(that) {
  37. return that.$el.data("resizableColumns") !== undefined;
  38. };
  39. $.extend($.fn.bootstrapTable.defaults, {
  40. resizable: false
  41. });
  42. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  43. _initBody = BootstrapTable.prototype.initBody,
  44. _toggleView = BootstrapTable.prototype.toggleView,
  45. _resetView = BootstrapTable.prototype.resetView;
  46. BootstrapTable.prototype.initBody = function () {
  47. var that = this;
  48. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  49. that.$el.off("column-switch.bs.table, page-change.bs.table").on("column-switch.bs.table, page-change.bs.table", function () {
  50. reInitResizable(that);
  51. });
  52. };
  53. BootstrapTable.prototype.toggleView = function () {
  54. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  55. if (this.options.resizable && this.options.cardView) {
  56. //Destroy the plugin
  57. destroy(this);
  58. }
  59. };
  60. BootstrapTable.prototype.resetView = function () {
  61. var that = this;
  62. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  63. if (this.options.resizable) {
  64. // because in fitHeader function, we use setTimeout(func, 100);
  65. setTimeout(function () {
  66. initResizable(that);
  67. }, 100);
  68. }
  69. };
  70. })(jQuery);
  71. });