Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Fullscreen.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * --------------------------------------------
  3. * AdminLTE Fullscreen.js
  4. * License MIT
  5. * --------------------------------------------
  6. */
  7. import $ from 'jquery'
  8. /**
  9. * Constants
  10. * ====================================================
  11. */
  12. const NAME = 'Fullscreen'
  13. const DATA_KEY = 'lte.fullscreen'
  14. const JQUERY_NO_CONFLICT = $.fn[NAME]
  15. const SELECTOR_DATA_WIDGET = '[data-widget="fullscreen"]'
  16. const SELECTOR_ICON = `${SELECTOR_DATA_WIDGET} i`
  17. const Default = {
  18. minimizeIcon: 'fa-compress-arrows-alt',
  19. maximizeIcon: 'fa-expand-arrows-alt'
  20. }
  21. /**
  22. * Class Definition
  23. * ====================================================
  24. */
  25. class Fullscreen {
  26. constructor(_element, _options) {
  27. this.element = _element
  28. this.options = $.extend({}, Default, _options)
  29. }
  30. // Public
  31. static _jQueryInterface(config) {
  32. let data = $(this).data(DATA_KEY)
  33. if (!data) {
  34. data = $(this).data()
  35. }
  36. const _options = $.extend({}, Default, typeof config === 'object' ? config : data)
  37. const plugin = new Fullscreen($(this), _options)
  38. $(this).data(DATA_KEY, typeof config === 'object' ? config : data)
  39. if (typeof config === 'string' && /toggle|fullscreen|windowed/.test(config)) {
  40. plugin[config]()
  41. } else {
  42. plugin.init()
  43. }
  44. }
  45. toggle() {
  46. if (document.fullscreenElement ||
  47. document.mozFullScreenElement ||
  48. document.webkitFullscreenElement ||
  49. document.msFullscreenElement) {
  50. this.windowed()
  51. } else {
  52. this.fullscreen()
  53. }
  54. }
  55. fullscreen() {
  56. if (document.documentElement.requestFullscreen) {
  57. document.documentElement.requestFullscreen()
  58. } else if (document.documentElement.webkitRequestFullscreen) {
  59. document.documentElement.webkitRequestFullscreen()
  60. } else if (document.documentElement.msRequestFullscreen) {
  61. document.documentElement.msRequestFullscreen()
  62. }
  63. $(SELECTOR_ICON).removeClass(this.options.maximizeIcon).addClass(this.options.minimizeIcon)
  64. }
  65. // Static
  66. windowed() {
  67. if (document.exitFullscreen) {
  68. document.exitFullscreen()
  69. } else if (document.webkitExitFullscreen) {
  70. document.webkitExitFullscreen()
  71. } else if (document.msExitFullscreen) {
  72. document.msExitFullscreen()
  73. }
  74. $(SELECTOR_ICON).removeClass(this.options.minimizeIcon).addClass(this.options.maximizeIcon)
  75. }
  76. }
  77. /**
  78. * Data API
  79. * ====================================================
  80. */
  81. $(document).on('click', SELECTOR_DATA_WIDGET, function () {
  82. Fullscreen._jQueryInterface.call($(this), 'toggle')
  83. })
  84. /**
  85. * jQuery API
  86. * ====================================================
  87. */
  88. $.fn[NAME] = Fullscreen._jQueryInterface
  89. $.fn[NAME].Constructor = Fullscreen
  90. $.fn[NAME].noConflict = function () {
  91. $.fn[NAME] = JQUERY_NO_CONFLICT
  92. return Fullscreen._jQueryInterface
  93. }
  94. export default Fullscreen