Files
shaka-player/demo/load.js
T
Joey Parrish b8ccc02320 Fix support test on old browsers
- IE did not get forEach until IE 9, so it can't be used in
   polyfill.installAll().
 - Object.keys, console, and console.log.bind may all be unavailable
   on older browsers, so skip initialization of on-screen logging in
   the demo app if they are missing.  The support test will fail
   anyway.
 - 'catch' is a reserved word on older browsers, so use the two-arg
   version of then() to catch promise failures.

With these fixes, the support test can again be used on old browsers,
and the compiled-mode demo app can report an error back to IE 6.

Change-Id: I3019468f24a510a265ad5b13df4f01cd1bb1f34d
2016-04-07 20:51:24 +00:00

71 lines
2.8 KiB
JavaScript

/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Loads the library. Chooses compiled or debug version of the library based
* on the presence or absence of the URL parameter "compiled".
*
* This dynamic loading process is not necessary in a production environment,
* but greatly simplifies the process of switching between compiled and
* uncompiled mode during development.
*
* This is used in the provided demo app, but can also be used to load the
* uncompiled version of the library into your own application environment.
*/
(function() { // anonymous namespace
// The sources may be in a different folder from the app.
// Compute the base URL for all library sources.
var currentScript = document.currentScript ||
document.scripts[document.scripts.length - 1];
var loaderSrc = currentScript.src;
var baseUrl = loaderSrc.split('/').slice(0, -1).join('/') + '/';
function loadScript(src) {
// This does not seem like it would be the best way to do this, but the
// timing is different than creating a new script element and appending
// it to the head element. This way, all script loading happens before
// DOMContentLoaded. This is also compatible with goog.require's loading
// mechanism, whereas appending an element to head isn't.
document.write('<script src="' + baseUrl + src + '"></script>');
}
var fields = location.search.split('?').slice(1).join('?');
fields = fields ? fields.split(';') : [];
// Very old browsers do not have Array.prototype.indexOf.
var compiledMode = false;
for (var i = 0; i < fields.length; ++i) {
if (fields[i] == 'compiled') {
compiledMode = true;
break;
}
}
if (compiledMode) {
// This contains the entire library, compiled in debug mode.
loadScript('../dist/shaka-player.compiled.debug.js');
} else {
// In non-compiled mode, we load the closure library and the generated deps
// file to bootstrap the system. goog.require will load the rest.
loadScript('../third_party/closure/goog/base.js');
loadScript('../dist/deps.js');
// This file contains goog.require calls for all exported classes.
loadScript('../shaka-player.uncompiled.js');
}
})(); // anonymous namespace