Skip to content

Commit

Permalink
New methods: destroy, detach, reAttach
Browse files Browse the repository at this point in the history
  • Loading branch information
ewal committed May 28, 2014
1 parent 73d325c commit 2de06ee
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"
Expand Down
24 changes: 22 additions & 2 deletions dist/bg_video.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand Down Expand Up @@ -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;

})();
Expand Down
4 changes: 2 additions & 2 deletions dist/bg_video.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "BgVideo",
"version": "0.0.6",
"version": "0.0.7",
"description": "",
"main": "Gruntfile.js",
"directories": {
Expand Down
18 changes: 18 additions & 0 deletions src/bg_video.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class BgVideo

constructor: ($elm, options, nativeAttributes) ->

@$elm = $elm

@$detachedElm = null

@settings =
sources: []
cssPosition: 'absolute' # static|fixed|absolute
Expand Down Expand Up @@ -70,4 +74,18 @@ class BgVideo
ext = source.split('.').pop().toLowerCase()
mimeTypes[ext]

destroy: ->
@pause()
@$video.remove()

detach: ->
@pause()
@$detachedElm = @$video.detach()

reAttach: ->
if @$detachedElm?
@$elm.append @$video
@play()
@$detachedElm = null

root.BgVideo = BgVideo

0 comments on commit 2de06ee

Please sign in to comment.