bootstrap-table-mobile.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @author: Dennis Hernández
  3. * @webSite: http://djhvscf.github.io/Blog
  4. * @version: v1.1.0
  5. */
  6. !function ($) {
  7. 'use strict';
  8. var resetView = function (el) {
  9. if (el.options.height || el.options.showFooter) {
  10. setTimeout(el.resetView(), 1);
  11. }
  12. };
  13. var changeView = function (el, width, height) {
  14. if (el.options.minHeight) {
  15. if (checkValuesLessEqual(width, el.options.minWidth) && checkValuesLessEqual(height, el.options.minHeight)) {
  16. checkToggledStatus(false, true, el);
  17. } else if (checkValuesGreater(width, el.options.minWidth) && checkValuesGreater(height, el.options.minHeight)) {
  18. checkToggledStatus(true, false, el);
  19. }
  20. } else {
  21. if (checkValuesLessEqual(width, el.options.minWidth)) {
  22. checkToggledStatus(false, true, el);
  23. } else if (checkValuesGreater(width, el.options.minWidth)) {
  24. checkToggledStatus(true, false, el);
  25. }
  26. }
  27. resetView(el);
  28. };
  29. var checkValuesLessEqual = function (currentValue, targetValue) {
  30. return currentValue <= targetValue;
  31. };
  32. var checkValuesGreater = function (currentValue, targetValue) {
  33. return currentValue > targetValue;
  34. };
  35. var checkToggledStatus = function (targetToggledStatus, newToggledStatus, el) {
  36. if (el.options.toggled === targetToggledStatus) {
  37. el.toggleView();
  38. el.options.toggled = newToggledStatus;
  39. }
  40. };
  41. $.extend($.fn.bootstrapTable.defaults, {
  42. mobileResponsive: false,
  43. minWidth: 562,
  44. minHeight: undefined,
  45. checkOnInit: true,
  46. toggled: false
  47. });
  48. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  49. _init = BootstrapTable.prototype.init;
  50. BootstrapTable.prototype.init = function () {
  51. _init.apply(this, Array.prototype.slice.apply(arguments));
  52. if (!this.options.mobileResponsive) {
  53. return;
  54. }
  55. if (!this.options.minWidth) {
  56. return;
  57. }
  58. var that = this;
  59. $(window).resize(function () {
  60. changeView(that, $(this).width(), $(this).height())
  61. });
  62. if (this.options.checkOnInit) {
  63. changeView(this, $(window).width(), $(window).height());
  64. }
  65. };
  66. }(jQuery);