bootstrap-table-resizable.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @author: Dennis Hernández
  3. * @webSite: http://djhvscf.github.io/Blog
  4. * @version: v1.0.0
  5. */
  6. (function ($) {
  7. 'use strict';
  8. var initResizable = function (el) {
  9. var that = el;
  10. //Deletes the plugin to re-create it
  11. $(el.$el).colResizable({disable: true});
  12. //Creates the plugin
  13. $(el.$el).colResizable({
  14. liveDrag: that.options.liveDrag,
  15. fixed: that.options.fixed,
  16. headerOnly: that.options.headerOnly,
  17. minWidth: that.options.minWidth,
  18. hoverCursor: that.options.hoverCursor,
  19. dragCursor: that.options.dragCursor,
  20. onResize: that.onResize,
  21. onDrag: that.options.onResizableDrag
  22. });
  23. };
  24. $.extend($.fn.bootstrapTable.defaults, {
  25. resizable: false,
  26. liveDrag: false,
  27. fixed: true,
  28. headerOnly: false,
  29. minWidth: 15,
  30. hoverCursor: 'e-resize',
  31. dragCursor: 'e-resize',
  32. onResizableResize: function (e) {
  33. return false;
  34. },
  35. onResizableDrag: function (e) {
  36. return false;
  37. }
  38. });
  39. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  40. _init = BootstrapTable.prototype.init,
  41. _toggleColumn = BootstrapTable.prototype.toggleColumn,
  42. _toggleView = BootstrapTable.prototype.toggleView,
  43. _resetView = BootstrapTable.prototype.resetView;
  44. BootstrapTable.prototype.init = function () {
  45. _init.apply(this, Array.prototype.slice.apply(arguments));
  46. if (this.options.resizable) {
  47. initResizable(this);
  48. }
  49. };
  50. BootstrapTable.prototype.toggleColumn = function () {
  51. _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
  52. if (this.options.resizable) {
  53. initResizable(this);
  54. }
  55. };
  56. BootstrapTable.prototype.toggleView = function () {
  57. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  58. if (this.options.resizable) {
  59. if (this.options.cardView) {
  60. //Deletes the plugin
  61. $(this.$el).colResizable({disable: true});
  62. return;
  63. }
  64. initResizable(this);
  65. }
  66. };
  67. BootstrapTable.prototype.resetView = function () {
  68. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  69. if (this.options.resizable) {
  70. initResizable(this);
  71. }
  72. };
  73. BootstrapTable.prototype.onResize = function (e) {
  74. var that = $(e.currentTarget);
  75. that.bootstrapTable('resetView');
  76. that.data('bootstrap.table').options.onResizableResize.apply(e);
  77. }
  78. })(jQuery);