From 36f9b537cc6303640b0568051f3d9f0792c6b2bb Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 13 Feb 2013 23:49:48 +0400 Subject: [PATCH] fix loading of worker files from UIWorkerClient --- lib/ace/worker/worker.js | 30 +++++++++++++++--------------- lib/ace/worker/worker_client.js | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/ace/worker/worker.js b/lib/ace/worker/worker.js index 46f173a5..00fef1f8 100644 --- a/lib/ace/worker/worker.js +++ b/lib/ace/worker/worker.js @@ -1,9 +1,10 @@ "no use strict"; +;(function(window) { +if (typeof window.window != "undefined" && window.document) { + return; +} -if (typeof window != "undefined" && window.document) - throw "atempt to load ace worker into main window instead of webWorker"; - -var console = { +window.console = { log: function() { var msgs = Array.prototype.slice.call(arguments, 0); postMessage({type: "log", data: msgs}); @@ -13,11 +14,9 @@ var console = { postMessage({type: "log", data: msgs}); } }; -var window = { - console: console -}; +window.window = window; -var normalizeModule = function(parentId, moduleName) { +window.normalizeModule = function(parentId, moduleName) { // normalize plugin requires if (moduleName.indexOf("!") !== -1) { var chunks = moduleName.split("!"); @@ -37,7 +36,7 @@ var normalizeModule = function(parentId, moduleName) { return moduleName; }; -var require = function(parentId, id) { +window.require = function(parentId, id) { if (!id.charAt) throw new Error("worker.js require() accepts only (parentId, id) as arguments"); @@ -64,7 +63,7 @@ var require = function(parentId, id) { require.modules = {}; require.tlns = {}; -var define = function(id, deps, factory) { +window.define = function(id, deps, factory) { if (arguments.length == 2) { factory = deps; if (typeof id != "string") { @@ -96,11 +95,11 @@ var define = function(id, deps, factory) { }; }; -function initBaseUrls(topLevelNamespaces) { +window.initBaseUrls = function initBaseUrls(topLevelNamespaces) { require.tlns = topLevelNamespaces; } -function initSender() { +window.initSender = function initSender() { var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter; var oop = require(null, "ace/lib/oop"); @@ -132,10 +131,10 @@ function initSender() { return new Sender(); } -var main; -var sender; +window.main = null; +window.sender = null; -onmessage = function(e) { +window.onmessage = function(e) { var msg = e.data; if (msg.command) { if (main[msg.command]) @@ -154,3 +153,4 @@ onmessage = function(e) { sender._emit(msg.event, msg.data); } }; +})(this); \ No newline at end of file diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index a93abcc2..ddd27050 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -203,7 +203,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) { this.postMessage({type: "event", name: name, data: data}); }; - require([mod], function(Main) { + config.loadModule(["worker", mod], function(Main) { main = new Main[classname](sender); while (_self.messageBuffer.length) processNext();