Permalink
Browse files

Add common build which includes both worker and iframe runner context

  • Loading branch information...
1 parent 19b5228 commit 358a0c071abe5692861c3df73924ff0aee8ccdcb Tobias von Klipstein committed Sep 28, 2012
Showing with 79 additions and 12 deletions.
  1. +3 −10 Makefile
  2. +1 −1 example/library/index-build.html
  3. +66 −0 src/bootstrapper/_build/common.js
  4. +9 −1 src/bootstrapper/context/iframe/context.js
View
13 Makefile
@@ -106,20 +106,13 @@ doc: mkjsdoc
jsdoc -r -d ${WORKSPACE}/jsdoc${SUB_DIR} ${WORKSPACE}/src || true
build: clean mkdist
- ${CLOSURE_AMD} --common_js_entry_module bootstrapper/_build/worker.js \
- src/bootstrapper/_build/worker.js \
- `find src -name '*.js' -not -path 'src/bootstrapper/_dev/*' -not -path 'src/bootstrapper/_build/*' -not -path 'src/bootstrapper/context/socketio/*' -not -path 'src/bootstrapper/context/iframe/*' -not -path 'src/bootstrapper/context/node/*'` | ${CLOSURE_PRETTY} > ${DIST_DIR}/bonsai.js
+ ${CLOSURE_AMD} --common_js_entry_module bootstrapper/_build/common.js \
+ src/bootstrapper/_build/common.js \
+ `find src -name '*.js' -not -path 'src/bootstrapper/_dev/*' -not -path 'src/bootstrapper/_build/*' -not -path 'src/bootstrapper/context/socketio/*' -not -path 'src/bootstrapper/context/node/*'` | ${CLOSURE_PRETTY} > ${DIST_DIR}/bonsai.js
echo "/*" > ${DIST_DIR}/bonsai.min.js
cat ${WORKSPACE}/LICENSE >> ${DIST_DIR}/bonsai.min.js
echo "*/" >> ${DIST_DIR}/bonsai.min.js
cat ${DIST_DIR}/bonsai.js | ${CLOSURE_FINALIZE} >> ${DIST_DIR}/bonsai.min.js
- ${CLOSURE_AMD} --common_js_entry_module bootstrapper/_build/iframe.js \
- src/bootstrapper/_build/iframe.js \
- `find src -name '*.js' -not -path 'src/bootstrapper/_dev/*' -not -path 'src/bootstrapper/_build/*' -not -path 'src/bootstrapper/context/socketio/*' -not -path 'src/bootstrapper/context/worker/*' -not -path 'src/bootstrapper/context/node/*'` | ${CLOSURE_PRETTY} > ${DIST_DIR}/bonsai.iframe.js
- echo "/*" > ${DIST_DIR}/bonsai.iframe.min.js
- cat ${WORKSPACE}/LICENSE >> ${DIST_DIR}/bonsai.iframe.min.js
- echo "*/" >> ${DIST_DIR}/bonsai.iframe.min.js
- cat ${DIST_DIR}/bonsai.iframe.js | ${CLOSURE_FINALIZE} >> ${DIST_DIR}/bonsai.iframe.min.js
preview-bundle: build
mkdir -p ${TEMP_DIR}/preview-bundle/lib
View
2 example/library/index-build.html
@@ -2,7 +2,7 @@
<meta name=viewport content=width=device-width,initial-scale=1>
<head>
<title>Bonsai Movie Library</title>
- <script src=../../dist/bonsai.iframe.js></script>
+ <script src=../../dist/bonsai.js></script>
<!--<script src="http://localhost:8080/socket.io/socket.io.js"></script>-->
<script src="movies/movie_list.js"></script>
<style type="text/css">
View
66 src/bootstrapper/_build/common.js
@@ -0,0 +1,66 @@
+/**
+* Entry module for building bonsai for the iframe environment.
+*/
+define([
+ '../player',
+ '../../message_channel',
+ '../context/iframe/bootstrap',
+ '../context/iframe/context',
+ '../context/worker/bootstrap',
+ '../context/worker/context',
+ '../../renderer/svg/svg',
+ '../../tools',
+ '../util'
+], function(player, MessageChannel, bootstrapIframe, IframeRunnerContext, bootstrapWorker, WorkerRunnerContext, SvgRenderer, tools, bootstrapUtil) {
+ 'use strict';
+
+ if(typeof window != 'undefined' && window.messageChannel) {
+
+ // This needs to execute async (setTimeout:1) so that
+ // IFrameContext.init finishes before this executes:
+ setTimeout(function() {
+ var messageChannel = window.messageChannel;
+ delete window.messageChannel;
+ bootstrapIframe(messageChannel, window);
+ }, 1);
+
+ } else if(typeof importScripts != 'undefined') {
+ // init worker bootstrap
+ var messageChannel;
+
+ var notifyRenderer = function(message) {postMessage(message);};
+ var onMessage = function(message) {messageChannel.notify(message.data);};
+ var disconnect = function() {
+ removeEventListener('message', onMessage);
+ messageChannel = null;
+ };
+
+ messageChannel = new MessageChannel(notifyRenderer, disconnect);
+ addEventListener('message', onMessage);
+ bootstrapWorker(messageChannel);
+ } else {
+ window['bonsai'] = player;
+
+ var scripts = tools.map(document.getElementsByTagName('script'), function(script) {
+ return script.src;
+ });
+
+ var supportBlobUrls = (function() {
+ var url = window.URL || window.webkitURL;
+ return typeof url !== 'undefined';
+ })();
+
+ player.Renderer = SvgRenderer;
+
+ var originalPlayerRun = player.run;
+ player.run = tools.hitch(player, function(node, url, options) {
+ player.setup({
+ baseUrl: player._baseUrl || tools.baseUri(document),
+ runnerContext: player.RunnerContext || (supportBlobUrls ? WorkerRunnerContext : IframeRunnerContext),
+ runnerUrl: player.runnerUrl || supportBlobUrls ? bootstrapUtil.getBlobUrl(__bonsaiRunnerCode__) : ('' + __bonsaiRunnerCode__)
+ });
+ originalPlayerRun.apply(this, arguments);
+ });
+
+ }
+});
View
10 src/bootstrapper/context/iframe/context.js
@@ -60,7 +60,15 @@ define([
}
});
- frameDoc.write('<script src="' + this.runnerUrl + '"></script>');//TODO: could we append the script here? Also: escaping
+ if (this.runnerUrl.indexOf('function __bonsaiRunnerCode__') > -1) {
+ var runnerCode = this.runnerUrl.substring(
+ this.runnerUrl.indexOf("{") + 1,
+ this.runnerUrl.lastIndexOf("}")
+ );
+ frameDoc.write('<script>' + runnerCode + '</script>');
+ } else {
+ frameDoc.write('<script src="' + this.runnerUrl + '"></script>');
+ }
// TODO: y on first load fails in /library
frameDoc.close();

0 comments on commit 358a0c0

Please sign in to comment.