bootstrap-table-resizable.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 (that) {
  9. //Deletes the plugin to re-create it
  10. that.$el.colResizable({disable: true});
  11. //Creates the plugin
  12. that.$el.colResizable({
  13. liveDrag: that.options.liveDrag,
  14. fixed: that.options.fixed,
  15. headerOnly: that.options.headerOnly,
  16. minWidth: that.options.minWidth,
  17. hoverCursor: that.options.hoverCursor,
  18. dragCursor: that.options.dragCursor,
  19. onResize: that.onResize,
  20. onDrag: that.options.onResizableDrag
  21. });
  22. };
  23. $.extend($.fn.bootstrapTable.defaults, {
  24. resizable: false,
  25. liveDrag: false,
  26. fixed: true,
  27. headerOnly: false,
  28. minWidth: 15,
  29. hoverCursor: 'e-resize',
  30. dragCursor: 'e-resize',
  31. onResizableResize: function (e) {
  32. return false;
  33. },
  34. onResizableDrag: function (e) {
  35. return false;
  36. }
  37. });
  38. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  39. _toggleView = BootstrapTable.prototype.toggleView,
  40. _resetView = BootstrapTable.prototype.resetView;
  41. BootstrapTable.prototype.toggleView = function () {
  42. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  43. if (this.options.resizable && this.options.cardView) {
  44. //Deletes the plugin
  45. $(this.$el).colResizable({disable: true});
  46. }
  47. };
  48. BootstrapTable.prototype.resetView = function () {
  49. var that = this;
  50. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  51. if (this.options.resizable) {
  52. // because in fitHeader function, we use setTimeout(func, 100);
  53. setTimeout(function () {
  54. initResizable(that);
  55. }, 100);
  56. }
  57. };
  58. BootstrapTable.prototype.onResize = function (e) {
  59. var that = $(e.currentTarget);
  60. that.bootstrapTable('resetView');
  61. that.data('bootstrap.table').options.onResizableResize.apply(e);
  62. }
  63. })(jQuery);