bootstrap-table-mobile.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 toggled = false;
  9. var resetView = function (el) {
  10. if (el.options.height || el.options.showFooter) {
  11. setTimeout(el.resetView(), 1);
  12. }
  13. }
  14. var changeView = function (el, width, height) {
  15. if(width <= el.options.minWidth && height <= el.options.minHeight){
  16. if (!toggled) {
  17. el.toggleView();
  18. toggled = true;
  19. }
  20. } else if (width > el.options.minWidth && height > el.options.minHeight) {
  21. if (toggled) {
  22. el.toggleView()
  23. toggled = false;
  24. }
  25. }
  26. resetView(el);
  27. }
  28. $.extend($.fn.bootstrapTable.defaults, {
  29. mobileResponsive: false,
  30. minWidth: 562,
  31. minHeight: 562,
  32. checkOnInit: false
  33. });
  34. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  35. _init = BootstrapTable.prototype.init;
  36. BootstrapTable.prototype.init = function () {
  37. _init.apply(this, Array.prototype.slice.apply(arguments));
  38. if (!this.options.mobileResponsive) {
  39. return;
  40. }
  41. var that = this;
  42. $(window).resize(function () {
  43. changeView(that, $(this).width(), $(this).height())
  44. });
  45. if (this.options.checkOnInit) {
  46. changeView(this, $(window).width(), $(window).height());
  47. }
  48. };
  49. }(jQuery);