Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New functions: unbind (core) and unSyncWith (syncwith plugin)

  • Loading branch information...
commit 7a0d98dc226a1aa07c602619335a77970012d15a 1 parent 315c318
@oscarotero authored
View
4 demos/syncwith.html
@@ -30,6 +30,10 @@
video0.syncReady(function () {
this.play();
});
+
+ video0.timeline(5, function () {
+ this.unSyncWith(video1).unSyncWith(video2);
+ });
});
</script>
</head>
View
17 source/jquery.media.core.js
@@ -783,6 +783,23 @@
}
+
+ /**
+ * function unbind (event, fn)
+ *
+ * Unbind a function to specific event
+ */
+ $media.prototype.unbind = function (event, fn) {
+ if (fn) {
+ this.$element.unbind(event, $.proxy(fn, this));
+ } else {
+ this.$element.unbind(event);
+ }
+
+ return this;
+ }
+
+
/**
* function trigger (event, [data])
*
View
42 source/plugins/syncwith.js
@@ -21,8 +21,10 @@
return sync_ready;
}
- var synchronize = function (media, time) {
- $.each(media.sync, function (i, sync) {
+ var synchronize = function (event, time) {
+ var that = this;
+
+ $.each(that.sync, function (i, sync) {
if (sync.media.seeking()) {
return;
}
@@ -34,7 +36,7 @@
sync.media.seek(sync_offset + 0.1);
}
- if (media.playing()) {
+ if (that.playing()) {
sync.media.play();
} else {
sync.media.pause();
@@ -55,28 +57,38 @@
}
this.sync = [];
- this.syncing = 0;
this.sync.push({
media: media,
offset: offset
});
- this.play(function (event, time) {
- synchronize(this, time);
- });
+ this.bind('mediaPlay mediaPause mediaPlaying', synchronize);
- this.pause(function (event, time) {
- synchronize(this, time);
+ this.syncReady(function () {
+ $.proxy(synchronize, this)(null, this.time());
});
- this.playing(function (event, time) {
- synchronize(this, time);
- });
+ return this;
+ });
- this.syncReady(function () {
- synchronize(this, this.time());
- });
+ $media.extend('unSyncWith', function (media) {
+ if (!media) {
+ this.sync = [];
+ } else if ($.isArray(this.sync) && this.sync.length) {
+ for (var i = 0; i < this.sync.length; i++) {
+ if (this.sync[i].media.$element.is(media.$element)) {
+ this.sync.splice(i, 1);
+ break;
+ }
+ }
+ } else {
+ return this;
+ }
+
+ if (!this.sync.length) {
+ this.unbind('mediaPlay mediaPause mediaPlaying', synchronize);
+ }
return this;
});
Please sign in to comment.
Something went wrong with that request. Please try again.