Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submovie urls #203

Merged
merged 2 commits into from
Mar 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/bootstrapper/context/iframe/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,22 @@ define([
var globalExports = iframeWindow.exports = {}; // for plugins

// As per the boostrap's contract, it must provide stage.loadSubMovie
stage.loadSubMovie = function(movieUrl, callback, movieInstance) {
stage.loadSubMovie = function(movieUrl, assetUrl, callback, movieInstance) {

if (arguments.length < 4) {
movieInstance = callback;
callback = assetUrl;
assetUrl = null;
}

movieUrl = this.assetBaseUrl.resolveUri(movieUrl);
assetUrl = assetUrl ? movieUrl.resolveUri(assetUrl) : movieUrl;

var iframe = doc.createElement('iframe');
doc.documentElement.appendChild(iframe);
var subWindow = iframe.contentWindow;
var subMovie = movieInstance || new env.Movie();
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl);
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl, assetUrl);

// Need to call open()/close() before exposing anything on the window
// (Opera would initiate a separate script context if we did it after)
Expand Down
12 changes: 10 additions & 2 deletions src/bootstrapper/context/node/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,19 @@ requirejs.requirejs([
initStage: function(stage) {
var context = this;
var env = stage.env;
stage.loadSubMovie = function(movieUrl, callback, movieInstance) {
stage.loadSubMovie = function(movieUrl, assetUrl, callback, movieInstance) {

if (arguments.length < 4) {
movieInstance = callback;
callback = assetUrl;
assetUrl = null;
}

movieUrl = this.assetBaseUrl.resolveUri(movieUrl);
assetUrl = assetUrl ? movieUrl.resolveUri(assetUrl) : movieUrl;

var subMovie = movieInstance || new env.Movie();
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl);
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl, assetUrl);
var subEnvExports = subEnvironment.exports;
var functionArgNames = [];
var functionArgValues = [];
Expand Down
11 changes: 9 additions & 2 deletions src/bootstrapper/context/worker/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,19 @@ define([
});

// As per the boostrap's contract, it must provide stage.loadSubMovie
stage.loadSubMovie = function(movieUrl, callback, movieInstance) {
stage.loadSubMovie = function(movieUrl, assetUrl, callback, movieInstance) {

if (arguments.length < 4) {
movieInstance = callback;
callback = assetUrl;
assetUrl = null;
}

movieUrl = this.assetBaseUrl.resolveUri(movieUrl);
assetUrl = assetUrl ? movieUrl.resolveUri(assetUrl) : movieUrl;

var subMovie = movieInstance || new env.Movie();
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl);
var subEnvironment = stage.getSubMovieEnvironment(subMovie, movieUrl, assetUrl);
var subEnvExports = subEnvironment.exports;
var functionArgNames = [];
var functionArgValues = [];
Expand Down
2 changes: 1 addition & 1 deletion src/runner/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ define([
exports.KeyframeAnimation = bindConstructorToParameters(KeyframeAnimation, [stage]);
exports.Bitmap = bindConstructorToParameters(Bitmap, [assetLoader]);
exports.FontFamily = bindConstructorToParameters(FontFamily, [assetLoader]);
exports.Movie = bindConstructorToParameters(Movie, [stage]);
exports.Movie = bindConstructorToParameters(Movie, [stage, null]);
exports.Sprite = bindConstructorToParameters(Sprite, [assetLoader]);
exports.Video = bindConstructorToParameters(Video, [assetLoader]);
exports.Audio = bindConstructorToParameters(Audio, [assetLoader]);
Expand Down
10 changes: 8 additions & 2 deletions src/runner/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ define([
* @mixes Timeline
* @mixes displayList.timelineMethods
*/
function Movie(root, url, callback, displayList) {
function Movie(root, displayList, url, assetUrl, callback) {

if (arguments.length === 4 && typeof assetUrl === 'function') {
callback = assetUrl;
assetUrl = null;
}

AssetDisplayObject.call(this, null, url, callback);

if (!displayList) {
Expand All @@ -35,7 +41,7 @@ define([
this.root = root;
var me = this;
if (url) {
root.loadSubMovie(url, function(err) {
root.loadSubMovie(url, assetUrl, function(err) {
// We trigger the event asynchronously so as to ensure that any events
// bound after instantiation are still triggered:
if (err) {
Expand Down
5 changes: 2 additions & 3 deletions src/runner/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,13 @@ define([
* @private
* @returns {Environment} The Submovie Environment
*/
getSubMovieEnvironment: function(subMovie, subMovieUrl) {
getSubMovieEnvironment: function(subMovie, subMovieUrl, assetUrl) {
subMovieUrl = this.assetBaseUrl.resolveUri(subMovieUrl);
subMovie.url = subMovieUrl.toString();
var assetBase = subMovieUrl.scheme === 'data' ? null : subMovieUrl;
return new Environment(
subMovie,
new AssetLoader(this.registry.pendingAssets)
.on('request', hitch(this, this.loadAsset, assetBase))
.on('request', hitch(this, this.loadAsset, assetUrl.scheme === 'data' ? null : assetUrl))
);
},

Expand Down
6 changes: 3 additions & 3 deletions test/movie-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define([
describe('Movie', function() {

testDisplayList(function(displayList) {
return new Movie({}, null, null, displayList);
return new Movie({}, displayList, null, null, null);
});

it('Sets its root to first argument [usually bound by environment.js]', function() {
Expand All @@ -23,8 +23,8 @@ define([
};
var url = 'http://abc.def/pa/t/h.js';
var callback = function() {};
var m = new Movie(root, url, callback);
expect(root.loadSubMovie).toHaveBeenCalled();
var m = new Movie(root, null, url, callback);
expect(root.loadSubMovie.mostRecentCall.args[0]).toBe(url);
});

testLifeCycle(function() { return new Movie({}); });
Expand Down
3 changes: 2 additions & 1 deletion test/stage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ define([
it('returns an Environment instance for a new subMovie', function() {
var subMovie = {};
var subMovieUrl = 'test/123.js';
var env = makeStage().getSubMovieEnvironment(subMovie, subMovieUrl);
var assetUrl = 'arbitrary/assets'
var env = makeStage().getSubMovieEnvironment(subMovie, subMovieUrl, assetUrl);
expect(env instanceof Environment).toBe(true);
expect(env.exports.stage).toBe(subMovie);
});
Expand Down