From 2de06ee1338ec4c64df38deb77c31346e6a1c4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20L=C3=B6fquist?= Date: Wed, 28 May 2014 13:46:24 +0200 Subject: [PATCH] New methods: destroy, detach, reAttach --- bower.json | 2 +- dist/bg_video.js | 24 ++++++++++++++++++++++-- dist/bg_video.min.js | 4 ++-- package.json | 2 +- src/bg_video.coffee | 18 ++++++++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 070bdfd..d5cac13 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "BgVideo", - "version": "0.0.6", + "version": "0.0.7", "main": "dist/bg_video.js", "authors": [ "Emil Löfquist", "Emil Löfquist " diff --git a/dist/bg_video.js b/dist/bg_video.js index a759519..0754634 100644 --- a/dist/bg_video.js +++ b/dist/bg_video.js @@ -17,11 +17,13 @@ BgVideo = (function() { }; function BgVideo($elm, options, nativeAttributes) { + this.$elm = $elm; + this.$detachedElm = null; this.settings = { sources: [], cssPosition: 'absolute', alignment: 'top left', - hideBodyScrollsbars: true + hideBodyScrollbars: true }; this.attributes = { autoplay: 'autoplay', @@ -33,7 +35,7 @@ BgVideo = (function() { }; this.settings = $.extend(this.settings, options); this.attributes = $.extend(this.attributes, nativeAttributes); - if (this.settings.hideBodyScrollsbars) { + if (this.settings.hideBodyScrollbars) { $('body').css('overflow', 'hidden'); } this.$video = this.createVideoTag(); @@ -119,6 +121,24 @@ BgVideo = (function() { return mimeTypes[ext]; }; + BgVideo.prototype.destroy = function() { + this.pause(); + return this.$video.remove(); + }; + + BgVideo.prototype.detach = function() { + this.pause(); + return this.$detachedElm = this.$video.detach(); + }; + + BgVideo.prototype.reAttach = function() { + if (this.$detachedElm != null) { + this.$elm.append(this.$video); + this.play(); + return this.$detachedElm = null; + } + }; + return BgVideo; })(); diff --git a/dist/bg_video.min.js b/dist/bg_video.min.js index c996e75..0d47ed8 100644 --- a/dist/bg_video.min.js +++ b/dist/bg_video.min.js @@ -1,2 +1,2 @@ -/*! BgVideo 2014-05-16 */ -var BgVideo,root;root="undefined"!=typeof exports&&null!==exports?exports:this,$.supportsVideo=function(){return!!document.createElement("video").canPlayType},BgVideo=function(){function a(a,b,c){this.settings={sources:[],cssPosition:"absolute",alignment:"top left",hideBodyScrollsbars:!0},this.attributes={autoplay:"autoplay",controls:!1,loop:"loop",muted:"muted",poster:null,preload:"auto"},this.settings=$.extend(this.settings,b),this.attributes=$.extend(this.attributes,c),this.settings.hideBodyScrollsbars&&$("body").css("overflow","hidden"),this.$video=this.createVideoTag(),a.append(this.$video)}var b;return b={mp4:"video/mp4",m4v:"video/mp4",ogv:"video/ogg",webm:"video/webm"},a.prototype.play=function(){return this.$video.get(0).play()},a.prototype.pause=function(){return this.$video.get(0).pause()},a.prototype.mute=function(){return this.$video.prop("muted",!0)},a.prototype.unmute=function(){return this.$video.prop("muted",!1)},a.prototype.alignmentPosition=function(){switch(this.settings.alignment){case"top right":return{top:0,right:0};case"bottom left":return{bottom:0,left:0};case"bottom right":return{bottom:0,right:0};default:return{top:0,left:0}}},a.prototype.createVideoTag=function(){var a,b,c,d,e,f;for(a=$("