lg-fullscreen.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*! lightgallery - v1.2.21 - 2016-06-28
  2. * http://sachinchoolur.github.io/lightGallery/
  3. * Copyright (c) 2016 Sachin N; Licensed Apache 2.0 */
  4. (function($, window, document, undefined) {
  5. 'use strict';
  6. var defaults = {
  7. fullScreen: true
  8. };
  9. var Fullscreen = function(element) {
  10. // get lightGallery core plugin data
  11. this.core = $(element).data('lightGallery');
  12. this.$el = $(element);
  13. // extend module defalut settings with lightGallery core settings
  14. this.core.s = $.extend({}, defaults, this.core.s);
  15. this.init();
  16. return this;
  17. };
  18. Fullscreen.prototype.init = function() {
  19. var fullScreen = '';
  20. if (this.core.s.fullScreen) {
  21. // check for fullscreen browser support
  22. if (!document.fullscreenEnabled && !document.webkitFullscreenEnabled &&
  23. !document.mozFullScreenEnabled && !document.msFullscreenEnabled) {
  24. return;
  25. } else {
  26. fullScreen = '<span class="lg-fullscreen lg-icon"></span>';
  27. this.core.$outer.find('.lg-toolbar').append(fullScreen);
  28. this.fullScreen();
  29. }
  30. }
  31. };
  32. Fullscreen.prototype.requestFullscreen = function() {
  33. var el = document.documentElement;
  34. if (el.requestFullscreen) {
  35. el.requestFullscreen();
  36. } else if (el.msRequestFullscreen) {
  37. el.msRequestFullscreen();
  38. } else if (el.mozRequestFullScreen) {
  39. el.mozRequestFullScreen();
  40. } else if (el.webkitRequestFullscreen) {
  41. el.webkitRequestFullscreen();
  42. }
  43. };
  44. Fullscreen.prototype.exitFullscreen = function() {
  45. if (document.exitFullscreen) {
  46. document.exitFullscreen();
  47. } else if (document.msExitFullscreen) {
  48. document.msExitFullscreen();
  49. } else if (document.mozCancelFullScreen) {
  50. document.mozCancelFullScreen();
  51. } else if (document.webkitExitFullscreen) {
  52. document.webkitExitFullscreen();
  53. }
  54. };
  55. // https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
  56. Fullscreen.prototype.fullScreen = function() {
  57. var _this = this;
  58. $(document).on('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg', function() {
  59. _this.core.$outer.toggleClass('lg-fullscreen-on');
  60. });
  61. this.core.$outer.find('.lg-fullscreen').on('click.lg', function() {
  62. if (!document.fullscreenElement &&
  63. !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
  64. _this.requestFullscreen();
  65. } else {
  66. _this.exitFullscreen();
  67. }
  68. });
  69. };
  70. Fullscreen.prototype.destroy = function() {
  71. // exit from fullscreen if activated
  72. this.exitFullscreen();
  73. $(document).off('fullscreenchange.lg webkitfullscreenchange.lg mozfullscreenchange.lg MSFullscreenChange.lg');
  74. };
  75. $.fn.lightGallery.modules.fullscreen = Fullscreen;
  76. })(jQuery, window, document);