From cb9447b2c3579e1f00b7d9318ca8ba7f42ff7beb Mon Sep 17 00:00:00 2001 From: David LaPalomento Date: Tue, 26 Nov 2013 15:45:45 -0500 Subject: [PATCH 1/3] Fix typo in test description availble -> available --- test/unit/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/api.js b/test/unit/api.js index fae7fae0bc..205641bd26 100644 --- a/test/unit/api.js +++ b/test/unit/api.js @@ -91,7 +91,7 @@ test('should be able to initialize player twice on the same tag using string ref player.dispose(); }); -test('videojs.players should be availble after minification', function() { +test('videojs.players should be available after minification', function() { var videoTag = PlayerTest.makeTag(); var id = videoTag.id; From c69290c39fd64cc350bd6104ca5d5ceb42dc2ce4 Mon Sep 17 00:00:00 2001 From: David LaPalomento Date: Tue, 26 Nov 2013 15:46:20 -0500 Subject: [PATCH 2/3] Don't use minifiable player methods in fullscreenToggle Use string literals to lookup fullscreen-related methods on the player object in the fullscreenToggle component. Otherwise, closure compiler replaces them with minified method names and makes it impossible to supply a simpler "player" object with customized fullscreen logic for the fullscreenToggle to interact with. --- src/js/control-bar/fullscreen-toggle.js | 6 ++--- test/unit/api.js | 30 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/js/control-bar/fullscreen-toggle.js b/src/js/control-bar/fullscreen-toggle.js index 3e16b4379c..eb123c6ffd 100644 --- a/src/js/control-bar/fullscreen-toggle.js +++ b/src/js/control-bar/fullscreen-toggle.js @@ -23,11 +23,11 @@ vjs.FullscreenToggle.prototype.buildCSSClass = function(){ }; vjs.FullscreenToggle.prototype.onClick = function(){ - if (!this.player_.isFullScreen) { - this.player_.requestFullScreen(); + if (!this.player_['isFullScreen']) { + this.player_['requestFullScreen'](); this.el_.children[0].children[0].innerHTML = 'Non-Fullscreen'; // change the button text to "Non-Fullscreen" } else { - this.player_.cancelFullScreen(); + this.player_['cancelFullScreen'](); this.el_.children[0].children[0].innerHTML = 'Fullscreen'; // change the button to "Fullscreen" } }; diff --git a/test/unit/api.js b/test/unit/api.js index 205641bd26..d74bf48fe9 100644 --- a/test/unit/api.js +++ b/test/unit/api.js @@ -103,3 +103,33 @@ test('videojs.players should be available after minification', function() { player.dispose(); }); + +test('fullscreenToggle does not depend on minified player methods', function(){ + var noop, player, fullscreen, requestFullScreen, cancelFullScreen; + noop = function(){}; + requestFullScreen = false; + cancelFullScreen = false; + player = { + id: noop, + on: noop, + ready: noop + }; + + player['requestFullScreen'] = function(){ + requestFullScreen = true; + }; + player['cancelFullScreen'] = function(){ + cancelFullScreen = true; + }; + player['isFullScreen'] = false; + + fullscreen = new videojs.FullscreenToggle(player); + fullscreen.trigger('click'); + + ok(requestFullScreen, 'requestFullScreen called'); + + player.isFullScreen = true; + fullscreen.trigger('click'); + + ok(cancelFullScreen, 'cancelFullScreen called'); +}); From 7efcbd5e19686ef64764c5357e1be9a8fd860cfa Mon Sep 17 00:00:00 2001 From: David LaPalomento Date: Tue, 26 Nov 2013 18:42:37 -0500 Subject: [PATCH 3/3] Use externs to prevent obfuscation Instead of using string literals, create an externs file for the player and use that to ensure fullscreen functionality is never minified. --- Gruntfile.js | 4 ++-- src/js/control-bar/fullscreen-toggle.js | 6 +++--- src/js/player.externs.js | 11 +++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 src/js/player.externs.js diff --git a/Gruntfile.js b/Gruntfile.js index 7b2112cc45..f3404e39aa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,12 +52,12 @@ module.exports = function(grunt) { minify: { source:{ src: ['build/files/combined.video.js', 'build/compiler/goog.base.js', 'src/js/exports.js'], - externs: ['src/js/media/flash.externs.js'], + externs: ['src/js/player.externs.js', 'src/js/media/flash.externs.js'], dest: 'build/files/minified.video.js' }, tests: { src: ['build/files/combined.video.js', 'build/compiler/goog.base.js', 'src/js/exports.js', 'test/unit/*.js', '!test/unit/api.js'], - externs: ['src/js/media/flash.externs.js', 'test/qunit/qunit-externs.js'], + externs: ['src/js/player.externs.js', 'src/js/media/flash.externs.js', 'test/qunit/qunit-externs.js'], dest: 'build/files/test.minified.video.js' } }, diff --git a/src/js/control-bar/fullscreen-toggle.js b/src/js/control-bar/fullscreen-toggle.js index eb123c6ffd..3e16b4379c 100644 --- a/src/js/control-bar/fullscreen-toggle.js +++ b/src/js/control-bar/fullscreen-toggle.js @@ -23,11 +23,11 @@ vjs.FullscreenToggle.prototype.buildCSSClass = function(){ }; vjs.FullscreenToggle.prototype.onClick = function(){ - if (!this.player_['isFullScreen']) { - this.player_['requestFullScreen'](); + if (!this.player_.isFullScreen) { + this.player_.requestFullScreen(); this.el_.children[0].children[0].innerHTML = 'Non-Fullscreen'; // change the button text to "Non-Fullscreen" } else { - this.player_['cancelFullScreen'](); + this.player_.cancelFullScreen(); this.el_.children[0].children[0].innerHTML = 'Fullscreen'; // change the button to "Fullscreen" } }; diff --git a/src/js/player.externs.js b/src/js/player.externs.js new file mode 100644 index 0000000000..9087cec986 --- /dev/null +++ b/src/js/player.externs.js @@ -0,0 +1,11 @@ +/** + * @fileoverview Externs for videojs.Player. Externs are functions that the + * compiler shouldn't obfuscate. + */ + +/** + * Fullscreen functionality + */ +videojs.Player.prototype.isFullScreen = undefined; +videojs.Player.prototype.requestFullScreen = function(){}; +videojs.Player.prototype.cancelFullScreen = function(){};