blueimp-gallery-fullscreen.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * blueimp Gallery Fullscreen JS
  3. * https://github.com/blueimp/Gallery
  4. *
  5. * Copyright 2013, Sebastian Tschan
  6. * https://blueimp.net
  7. *
  8. * Licensed under the MIT license:
  9. * https://opensource.org/licenses/MIT
  10. */
  11. /* global define */
  12. ;(function (factory) {
  13. 'use strict'
  14. if (typeof define === 'function' && define.amd) {
  15. // Register as an anonymous AMD module:
  16. define(['./blueimp-helper', './blueimp-gallery'], factory)
  17. } else {
  18. // Browser globals:
  19. factory(window.blueimp.helper || window.jQuery, window.blueimp.Gallery)
  20. }
  21. })(function ($, Gallery) {
  22. 'use strict'
  23. $.extend(Gallery.prototype.options, {
  24. // Defines if the gallery should open in fullscreen mode:
  25. fullScreen: false
  26. })
  27. var initialize = Gallery.prototype.initialize
  28. var close = Gallery.prototype.close
  29. $.extend(Gallery.prototype, {
  30. getFullScreenElement: function () {
  31. return (
  32. document.fullscreenElement ||
  33. document.webkitFullscreenElement ||
  34. document.mozFullScreenElement ||
  35. document.msFullscreenElement
  36. )
  37. },
  38. requestFullScreen: function (element) {
  39. if (element.requestFullscreen) {
  40. element.requestFullscreen()
  41. } else if (element.webkitRequestFullscreen) {
  42. element.webkitRequestFullscreen()
  43. } else if (element.mozRequestFullScreen) {
  44. element.mozRequestFullScreen()
  45. } else if (element.msRequestFullscreen) {
  46. element.msRequestFullscreen()
  47. }
  48. },
  49. exitFullScreen: function () {
  50. if (document.exitFullscreen) {
  51. document.exitFullscreen()
  52. } else if (document.webkitCancelFullScreen) {
  53. document.webkitCancelFullScreen()
  54. } else if (document.mozCancelFullScreen) {
  55. document.mozCancelFullScreen()
  56. } else if (document.msExitFullscreen) {
  57. document.msExitFullscreen()
  58. }
  59. },
  60. initialize: function () {
  61. initialize.call(this)
  62. if (this.options.fullScreen && !this.getFullScreenElement()) {
  63. this.requestFullScreen(this.container[0])
  64. }
  65. },
  66. close: function () {
  67. if (this.getFullScreenElement() === this.container[0]) {
  68. this.exitFullScreen()
  69. }
  70. close.call(this)
  71. }
  72. })
  73. return Gallery
  74. })