/************************************************************************** * HTML5 Video Background * @info: http://www.codegrape.com/item/html5-video-background/1306 * @version: 1.0 (29.03.2012) * @requires: jQuery v1.7 or later (tested on 1.10.1) * @author: flashblue - http://www.codegrape.com/user/flashblue **************************************************************************/ ; (function ($) { $.fn.videoBG = function (f) { var g = { autoplay: true, loop: true, muted: false, videoVolume: 1, aspectRatio: 3, mp4: false, webm: false, flv: false, ogg: false, mp4Mobile: false, webmMobile: false, flvMobile: false, oggMobile: false, pattern: "", patternOpacity: 1, videoEndURL: "" }; var f = $.extend({}, g, f); var i = false; var j = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) ? true : false; var k = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i) ? false : true; var gsIsMobileDevice = window.location.href.toLowerCase().indexOf("/websitebuilder.aspx") < 0 && gsIsActualMobileOrTablet() ? true : false; if (f.mp4 && !f.mp4Mobile) { f.mp4Mobile = f.mp4 } if (f.webm && !f.webmMobile) { f.webmMobile = f.webm } if (f.flv && !f.flvMobile) { f.flvMobile = f.flv } if (f.ogg && !f.oggMobile) { f.oggMobile = f.ogg } //var l = window.location.href.toLowerCase().indexOf("/websitebuilder.aspx") > 0 ? $(".gs-main-wrapper") : $(window); // *** Goshly Dev Team - new/modified code - 28 Sep 2017 var l = $(window); if (window.location.href.toLowerCase().indexOf("/websitebuilder.aspx") > 0) { var windowHeight = $(window).height(); var wraperHeight = $(".gs-main-wrapper").height(); if (windowHeight > wraperHeight) { l = $(".gs-main-wrapper"); } } var m, winH; var n = $(this); var o, objVideo; var p = 0, videoH = 0; var q = $('
'); var r = $(''); var s = $(''); var t = $(''); var u = false; if (gsIsMobileDevice && f.pattern.length > 0) { q.css({ backgroundImage: 'url("' + f.pattern + '")', backgroundRepeat: "no-repeat", backgroundSize: "cover" }); s.hide(); } n.append(q); q.append(r); l.resize(resizeVideo); $("#gs-main-wrapper-resize-trigger").click(function (e) { resizeVideo(e); }); $("#gs-viewport-desktop").click(function (e) { resizeVideo(e); }); $("#gs-viewport-tablet-portrait").click(function (e) { resizeVideo(e); }); $("#gs-viewport-tablet-landscape").click(function (e) { resizeVideo(e); }); $("#gs-viewport-mobile-portrait").click(function (e) { resizeVideo(e); }); $("#gs-viewport-mobile-landscape").click(function (e) { resizeVideo(e); }); if (Modernizr.video && (f.mp4 || f.webm || f.ogg)) { createHTML5() } else { var v = swfobject.getFlashPlayerVersion(); if (v.major > 9) { createFlash() } } function createHTML5() { var a = "", type = "", error = false; if (Modernizr.video.h264 && f.mp4) { a = !j ? f.mp4 : f.mp4Mobile; type = "video/mp4" } else if (Modernizr.video.ogg && f.ogg) { a = !j ? f.ogg : f.oggMobile; type = "video/ogg" } else if (Modernizr.video.webm && f.webm) { a = !j ? f.webm : f.webmMobile; type = "video/webm" } else { error = true } q.append(t); if (!error) { var b = ' preload="' + (j ? "auto" : "metadata") + '"'; if (f.autoplay) { b += ' autoplay="autoplay"' } if (f.loop) { b += ' loop="loop"' } //var mobileOnlyAttrs = gsIsMobileDevice ? " playsinline='true' muted='true' " : ""; var mobileOnlyAttrs = " playsinline='true' muted='true' "; b += mobileOnlyAttrs; var c = ''; r.html(c); objVideo = r.find(".video-container"); //if (gsIsMobileDevice) { // objVideo.hide(); //} o = objVideo[0]; o.volume = !f.muted ? f.videoVolume : 0; o.addEventListener("ended", videoEnded, false); o.addEventListener("loadedmetadata", videoMetadata, false); o.addEventListener("waiting", videoWaiting); o.addEventListener("playing", videoPlaying); o.load(); i = true } } function videoMetadata(e) { o.removeEventListener("loadedmetadata", videoMetadata, false); p = o.videoWidth; videoH = o.videoHeight; if (f.pattern != "") { createPattern() } resizeVideo(); r.show(); if (!k) { o.play() } } function videoEnded(e) { if (f.videoEndURL != "") { goToUrl() } } function videoWaiting(e) { t.fadeIn() } function videoPlaying(e) { t.fadeOut() } function createPattern() { s.css({ "background-image": "url(" + f.pattern + ")", "opacity": f.patternOpacity }); q.append(s) } function createFlash() { var a = "", error = false; if (f.mp4) { a = !j ? f.mp4 : f.mp4Mobile } else if (f.flv) { a = !j ? f.flv : f.flvMobile } else { error = true } if (!error) { resizeVideo(); var b = { videoUrl: "../" + a, fullSizeView: (f.aspectRatio + 1), defaultVolume: f.videoVolume, pattern: f.pattern, patternAlpha: f.patternOpacity, loop: f.loop, muted: f.muted, videoEndURL: f.videoEndURL }; var c = { scale: "noscale", allowFullScreen: "true", menu: "false", bgcolor: "#000000", wmode: "transparent" }; var d = { name: "video-bg-swf" }; swfobject.embedSWF("flash/videobg.swf", "video-bg-holder", "100%", "100%", "9", null, b, c, d, callbackFlash); r.show() } } function callbackFlash(e) { o = document.getElementById(e.id) } function goToUrl() { window.location = f.videoEndURL } function resizeVideo(e) { m = l.width(); winH = l.height(); var a = m / p, yScale = winH / videoH, scale = 1, w = 0, h = 0, x = 0, y = 0; switch (f.aspectRatio) { case 0: if (m < p || winH < videoH) { scale = Math.min(a, yScale) } w = Math.ceil(p * scale); h = Math.ceil(videoH * scale); x = Math.ceil((m - w) / 2); y = Math.ceil((winH - h) / 2); break; case 1: scale = Math.min(a, yScale); w = Math.ceil(p * scale); h = Math.ceil(videoH * scale); x = Math.ceil((m - w) / 2); y = Math.ceil((winH - h) / 2); break; case 2: w = m; h = winH; x = 0; y = 0; break; case 3: default: scale = Math.max(a, yScale); w = Math.ceil(p * scale); h = Math.ceil(videoH * scale); x = Math.ceil((m - w) / 2); y = Math.ceil((winH - h) / 2); break } if (i) { objVideo.css({ "width": w + "px", "height": h + "px" }); r.css({ "left": x + "px", "top": y + "px" }); if (f.pattern != "") { s.css({ "left": x + "px", "top": y + "px", "width": w + "px", "height": h + "px" }) } } else { r.css({ "width": m + "px", "height": winH + "px" }) } } function isPlaying() { if (i) { return !o.paused } else { return o.isPlaying() } } videoBg_play = function () { if (i) { o.play() } else { o.resume() } }; videoBg_pause = function () { o.pause() }; videoBg_toggle_play = function () { if (isPlaying()) { videoBg_pause() } else { videoBg_play() } }; videoBg_rewind = function () { if (i) { o.currentTime = 0 } else { o.rewind() } }; function isMuted() { if (i) { return !(o.volume) } else { return o.isMute() } } videoBg_mute = function () { if (i) { o.volume = 0 } else { o.mute() } }; videoBg_unmute = function () { if (i) { o.volume = f.videoVolume } else { o.unmute() } }; videoBg_toggle_sound = function () { if (isMuted()) { videoBg_unmute() } else { videoBg_mute() } }; videoBg_show = function () { videoBg_play(); q.stop().fadeTo(600, 1); u = false }; videoBg_hide = function () { videoBg_pause(); q.stop().fadeTo(600, 0); u = true }; videoBg_toggle_hide = function () { if (u) { videoBg_show() } else { videoBg_hide() } } } })(jQuery);