132 lines
4.8 KiB
JavaScript
132 lines
4.8 KiB
JavaScript
/**!
|
|
* lg-fullscreen.js | 1.1.0 | February 23rd 2019
|
|
* http://sachinchoolur.github.io/lg-fullscreen.js
|
|
* Copyright (c) 2016 Sachin N;
|
|
* @license GPLv3
|
|
*/(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LgFullscreen = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
|
(function (global, factory) {
|
|
if (typeof define === "function" && define.amd) {
|
|
define([], factory);
|
|
} else if (typeof exports !== "undefined") {
|
|
factory();
|
|
} else {
|
|
var mod = {
|
|
exports: {}
|
|
};
|
|
factory();
|
|
global.lgFullscreen = mod.exports;
|
|
}
|
|
})(this, function () {
|
|
'use strict';
|
|
|
|
var _extends = Object.assign || function (target) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
var source = arguments[i];
|
|
|
|
for (var key in source) {
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
target[key] = source[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
var fullscreenDefaults = {
|
|
fullScreen: true
|
|
};
|
|
|
|
function isFullScreen() {
|
|
return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement;
|
|
}
|
|
|
|
var Fullscreen = function Fullscreen(element) {
|
|
|
|
this.el = element;
|
|
|
|
this.core = window.lgData[this.el.getAttribute('lg-uid')];
|
|
this.core.s = _extends({}, fullscreenDefaults, this.core.s);
|
|
|
|
this.init();
|
|
|
|
return this;
|
|
};
|
|
|
|
Fullscreen.prototype.init = function () {
|
|
var fullScreen = '';
|
|
if (this.core.s.fullScreen) {
|
|
|
|
// check for fullscreen browser support
|
|
if (!document.fullscreenEnabled && !document.webkitFullscreenEnabled && !document.mozFullScreenEnabled && !document.msFullscreenEnabled) {
|
|
return;
|
|
} else {
|
|
fullScreen = '<span class="lg-fullscreen lg-icon"></span>';
|
|
this.core.outer.querySelector('.lg-toolbar').insertAdjacentHTML('beforeend', fullScreen);
|
|
this.fullScreen();
|
|
}
|
|
}
|
|
};
|
|
|
|
Fullscreen.prototype.requestFullscreen = function () {
|
|
var el = document.documentElement;
|
|
if (el.requestFullscreen) {
|
|
el.requestFullscreen();
|
|
} else if (el.msRequestFullscreen) {
|
|
el.msRequestFullscreen();
|
|
} else if (el.mozRequestFullScreen) {
|
|
el.mozRequestFullScreen();
|
|
} else if (el.webkitRequestFullscreen) {
|
|
el.webkitRequestFullscreen();
|
|
}
|
|
};
|
|
|
|
Fullscreen.prototype.exitFullscreen = function () {
|
|
if (document.exitFullscreen) {
|
|
document.exitFullscreen();
|
|
} else if (document.msExitFullscreen) {
|
|
document.msExitFullscreen();
|
|
} else if (document.mozCancelFullScreen) {
|
|
document.mozCancelFullScreen();
|
|
} else if (document.webkitExitFullscreen) {
|
|
document.webkitExitFullscreen();
|
|
}
|
|
};
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode
|
|
Fullscreen.prototype.fullScreen = function () {
|
|
var _this = this;
|
|
|
|
utils.on(document, 'fullscreenchange.lgfullscreen webkitfullscreenchange.lgfullscreen mozfullscreenchange.lgfullscreen MSFullscreenChange.lgfullscreen', function () {
|
|
if (utils.hasClass(_this.core.outer, 'lg-fullscreen-on')) {
|
|
utils.removeClass(_this.core.outer, 'lg-fullscreen-on');
|
|
} else {
|
|
utils.addClass(_this.core.outer, 'lg-fullscreen-on');
|
|
}
|
|
});
|
|
|
|
utils.on(this.core.outer.querySelector('.lg-fullscreen'), 'click.lg', function () {
|
|
if (isFullScreen()) {
|
|
_this.exitFullscreen();
|
|
} else {
|
|
_this.requestFullscreen();
|
|
}
|
|
});
|
|
};
|
|
|
|
Fullscreen.prototype.destroy = function () {
|
|
|
|
// exit from fullscreen if activated
|
|
if (isFullScreen()) {
|
|
this.exitFullscreen();
|
|
}
|
|
|
|
utils.off(document, '.lgfullscreen');
|
|
};
|
|
|
|
window.lgModules.fullscreen = Fullscreen;
|
|
});
|
|
|
|
},{}]},{},[1])(1)
|
|
});
|