From 3d6e23154c666a201051dbc260e0355e3cc8254a Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 8 Aug 2011 11:18:26 -0400 Subject: [PATCH] [#678] Adds .mute()/.unmute() proto methods --- popcorn.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/popcorn.js b/popcorn.js index fb6cb93..5e84999 100644 --- a/popcorn.js +++ b/popcorn.js @@ -171,6 +171,11 @@ // Store track event history data history: [], + // Stores ad-hoc state related data] + state: { + volume: this.media.volume + }, + // Store track event object references by trackId trackRefs: {}, @@ -433,7 +438,7 @@ // an object with defined methods Popcorn.extend(Popcorn.p, (function() { - var methods = "load play pause currentTime playbackRate mute volume duration preload playbackRate " + + var methods = "load play pause currentTime playbackRate volume duration preload playbackRate " + "autoplay loop controls muted buffered readyState seeking paused played seekable ended", ret = {}; @@ -497,6 +502,36 @@ return this; }, + // Mute the calling media, optionally toggle + mute: function( toggle ) { + + var event = toggle == null ? "muted" : "unmuted"; + + // If `toggle` is explicitly `false`, + // unmute the media and restore the volume level + if ( toggle === false ) { + this.media.muted = false; + this.media.volume = this.data.state.volume; + } + + // If `toggle` is either null or undefined, + // save the current volume and mute the media element + if ( toggle == null ) { + this.data.state.volume = this.media.volume; + this.media.muted = true; + } + + // Trigger either muted|unmuted event + this.trigger( event ); + + return this; + }, + + // Convenience method, unmute the calling media + unmute: function() { + return this.mute( false ); + }, + // Get the client bounding box of an instance element position: function() { return Popcorn.position( this.media ); -- 2.43.0