1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

Close GH-346: Remove need for good.require/good.provide.

This commit is contained in:
David LaPalomento 2013-02-22 22:26:58 -05:00 committed by Steve Heffernan
parent 191a9d671d
commit 60f9b505f1
19 changed files with 140 additions and 204 deletions

View File

@ -5,6 +5,16 @@ module.exports = function(grunt) {
pkg: grunt.file.readJSON('package.json'),
build: {
src: 'src/js/dependencies.js',
options: {
baseDir: 'src/js/'
}
},
deps: {
src: 'src/js/dependencies.js',
options: {
baseDir: 'src/js/'
}
},
clean: {
build: ['build/files/*'],
@ -22,13 +32,12 @@ module.exports = function(grunt) {
},
minify: {
source:{
sourcelist: 'build/files/sourcelist.txt',
src: ['build/files/combined.video.js'],
externs: ['src/js/media.flash.externs.js'],
dest: 'build/files/minified.video.js'
},
tests: {
sourcelist: 'build/files/sourcelist.txt',
src: ['test/unit/*.js'],
src: ['build/files/combined.video.js', 'test/unit/*.js'],
externs: ['src/js/media.flash.externs.js', 'test/qunit/qunit-externs.js'],
dest: 'build/files/test.minified.video.js'
}
@ -42,17 +51,6 @@ module.exports = function(grunt) {
files: [ 'src/**/*.js', 'test/unit/*.js' ],
tasks: 'dev'
}
// Copy is broken. Waiting for an update to use.
// copy: {
// latest: {
// files: [
// { src: ['dist/video-js'], dest: 'dist/latest' } // includes files in path
// // {src: ['path/**'], dest: 'dest/'}, // includes files in path and its subdirs
// // {expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'}, // makes all src relative to cwd
// // {expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'} // flattens results to a single level
// ]
// }
// },
});
grunt.loadNpmTasks('grunt-contrib-jshint');
@ -70,48 +68,34 @@ module.exports = function(grunt) {
var fs = require('fs'),
gzip = require('zlib').gzip;
grunt.registerTask('build', 'Building Source', function(){
grunt.registerMultiTask('build', 'Building Source', function(){
/*jshint undef:false, evil:true */
// Loading predefined source order from source-loader.js
// Trust me, this is the easist way to do it so far.
var blockSourceLoading = true;
eval(grunt.file.read('./build/source-loader.js'));
// Fix windows file path delimiter issue
var i = sourceFiles.length;
while (i--) {
sourceFiles[i] = sourceFiles[i].replace(/\\/g, '/');
}
// grunt.file.write('build/files/sourcelist.txt', sourceList.join(','));
// Allow time for people to update their index.html before they remove these
grunt.file.write('build/files/sourcelist.js', 'var sourcelist = ["' + sourceFiles.join('","') + '"]');
// Create a combined sources file. https://github.com/zencoder/video-js/issues/287
var combined = '';
sourceFiles.forEach(function(result){
combined += grunt.file.read(result);
});
grunt.file.write('build/files/combined.video.js', combined);
grunt.file.copy('src/css/video-js.css', 'build/files/video-js.css');
grunt.file.copy('src/css/video-js.png', 'build/files/video-js.png');
grunt.file.copy('src/swf/video-js.swf', 'build/files/video-js.swf');
var calcdeps = require('calcdeps').calcdeps;
// caclcdeps is async
var done = this.async();
// In current version of calcdeps, not supplying certain
// options that should have defaults causes errors
// so we have all options listed here with their defaults.
calcdeps({
input: ['src/js/exports.js'],
path:['src/js/'],
dep:[],
exclude:[],
output_mode:'list'
}, function(err,results){
if (err) {
grunt.warn({ message: err });
grunt.log.writeln(err);
done(false);
}
if (results) {
var i = results.length;
while (i--) {
results[i] = results[i].replace(/\\/g, '/');
}
grunt.file.write('build/files/sourcelist.txt', results.join(','));
grunt.file.write('build/files/sourcelist.js', 'var sourcelist = ["' + results.join('","') + '"]');
// Create a combined sources file. https://github.com/zencoder/video-js/issues/287
var combined = '';
results.forEach(function(result){
combined += grunt.file.read(result);
});
grunt.file.write('build/files/combined.video.js', combined);
}
done();
});
});
grunt.registerMultiTask('minify', 'Minify JS files using Closure Compiler.', function() {
@ -174,5 +158,17 @@ module.exports = function(grunt) {
grunt.file.copy('build/files/video-js.swf', 'dist/video-js/video-js.swf');
grunt.file.copy('build/demo-files/demo.html', 'dist/video-js/demo.html');
grunt.file.copy('build/demo-files/demo.captions.vtt', 'dist/video-js/demo.captions.vtt');
// Copy is broken. Waiting for an update to use.
// copy: {
// latest: {
// files: [
// { src: ['dist/video-js'], dest: 'dist/latest' } // includes files in path
// // {src: ['path/**'], dest: 'dest/'}, // includes files in path and its subdirs
// // {expand: true, cwd: 'path/', src: ['**'], dest: 'dest/'}, // makes all src relative to cwd
// // {expand: true, flatten: true, src: ['path/**'], dest: 'dest/', filter: 'isFile'} // flattens results to a single level
// ]
// }
// },
});
};

59
build/source-loader.js Normal file
View File

@ -0,0 +1,59 @@
// This file is used to load the video.js source files into a page
// in the correct order based on dependencies.
// When you create a new source file you will need to add
// it to the list below to use it in sandbox/index.html and
// test/index.html
// You can use the projectRoot variable to adjust relative urls
// that this script loads. By default it's "../", which is what /sandbox
// and /test need. If you had sandbox/newDir/index.html, in index.html you
// would set projectRoot = "../../"
// We could use somehting like requireJS to load files, and at one point
// we used goog.require/provide to load dependencies, but that seems like
// overkill with the small number of files we actually have.
// ADD NEW SOURCE FILES HERE
var sourceFiles = [
"src/js/goog.base.js",
"src/js/core.js",
"src/js/events.js",
"src/js/lib.js",
"src/js/component.js",
"src/js/player.js",
"src/js/controls.js",
"src/js/media.js",
"src/js/media.html5.js",
"src/js/media.flash.js",
"src/js/tracks.js",
"src/js/json.js",
"src/js/setup.js",
"src/js/plugins.js",
"src/js/exports.js"
];
// Allow overriding the default project root
var projectRoot = projectRoot || '../';
function loadScripts(scriptsArr){
for (var i = 0; i < scriptsArr.length; i++) {
// Using document.write because that's the easiest way to avoid triggering
// asynchrnous script loading
document.write( "<script src='" + projectRoot + scriptsArr[i] + "'><\/script>" );
}
}
// We use this file in the grunt build script to load the same source file list
// and don't want to load the scripts there.
if (typeof blockSourceLoading === 'undefined') {
loadScripts(sourceFiles);
// Allow for making Flash first
if (window.location.href.indexOf("?flash") !== -1) {
// Using doc.write to load this script to, otherwise when it runs videojs
// is undefined
document.write('<script>videojs.options.techOrder = ["flash"];videojs.options.flash.swf = "../src/swf/video-js.swf";</script>')
}
}

View File

@ -6,43 +6,8 @@
<link href="../src/css/video-js.css" rel="stylesheet" type="text/css">
<!--[if IE]>
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
<!--<![endif]-->
<!-- GENERATED LIST OF SOURCE FILES -->
<script src="../build/files/sourcelist.js"></script>
<script>
(function(){
// Load source list generated by build script
if (!sourcelist) {
console.log('run `grunt` to generate source list');
} else {
var root = '../';
for (var i = 0; i < sourcelist.length; i++) {
document.write( "<script src='" + root + sourcelist[i] + "'><\/script>" );
}
}
// Easy access to test Flash over HTML5. Add ?flash to URL
if (window.location.href.indexOf("?flash") !== -1) {
videojs.options.techOrder = ["Flash"];
videojs.options.flash.swf = "../src/swf/video-js.swf";
}
})()
</script>
<script type="text/javascript" charset="utf-8">
// Easy access to test Flash over HTML5. Add ?flash to URL
if (window.location.href.indexOf("?flash") !== -1) {
videojs.options.techOrder = ["flash"];
videojs.options.flash.swf = "../src/swf/video-js.swf";
}
</script>
<!-- LOAD VIDEO.JS SOURCE FILES IN ORDER -->
<script src="../build/source-loader.js"></script>
</head>
<body>

View File

@ -6,42 +6,14 @@
<link href="../src/css/video-js.css" rel="stylesheet" type="text/css">
<!--[if IE]>
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
<!--<![endif]-->
<!-- LOAD VIDEO.JS SOURCE FILES IN ORDER -->
<script src="../build/source-loader.js"></script>
<!-- GENERATED LIST OF SOURCE FILES -->
<script src="../build/files/sourcelist.js"></script>
<script>
(function(){
// Load source list generated by build script
if (!sourcelist) {
console.log('run `grunt` to generate source list');
} else {
var root = '../';
for (var i = 0; i < sourcelist.length; i++) {
document.write( "<script src='" + root + sourcelist[i] + "'><\/script>" );
}
}
})()
</script>
<script>
// Easy access to test Flash over HTML5. Add ?flash to URL
if (window.location.href.indexOf("?flash") !== -1) {
videojs.options.techOrder = ["flash"];
videojs.options.flash.swf = "../src/swf/video-js.swf";
}
</script>
</head>
<body>
<p style="background-color:#eee; border: 1px solid #777; padding: 10px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;">This page shows you how to create, register and initialize a Video.js plugin.</p>
<video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'>
<video id="vid1" class="video-js vjs-default-skin" controls preload="auto" width="640" height="264" poster="http://video-js.zencoder.com/oceans-clip.png">
<source src="http://video-js.zencoder.com/oceans-clip.mp4" type='video/mp4'>
<source src="http://video-js.zencoder.com/oceans-clip.webm" type='video/webm'>
<source src="http://video-js.zencoder.com/oceans-clip.ogv" type='video/ogg'>

View File

@ -3,11 +3,6 @@
*
*/
goog.provide('vjs.Component');
goog.require('vjs.events');
goog.require('vjs.dom');
/**
* Base UI Component class
* @param {Object} player Main Player

12
src/js/controls.js vendored
View File

@ -2,12 +2,6 @@
* @fileoverview Controls classes for Video.js buttons, sliders, etc.
*/
goog.provide('vjs.Control');
goog.provide('vjs.Menu');
goog.provide('vjs.MenuItem');
goog.require('vjs.Player');
/**
* Base class for all control elements
* @param {vjs.Player|Object} player
@ -531,6 +525,10 @@ vjs.Slider.prototype.onMouseUp = function() {
};
vjs.Slider.prototype.update = function(){
// In VolumeBar init we have a setTimeout for update that pops and update to the end of the
// execution stack. The player is destroyed before then update will cause an error
if (!this.el_) return;
// If scrubbing, we could use a cached value to make the handle keep up with the user's mouse.
// On HTML5 browsers scrubbing is really smooth, but some flash players are slow, so we might want to utilize this later.
// var progress = (this.player_.scrubbing) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration();
@ -930,7 +928,7 @@ vjs.MuteToggle.prototype.update = function(){
} else if (vol < 0.67) {
level = 2;
}
// Don't rewrite the button text if the actual text doesn't change.
// This causes unnecessary and confusing information for screen reader users.
// This check is needed because this function gets called every time the volume level is changed.

View File

@ -2,9 +2,6 @@
* @fileoverview Main function src.
*/
goog.provide('vjs');
goog.provide('videojs');
// HTML5 Shiv. Must be in <head> to support older browsers.
document.createElement('video');document.createElement('audio');
@ -17,7 +14,7 @@ document.createElement('video');document.createElement('audio');
* @param {Function=} ready Optional ready callback
* @return {vjs.Player} A player instance
*/
vjs = function(id, options, ready){
var vjs = function(id, options, ready){
var tag; // Element of ID
// Allow for element or ID to be passed in

View File

@ -5,10 +5,6 @@
* robust as jquery's, so there's probably some differences.
*/
goog.provide('vjs.events');
goog.require('vjs');
/**
* Add an event listener to element
* It stores the handler function in a separate cache object

View File

@ -5,16 +5,6 @@
* be renamed by closure compiler.
*/
goog.require('vjs');
goog.require('vjs.Component');
goog.require('vjs.Player');
goog.require('vjs.Control');
goog.require('vjs.Html5');
goog.require('vjs.Flash');
goog.require('vjs.TextTrack');
goog.require('vjs.autoSetup');
goog.require('vjs.plugin');
/**
* vjs (internal only) = videojs = _V_ (external only)
*

View File

@ -4,19 +4,21 @@
* (Compiler doesn't like JSON not being declared)
*/
goog.provide('vjs.JSON');
/**
* Javascript JSON implementation
* (Parse Method Only)
* https://github.com/douglascrockford/JSON-js/blob/master/json2.js
* Only using for parse method when parsing data-setup attribute JSON.
* @type {Object}
* @suppress {undefinedVars}
*/
vjs.JSON;
if (JSON && JSON.parse === 'function') {
vjs.JSON = JSON;
/**
* @suppress {undefinedVars}
*/
if (typeof window.JSON !== 'undefined' && window.JSON.parse === 'function') {
vjs.JSON = window.JSON;
} else {
vjs.JSON = {};

View File

@ -1,8 +1,3 @@
goog.provide('vjs.dom');
goog.provide('vjs.obj');
goog.require('vjs');
/**
* Creates an element and applies properties.
* @param {String=} tagName Name of tag to be created.
@ -17,13 +12,13 @@ vjs.createEl = function(tagName, properties){
//el[propName] = properties[propName];
// Not remembering why we were checking for dash
// but using setAttribute means you have to use getAttribute
// The check for dash checks for the aria-* attributes, like aria-label, aria-valuemin.
// The additional check for "role" is because the default method for adding attributes does not
// add the attribute "role". My guess is because it's not a valid attribute in some namespaces, although
// browsers handle the attribute just fine. The W3C allows for aria-* attributes to be used in pre-HTML5 docs.
// http://www.w3.org/TR/wai-aria-primer/#ariahtml. Using setAttribute gets around this problem.
if (propName.indexOf('aria-') !== -1 || propName=='role') {
el.setAttribute(propName, properties[propName]);
} else {

View File

@ -4,10 +4,6 @@
* Not using setupTriggers. Using global onEvent func to distribute events
*/
goog.provide('vjs.Flash');
goog.require('vjs.MediaTechController');
/**
* HTML5 Media Controller - Wrapper for HTML5 Media API
* @param {vjs.Player|Object} player

View File

@ -2,10 +2,6 @@
* @fileoverview HTML5 Media Controller - Wrapper for HTML5 Media API
*/
goog.provide('vjs.Html5');
goog.require('vjs.MediaTechController');
/**
* HTML5 Media Controller - Wrapper for HTML5 Media API
* @param {vjs.Player|Object} player

View File

@ -2,10 +2,6 @@
* @fileoverview Media Technology Controller - Base class for media playback technology controllers like Flash and HTML5
*/
goog.provide('vjs.MediaTechController');
goog.require('vjs.Component');
/**
* Base class for media (HTML5 Video, Flash) controllers
* @param {vjs.Player|Object} player Central player instance

View File

@ -1,7 +1,3 @@
goog.provide('vjs.Player');
goog.require('vjs.Component');
/**
* Main player class. A player instance is returned by _V_(id);
* @param {Element} tag The original video tag used for configuring options

View File

@ -1,5 +1,3 @@
goog.provide('vjs.plugin');
vjs.plugin = function(name, init){
vjs.Player.prototype[name] = init;
};
};

View File

@ -3,11 +3,6 @@
* based on the data-setup attribute of the video tag
*/
goog.provide('vjs.autoSetup');
goog.require('vjs.JSON');
goog.require('vjs.events');
// Automatically set up any tags that have a data-setup attribute
vjs.autoSetup = function(){
var options, vid, player,

View File

@ -7,13 +7,6 @@
* Descriptions (not supported yet) - audio descriptions that are read back to the user by a screen reading device
*/
goog.provide('vjs.TextTrack');
goog.require('vjs.Menu');
goog.require('vjs.MenuItem');
goog.require('vjs.Component');
// Player Additions - Functions add to the player object for easier access to tracks
/**
@ -143,7 +136,7 @@ vjs.TextTrack = function(player, options){
this.activeCues_ = [];
this.readyState_ = 0;
this.mode_ = 0;
this.player_.on('fullscreenchange', vjs.bind(this, this.adjustFontSize));
};
goog.inherits(vjs.TextTrack, vjs.Component);
@ -872,7 +865,7 @@ vjs.TextTrackButton.prototype.onFocus = function(){
// This function is not needed anymore. Instead, the keyboard functionality is handled by
// treating the button as triggering a submenu. When the button is pressed, the submenu
// appears. Pressing the button again makes the submenu disappear.
/*
// Show the menu, and keep showing when the menu items are in focus
this.menu.lockShowing();
@ -912,7 +905,7 @@ vjs.TextTrackButton.prototype.onKeyPress = function(event){
this.pressButton();
}
}
// Check for escape (27) key
if (event.which == 27){
event.preventDefault();

View File

@ -3,6 +3,10 @@
<head>
<title>Video.js Test Suite</title>
<!--[if IE]>
<script src="https://getfirebug.com/releases/lite/1.4/firebug-lite.js"></script>
<!--<![endif]-->
<!-- QUnit -->
<link rel="stylesheet" href="../test/qunit/qunit/qunit.css" />
<script src="../test/qunit/qunit/qunit.js"></script>
@ -10,12 +14,9 @@
<!-- Video.js CSS -->
<link rel="stylesheet" href="../src/css/video-js.css" type="text/css">
<!-- GENERATED LIST OF SOURCE FILES -->
<script src="../build/files/sourcelist.js"></script>
<script type="text/javascript">
(function(){
var root = '../';
// ADD NEW TEST FILES HERE
var tests = [
'test/unit/lib.js',
@ -28,6 +29,8 @@
'test/unit/plugins.js'
];
var compiledTests = "build/files/test.minified.video.js";
var projectRoot = '../';
var scripts = [];
// Choose either the raw source and tests
@ -36,13 +39,11 @@
if (QUnit.urlParams.min || QUnit.urlParams.compiled) {
scripts.push(compiledTests);
} else {
// sourcelist is loaded by sourcelist.js
// which is built by `grunt build` or `grunt watch`
scripts = scripts.concat(sourcelist,tests);
scripts = scripts.concat(['build/source-loader.js'], tests);
}
for (var i = 0; i < scripts.length; i++) {
document.write( "<script src='" + root + scripts[i] + "'><\/script>" );
document.write( "<script src='" + projectRoot + scripts[i] + "'><\/script>" );
}
})()